def copy_booking(self, id_: int, to_end: bool) -> int:
"""Add copy of Booking of id_ to_end of ledger, or after copied."""
copied = self.bookings[id_]
- new_lines = [DatLine('')] + [DatLine(dat_line.raw) for dat_line
- in copied.dat_lines]
+ empty_line = DatLine('')
if to_end or copied is self.bookings[-1]:
- self.dat_lines += new_lines
- new_id = self.bookings[-1].id_ + 1
+ intro = DatLine(
+ f'{dt_date.today().isoformat()} '
+ f'{copied.intro_line.target} ; {copied.dat_lines[0].comment}')
+ self.dat_lines += [empty_line, intro] + copied.dat_lines[1:]
+ prev_id = self.bookings[-1].id_
else:
start = self.dat_lines.index(copied.dat_lines[-1])
- self._replace_from_to(start + 1, start, new_lines)
- new_id = copied.id_ + 1
+ self._replace_from_to(start + 1, start,
+ [empty_line] + copied.dat_lines)
+ prev_id = copied.id_
self._load_bookings()
- return new_id
+ return prev_id + 1
@property
def dat_lines_sans_empty(self) -> list[DatLine]: