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 Nov 4, 2024
1 parent 54a3979 commit 3730a2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
16 changes: 8 additions & 8 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def update_delivery_note_lines(self):
invoice_line.delivery_note_id = (
note_line.delivery_note_id.id
)
if dn_invoice_lines:
new_lines.append(
(
0,
False,
self._prepare_note_dn_value(sequence, dn),
)
if not dn_invoice_lines:
sequence -= 1
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
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 @@ -107,8 +107,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 3730a2f

Please sign in to comment.