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 ) ), ) 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.", + )