+ def booking_lines_from_postvars(self, postvars, db):
+ add_empty_line = None
+ date = postvars['date'][0]
+ description = postvars['description'][0]
+ start_comment = postvars['line_0_comment'][0]
+ start_line = f'{date} {description}'
+ if start_comment.rstrip() != '':
+ start_line += f' ; {start_comment}'
+ lines = [start_line]
+ if 'line_0_add' in postvars.keys():
+ add_empty_line = 0
+ i = j = 1
+ while f'line_{i}_comment' in postvars.keys():
+ if f'line_{i}_delete' in postvars.keys():
+ i += 1
+ continue
+ elif f'line_{i}_delete_after' in postvars.keys():
+ break
+ elif f'line_{i}_add' in postvars.keys():
+ add_empty_line = j
+ account = postvars[f'line_{i}_account'][0]
+ amount = postvars[f'line_{i}_amount'][0]
+ currency = postvars[f'line_{i}_currency'][0]
+ comment = postvars[f'line_{i}_comment'][0]
+ i += 1
+ new_main = f' {account} {amount}'
+ if '' == new_main.rstrip() == comment.rstrip(): # don't write empty lines, ignore currency if nothing else set
+ continue
+ if len(amount.rstrip()) > 0:
+ new_main += f' {currency}'
+ j += 1
+ new_line = new_main
+ if comment.rstrip() != '':
+ new_line += f' ; {comment}'
+ lines += [new_line]
+ if 'add_sink' in postvars.keys():
+ temp_lines = lines.copy() + ['_']
+ try:
+ 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}']
+ except HandledException:
+ pass
+ if 'add_taxes' in postvars.keys():
+ lines += db.add_taxes(lines, finish=False)
+ elif 'add_taxes2' in postvars.keys():
+ lines += db.add_taxes(lines, finish=True)
+ return lines, add_empty_line
+