Skip to content

Commit

Permalink
[FIX] l10n_it_delivery_note: fix ddt reference in invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Borruso committed May 8, 2024
1 parent 27ffd89 commit a30c302
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
5 changes: 1 addition & 4 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ def update_delivery_note_lines(self):
else:
sequence = 1
done_invoice_lines = self.env["account.move.line"]
for dn in invoice.mapped(
"invoice_line_ids.sale_line_ids.delivery_note_line_ids."
"delivery_note_id"
).sorted(key="name"):
for dn in invoice.delivery_note_ids.sorted(key="name"):
dn_invoice_lines = invoice.invoice_line_ids.filtered(
lambda x: x not in done_invoice_lines
and dn
Expand Down
5 changes: 3 additions & 2 deletions l10n_it_delivery_note/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def _generate_delivery_note_lines(self, invoice_ids):
def _create_invoices(self, grouped=False, final=False, date=None):
invoice_ids = super()._create_invoices(grouped=grouped, final=final, date=date)

self._assign_delivery_notes_invoices(invoice_ids.ids)
self._generate_delivery_note_lines(invoice_ids.ids)
if not self.env.context.get("skip_assign_dns", False):
self._assign_delivery_notes_invoices(invoice_ids.ids)
self._generate_delivery_note_lines(invoice_ids.ids)

return invoice_ids

Expand Down
41 changes: 13 additions & 28 deletions l10n_it_delivery_note/models/stock_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,16 @@ def action_invoice(self, invoice_method=False):
)
if not sale_ids:
continue

delivery_notes = sale_ids.mapped("delivery_note_ids") & self
orders_lines = sale_ids.mapped("order_line").filtered(
lambda l: l.product_id
)

downpayment_lines = orders_lines.filtered(lambda l: l.is_downpayment)
invoiceable_lines = orders_lines.filtered(lambda l: l.is_invoiceable)

cache = self._fix_quantities_to_invoice(
cache = delivery_notes._fix_quantities_to_invoice(
invoiceable_lines - downpayment_lines, invoice_method
)

Expand All @@ -754,18 +756,22 @@ def action_invoice(self, invoice_method=False):
if order_lines.filtered(lambda l: l.need_to_be_invoiced):
cache[downpayment] = downpayment.fix_qty_to_invoice()

invoice_ids = sale_ids.filtered(
lambda o: o.invoice_status == DOMAIN_INVOICE_STATUSES[1]
)._create_invoices(final=True)
invoice_ids = (
sale_ids.filtered(
lambda o: o.invoice_status == DOMAIN_INVOICE_STATUSES[1]
)
.with_context(skip_assign_dns=True)
._create_invoices(final=True)
)

for line, vals in cache.items():
line.write(vals)

orders_lines._get_to_invoice_qty()

for line in self.mapped("line_ids"):
for line in delivery_notes.mapped("line_ids"):
line.write({"invoice_status": "invoiced"})
for delivery_note in self:
for delivery_note in delivery_notes:
ready_invoice_ids = [
invoice_id
for invoice_id in delivery_note.sale_ids.mapped("invoice_ids").ids
Expand All @@ -778,31 +784,10 @@ def action_invoice(self, invoice_method=False):
]
}
)
self._compute_invoice_status()
delivery_notes._compute_invoice_status()
invoices = self.env["account.move"].browse(invoice_ids.ids)
invoices.update_delivery_note_lines()

if all(
line.invoice_status == "invoiced" for line in self.mapped("line_ids")
):
for delivery_note in self:
ready_invoice_ids = [
invoice_id
for invoice_id in delivery_note.sale_ids.mapped(
"invoice_ids"
).ids
if invoice_id in invoices.ids
]
delivery_note.write(
{
"invoice_ids": [
(4, invoice_id) for invoice_id in ready_invoice_ids
]
}
)
self._compute_invoice_status()
invoices.update_delivery_note_lines()

def action_done(self):
self.write({"state": DOMAIN_DELIVERY_NOTE_STATES[3]})

Expand Down

0 comments on commit a30c302

Please sign in to comment.