Skip to content

Commit

Permalink
[14.0][FIX] l10n_it_delivery_note invoice multiple DDT on same sale o…
Browse files Browse the repository at this point in the history
…rder line
  • Loading branch information
sergiocorato committed Feb 26, 2024
1 parent 937d3bb commit d25168d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 6 deletions.
13 changes: 7 additions & 6 deletions l10n_it_delivery_note/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,14 @@ def update_delivery_note_lines(self):
invoice_line.delivery_note_id = (
note_line.delivery_note_id.id
)
new_lines.append(
(
0,
False,
self._prepare_note_dn_value(sequence, dn),
if dn_invoice_lines:
new_lines.append(
(
0,
False,
self._prepare_note_dn_value(sequence, dn),
)
)
)
for invoice_line in dn_invoice_lines:
sequence += 1
invoice_line.sequence = sequence
Expand Down
91 changes: 91 additions & 0 deletions l10n_it_delivery_note/tests/test_stock_delivery_note_invoicing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta

from odoo.tests import new_test_user
from odoo.tests.common import Form

from .delivery_note_common import StockDeliveryNoteCommon
Expand Down Expand Up @@ -1282,3 +1283,93 @@ def test_delivery_note_to_draft_from_create(self):
delivery_note.action_draft()
self.assertEqual(delivery_note.invoice_status, "no")
self.assertEqual(delivery_note.state, "draft")

def test_invoicing_multiple_dn(self):
user = new_test_user(
self.env,
login="test_multiple_dn",
groups="stock.group_stock_manager,"
"l10n_it_delivery_note.use_advanced_delivery_notes",
)
self.env.user = user
StockPicking = self.env["stock.picking"]
sales_order = self.create_sales_order(
[
self.right_corner_desk_line, # 2
self.desk_combination_line, # 1
],
)
self.assertEqual(len(sales_order.order_line), 2)
sales_order.action_confirm()
self.assertEqual(len(sales_order.picking_ids), 1)
picking = sales_order.picking_ids
self.assertEqual(len(picking.move_lines), 2)

# deliver only half of the first product
picking.move_lines[0].quantity_done = 1
res_dict = picking.button_validate()
wizard = Form(
self.env[(res_dict.get("res_model"))]
.with_user(user)
.with_context(res_dict["context"])
).save()
wizard.process()
res_dict = picking.action_delivery_note_create()
wizard = Form(
self.env[(res_dict.get("res_model"))]
.with_user(user)
.with_context(res_dict["context"])
).save()
wizard.confirm()
self.assertTrue(picking.delivery_note_id)
dn = picking.delivery_note_id
self.assertEqual(dn.partner_id, self.recipient)
dn.action_confirm()
dn.action_done()
picking_backorder = StockPicking.search([("backorder_id", "=", picking.id)])
self.assertEqual(len(picking_backorder.move_lines), 2)
picking_backorder.move_lines[0].quantity_done = 1
picking_backorder.move_lines[1].quantity_done = 1
picking_backorder.button_validate()
self.assertEqual(picking_backorder.state, "done")
back_res_dict = picking_backorder.action_delivery_note_create()
back_wizard = Form(
self.env[(back_res_dict.get("res_model"))]
.with_user(user)
.with_context(back_res_dict["context"])
).save()
back_wizard.confirm()
self.assertTrue(picking_backorder.delivery_note_id)
back_dn = picking_backorder.delivery_note_id
self.assertEqual(back_dn.partner_id, self.recipient)
back_dn.action_confirm()
back_dn.action_done()
sales_order._create_invoices()
self.assertTrue(len(sales_order.invoice_ids), 1)
invoice = sales_order.invoice_ids
invoice.action_post()
self.assertEqual(invoice.state, "posted")
self.assertEqual(
invoice.invoice_line_ids.filtered(
lambda inv_line: inv_line.product_id.id
== self.right_corner_desk_line[2]["product_id"]
).quantity,
2,
)
self.assertEqual(
invoice.invoice_line_ids.filtered(
lambda inv_line: inv_line.product_id.id
== self.desk_combination_line[2]["product_id"]
).quantity,
1,
)
self.assertEqual(dn.invoice_status, "invoiced")
self.assertEqual(back_dn.invoice_status, "invoiced")
self.assertIn(
'Delivery Note "DDT/00001" of 26/02/2024',
invoice.invoice_line_ids.mapped("name"),
)
self.assertIn(
'Delivery Note "DDT/00002" of 26/02/2024',
invoice.invoice_line_ids.mapped("name"),
)

0 comments on commit d25168d

Please sign in to comment.