From 62022df3639eaee3a0a10d465b7a4ed462f8496f Mon Sep 17 00:00:00 2001 From: ThiagoMForgeFlow Date: Tue, 1 Oct 2024 10:08:49 +0200 Subject: [PATCH 1/2] [IMP] sale_order_invoice_amount: not count over-invoicing lines for uninvoicing amount --- sale_order_invoice_amount/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sale_order_invoice_amount/models/sale_order.py b/sale_order_invoice_amount/models/sale_order.py index 2599d71506c..48cb07c523a 100644 --- a/sale_order_invoice_amount/models/sale_order.py +++ b/sale_order_invoice_amount/models/sale_order.py @@ -53,6 +53,7 @@ def _compute_invoice_amount(self): * (line.price_total / line.product_uom_qty) for line in rec.order_line.filtered( lambda sl: sl.product_uom_qty > 0 + and sl.product_uom_qty > sl.qty_invoiced ) ), ) From 30116fd2dedac814cd4b09f16b860d497ec59e0d Mon Sep 17 00:00:00 2001 From: DavidJForgeFlow Date: Wed, 9 Oct 2024 12:10:27 +0200 Subject: [PATCH 2/2] [IMP] sale_order_invoice_amount: add test for more qty invoiced than needed. --- .../tests/test_sale_order_invoice_amount.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py b/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py index 91f3792be1c..d617d49861a 100644 --- a/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py +++ b/sale_order_invoice_amount/tests/test_sale_order_invoice_amount.py @@ -376,3 +376,44 @@ def test_03_sale_order_invoiced_amount_different_currencies_sale(self): 0.0, "Uninvoiced Amount should be calculated.", ) + + def test_04_sale_order_invoiced_amount_negative(self): + self.assertEqual( + self.sale_order_1.invoiced_amount, + 0.0, + "Invoiced Amount should be 0.0", + ) + + self.sale_order_1.action_confirm() + aml1 = self.order_line_1._prepare_invoice_line() + aml1["quantity"] = 20.0 + aml2 = self.order_line_2._prepare_invoice_line() + test_invoice = self.env["account.move"].create( + [ + { + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2024-01-01"), + "date": fields.Date.from_string("2024-01-01"), + "partner_id": self.res_partner_1.id, + "invoice_line_ids": [ + ( + 0, + 0, + aml1, + ), + ( + 0, + 0, + aml2, + ), + ], + } + ] + ) + test_invoice.action_post() + self.assertEqual( + self.sale_order_1.uninvoiced_amount, + 121.0, + "Uninvoiced Amount should be 121, as we invoiced more than required in one line, " + "but we have not invoices sale order line 3.", + )