home · contact · privacy
Improve accounting scripts.
[misc] / ledger.py
index a26ca0f345f5dfdaf02eb8cff45330991eb14d7d..f29f73ec190d3b1391b4a3f05ca088607ac221d2 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -449,8 +449,8 @@ class Booking:
             self.description = description
             self.top_comment = top_comment 
             self.validate_head()
-            self.transfer_lines = transfer_lines
-            if len(self.transfer_lines) < 2 and self.validate:
+            self.transfer_lines = transfer_lines if transfer_lines else []
+            if self.validate and len(self.transfer_lines) < 2:
                 raise PlomException(f'{self.intro}: too few transfer lines')
             self.calculate_account_changes()
             self.lines = [LedgerTextLine(l) for l in self.for_writing]
@@ -1032,8 +1032,11 @@ class LedgerDB(PlomDB):
             content = sent if sent else ([] if 'textarea'==edit_mode else None)
         else:
             content = self.bookings[index]
+        date_today = str(datetime.now())[:10]
         if copy:
-            content.date = str(datetime.now())[:10]
+            content.date = date_today 
+        elif -1 == index and (content is None or [] == content):
+            content = Booking(date=date_today, validate=False)
         if 'textarea' == edit_mode and content:
             content = content.for_writing
         else:
@@ -1248,7 +1251,7 @@ class LedgerHandler(PlomHandler):
         elif prefix + '/edit' == parsed_url.path:
             index = int(postvars['index'][0])
             edit_mode = postvars['edit_mode'][0]
-            validate = submit_button in {'save', 'copy', 'check'}
+            validate = submit_button in {'update', 'add', 'copy', 'check'}
             starts_at = '?' if index == -1 else db.bookings[index].starts_at
             if 'textarea' == edit_mode:
                 lines = [LedgerTextLine(line) for line in postvars['booking'][0].rstrip().split('\n')]