from plomlib import PlomDB, PlomException, run_server, PlomHandler
server_port = 8082
-db_path = '/home/plom/org/ledger2023.dat'
+db_path = '/home/plom/org/ledger2024.dat'
html_head = """
<style>
</form>
"""
add_free_html = """<br />
-<textarea name="booking" rows=10 cols=80>
-{% for line in lines %}{{ line }}
-{% endfor %}
-</textarea>
+<textarea name="booking" rows=10 cols=80>{% for line in lines %}{{ line }}{% if not loop.last %}
+{% endif %}{% endfor %}</textarea>
"""
add_structured_html = """
<input type="submit" name="add_taxes" value="add taxes" tabindex="5" />
elif b.date_string > date:
start_at = b.start_line
break
+ lines += [''] # DEBUG is new
return self.write_lines_in_total_lines_at(self.real_lines, start_at, lines)
def update(self, start, end, lines, date):
- total_lines = self.real_lines[:start] + self.real_lines[end:]
+ remaining_lines = self.real_lines[:start] + self.real_lines[end:]
n_original_lines = end - start
- start_at = len(total_lines)
+ start_at = len(remaining_lines)
for b in self.bookings:
if b.date_string == date:
- if start_at == len(total_lines) or b.start_line == start:
+ if start_at == len(remaining_lines) or b.start_line == start:
start_at = b.start_line
if b.start_line > start:
start_at -= n_original_lines
elif b.date_string > date:
break
- if start_at == len(total_lines):
+ # print("DEBUG update start_at", start_at, "len(remaining_lines)", len(remaining_lines), "len(self.real_lines)", len(self.real_lines), "end", end)
+ if start_at != 0 and end != len(self.real_lines) and start_at == len(remaining_lines):
+ # Add empty predecessor line if appending.
lines = [''] + lines
- return self.write_lines_in_total_lines_at(total_lines, start_at, lines)
+ return self.write_lines_in_total_lines_at(remaining_lines, start_at, lines)
def write_lines_in_total_lines_at(self, total_lines, start_at, lines):
- total_lines = total_lines[:start_at] + lines + [''] + total_lines[start_at:]
+ # total_lines = total_lines[:start_at] + lines + [''] + total_lines[start_at:]
+ total_lines = total_lines[:start_at] + lines + total_lines[start_at:]
_, _ = parse_lines(lines)
text = '\n'.join(total_lines)
self.write_db(text)
else:
line += f"\t\t"
for currency, amount in account_sums[path + node].items():
- if currency != '€' and amount > 0:
+ if currency != '€' and amount != 0:
line += f"{amount:5.2f} {currency}\t"
lines += [line]
indent += " "
if b.start_line > start:
next_booking = b
break
- start_at = next_booking.start_line + len(next_booking.lines) - (end - start) + 1
- self.make_move(start, end, start_at-1)
+ # start_at = next_booking.start_line + len(next_booking.lines) - (end - start) + 1
+ # self.make_move(start, end, start_at-1)
+ start_at = next_booking.start_line + len(next_booking.lines) - (end - start)
+ print("DEBUG", start, end, start_at)
+ self.make_move(start, end, start_at)
return redir_nth
def make_move(self, start, end, start_at):
+ # FIXME currently broken due to changed self.write_lines_in_total_lines_at, easy fix would be lines += [""] maybe?
lines = self.get_lines(start, end)
- total_lines = self.real_lines[:start-1] + self.real_lines[end:] # +1 because we reduce the original position's two empty border lines to in-between line
+ if start == 0:
+ total_lines = self.real_lines[end+1:]
+ lines = [''] + lines
+ start_at += 1
+ else:
+ total_lines = self.real_lines[:start-1] + self.real_lines[end:] # -1 because we reduce the original position's two empty limit lines to one in-between line
+ lines += ['']
self.write_lines_in_total_lines_at(total_lines, start_at, lines)
def booking_lines_from_postvars(self, postvars):
temp_bookings, _ = parse_lines(temp_lines)
for currency in temp_bookings[0].sink:
amount = temp_bookings[0].sink[currency]
- lines += [f'Assets {amount:.2f} {currency}']
+ # lines += [f'Assets {amount:.2f} {currency}']
+ lines += [f'Assets {amount} {currency}']
except PlomException:
pass
elif 'add_taxes' in postvars.keys():
postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1)
start = int(postvars['start'][0])
end = int(postvars['end'][0])
+ print("DEBUG start, end", start, end)
db = LedgerDB(prefix)
add_empty_line = None
lines = []
nth = db.get_nth_for_booking_of_start_line(start)
else:
new_start = db.update(start, end, lines, target_date)
+ print("DEBUG save", new_start, start, end, lines)
nth = db.get_nth_for_booking_of_start_line(new_start)
if new_start > start:
nth -= 1