home · contact · privacy
Improve /fix accounting scripts.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 27 Nov 2023 17:02:41 +0000 (18:02 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 27 Nov 2023 17:02:41 +0000 (18:02 +0100)
calories.py
ledger.py
plomlib.py
unite.py

index 4352567aafa9e8bcdd9e31b2d4b4dcc0b52d43e3..28b1a16e0e99dfea186d6ff91f7dd8c006d1dad0 100644 (file)
@@ -251,8 +251,7 @@ class ConsumptionsHandler(PlomHandler):
                 to_delete += [target]
         i = 0
         if 'eatable_uuid' in postvars.keys():
-            for uuid_encoded in postvars['eatable_uuid']:
-                uuid = uuid_encoded
+            for uuid in postvars['eatable_uuid']:
                 if uuid not in to_delete:
                     e = Eatable(decode("title", i, False), decode("cals", i), decode("sugar_g", i), decode("standard_g", i), decode("comments", i, False))
                     db.add_eatable(uuid, e)
index 87d219efa9fc30c37b6e0a25165a445c5edce9f3..b6fe0644074f07566e2a0aabe2d6fab30bdfbf19 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -610,7 +610,7 @@ class LedgerDB(PlomDB):
             start = end = 0
         desc = head_comment = ''
         if len(bookings) == 0:
-            for i in range(1, 3):
+            for i in range(1, 8):
                 booking_lines += [{'i': i, 'acc': '', 'amt': '', 'curr': '€', 'comment': ''}]
             date=today
         else:
@@ -737,6 +737,7 @@ class LedgerHandler(PlomHandler):
             parsed_url = urlparse(self.path)
             length = int(self.headers['content-length'])
             postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1)
+            print("DEBUG", postvars['start'], postvars['end'])
             start = int(postvars['start'][0])
             end = int(postvars['end'][0])
             db = LedgerDB(prefix)
@@ -775,10 +776,11 @@ class LedgerHandler(PlomHandler):
             # otherwise just re-build editing form
             else:
                 if prefix + '/add_structured' == parsed_url.path: 
-                    edit_content = db.add_structured(db, start, end, temp_lines=lines, add_empty_line=add_empty_line)
+                    edit_content = db.add_structured(start, end, temp_lines=lines, add_empty_line=add_empty_line)
                 else:
-                    edit_content = db.add_free(db, start, end)
-                self.send_HTML(edit_content)
+                    edit_content = db.add_free(start, end)
+                header = jinja2.Template(html_head).render(prefix=prefix)
+                self.send_HTML(header + edit_content)
         except PlomException as e:
             self.fail_400(e)
 
@@ -815,7 +817,7 @@ class LedgerHandler(PlomHandler):
             else:
                 page = db.ledger_as_html()
             header = jinja2.Template(html_head).render(prefix=prefix)
-            self.send_HTML(header+ page)
+            self.send_HTML(header + page)
         except PlomException as e:
             self.fail_400(e)
 
index 6a13f05f4b20b148be7b8464a60f268ad9464626..18c2f185ec615a6dc61c6232bdf19b585499668b 100644 (file)
@@ -27,6 +27,9 @@ class PlomDB:
     def backup(self):
         import shutil
         from datetime import datetime, timedelta
+        if not os.path.exists(self.db_file):
+            return
+
         # collect modification times of numbered .bak files
         bak_prefix = f'{self.db_file}.bak.'
         backup_dates = []
index 14a7e3c4f9ad479539f0cd8398ff5d7494f781a0..64a72af3847c0d13ed27cacbfcf65eede324b0ad 100644 (file)
--- a/unite.py
+++ b/unite.py
@@ -3,7 +3,7 @@ from urllib.parse import urlparse
 from income_progress_bars import IncomeProgressHandler 
 from calories import ConsumptionsHandler 
 from ledger import LedgerHandler 
-server_port = 8084
+server_port = 8081
 
 
 class UnitedRequestHandler(PlomHandler):