home · contact · privacy
Improve accounting scripts.
[misc] / ledger.py
index 656a26e95656a6d83e6c23a7814be7f648728076..958852aa56b0e747c1c2ad36f78f0d054f255310 100755 (executable)
--- a/ledger.py
+++ b/ledger.py
@@ -531,14 +531,19 @@ class LedgerHandler(PlomHandler):
             edit_mode = postvars['edit_mode'][0]
             validate = submit_button in {'update', 'add', 'copy', 'check'}
             starts_at = '?' if index == -1 else db.bookings[index].starts_at
+            delete = False
             if 'textarea' == edit_mode:
                 lines = [LedgerTextLine(line) for line in postvars['booking'][0].rstrip().split('\n')]
-                booking = Booking(lines, starts_at, validate=validate)
+                if len(lines) == 1 and lines[0].text_line == 'delete':
+                    delete = True
+                else:
+                    booking = Booking(lines, starts_at, validate=validate)
             else:
                 booking = Booking.from_postvars(postvars, starts_at, validate)
             if submit_button in {'update', 'add'}:
                 if submit_button == 'update':
-                    if 'textarea' == edit_mode and 'delete' == ''.join([l.text_line for l in lines]).strip():
+                    # if 'textarea' == edit_mode and 'delete' == ''.join([l.text_line for l in lines]).strip():
+                    if 'textarea' == edit_mode and delete:
                        del db.bookings[index]
                     # if not creating new Booking, and date unchanged, keep it in place 
                     elif booking.date == db.bookings[index].date: