diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index aa40757ff2b..326af6d2e00 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2857,8 +2857,12 @@ class AccountMoveLine(models.Model): 'discount': 0.0, 'price_unit': balance / (quantity or 1.0), } - else: + elif not discount_factor: + # balance of line is 0, but discount == 100% so we display the normal unit_price vals = {} + else: + # balance is 0, so unit price is 0 as well + vals = {'price_unit': 0.0} return vals # ------------------------------------------------------------------------- diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index 324f75b844a..a1e9b0f9ad1 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -477,8 +477,8 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon): def test_in_invoice_line_onchange_business_fields_1(self): move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: - # Current price_unit is 1000. - # We set quantity = 4, discount = 50%, price_unit = 400 because (4 * 400) * 0.5 = 800. + # Current price_unit is 800. + # We set quantity = 4, discount = 50%, price_unit = 400. The debit/credit fields don't change because (4 * 400) * 0.5 = 800. line_form.quantity = 4 line_form.discount = 50 line_form.price_unit = 400 diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py index 897ee41b4be..7c3c600ce3d 100644 --- a/addons/account/tests/test_account_move_in_refund.py +++ b/addons/account/tests/test_account_move_in_refund.py @@ -189,8 +189,8 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon): def test_in_refund_line_onchange_business_fields_1(self): move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: - # Current price_unit is 1000. - # We set quantity = 4, discount = 50%, price_unit = 400 because (4 * 400) * 0.5 = 800. + # Current price_unit is 800. + # We set quantity = 4, discount = 50%, price_unit = 400. The debit/credit fields don't change because (4 * 400) * 0.5 = 800. line_form.quantity = 4 line_form.discount = 50 line_form.price_unit = 400 diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 2eb0b43a2da..524da8697f3 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -480,7 +480,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: # Current price_unit is 1000. - # We set quantity = 4, discount = 50%, price_unit = 500 because (4 * 500) * 0.5 = 1000. + # We set quantity = 4, discount = 50%, price_unit = 400. The debit/credit fields don't change because (4 * 500) * 0.5 = 1000. line_form.quantity = 4 line_form.discount = 50 line_form.price_unit = 500 diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py index e7f7a66df37..8f9e9c0da8b 100644 --- a/addons/account/tests/test_account_move_out_refund.py +++ b/addons/account/tests/test_account_move_out_refund.py @@ -190,7 +190,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon): move_form = Form(self.invoice) with move_form.invoice_line_ids.edit(0) as line_form: # Current price_unit is 1000. - # We set quantity = 4, discount = 50%, price_unit = 500 because (4 * 500) * 0.5 = 1000. + # We set quantity = 4, discount = 50%, price_unit = 400. The debit/credit fields don't change because (4 * 500) * 0.5 = 1000. line_form.quantity = 4 line_form.discount = 50 line_form.price_unit = 500