Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def update_delivery_note_lines(self):
new_lines = []
old_lines = invoice.invoice_line_ids.filtered(lambda l: l.note_dn)
old_lines.unlink()

# move all the invoice lines sequence (included sections/notes)
for inv_line in invoice.invoice_line_ids:
inv_line.sequence += 10
#
# TODO: Come bisogna comportarsi nel caso in
# cui il DdT non sia un DdT "valido"?
Expand All @@ -112,7 +114,15 @@ def update_delivery_note_lines(self):
context["lang"] = invoice.partner_id.lang

if len(invoice.delivery_note_ids) == 1:
sequence = invoice.invoice_line_ids[0].sequence - 1
# get the first position of the normal invoice lines
sequence = (
min(
invoice.invoice_line_ids.filtered(
lambda l: not l.display_type
).mapped("sequence")
)
- 5
)
new_lines.append(
(
0,
Expand All @@ -123,7 +133,6 @@ def update_delivery_note_lines(self):
)
)
else:
sequence = 1
done_invoice_lines = self.env["account.move.line"]
for dn in invoice.mapped("delivery_note_ids").sorted(key="name"):
dn_invoice_lines = invoice.invoice_line_ids.filtered(
Expand All @@ -147,17 +156,16 @@ def update_delivery_note_lines(self):
note_line.delivery_note_id.id
)
if dn_invoice_lines:
# get the first position of the invoice lines linked to a
# delivery note, excluding in this way the section/note lines
sequence = min(dn_invoice_lines.mapped("sequence")) - 5
new_lines.append(
(
0,
False,
self._prepare_note_dn_value(sequence, dn),
)
)
sequence += 1
for invoice_line in dn_invoice_lines:
invoice_line.sequence = sequence
sequence += 1

invoice.write({"line_ids": new_lines})

Expand Down
Loading