diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index ec00bb99a97..66d32323a57 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -3897,6 +3897,7 @@ class AccountMoveLine(models.Model): if tax.price_include: amount_currency += tax_res['amount'] + tax_included_division_is_zero = any(tax.price_include and tax.amount == 100 and tax.amount_type == 'division' for tax in taxes) and amount_currency == 0 discount_factor = 1 - (discount / 100.0) if amount_currency and discount_factor: # discount != 100% @@ -3911,8 +3912,9 @@ class AccountMoveLine(models.Model): 'discount': 0.0, 'price_unit': amount_currency / (quantity or 1.0), } - elif not discount_factor: - # balance of line is 0, but discount == 100% so we display the normal unit_price + elif not discount_factor or tax_included_division_is_zero: + # balance of line is 0, but discount == 100% or taxes (price included) == 100%, + # so we display the normal unit_price vals = {} else: # balance is 0, so unit price is 0 as well diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 2d451a53dec..bbe25ed04b9 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3449,3 +3449,24 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): # Tags should be empty since the tax has been removed from the invoice line self.assertRecordValues(invoice.line_ids, [{'tax_tag_ids': []}, {'tax_tag_ids': []}]) + + def test_changeprice_unit_to_zero(self): + move = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'invoice_date': fields.Date.from_string('2017-01-01'), + 'invoice_line_ids': [ + (0, None, { + 'product_id': self.product_a.id, + 'product_uom_id': self.product_a.uom_id.id, + 'quantity': 1.0, + 'price_unit': 1000.0, + 'tax_ids': [(6, 0, [])], + })] + }) + + move.write({'invoice_line_ids': [(1, move.invoice_line_ids.ids[0], { + 'price_unit': 0.0, + })]}) + + self.assertTrue(all(line.price_unit == 0 for line in move.line_ids)) diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index 5bd499e3253..b448a532a33 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -713,3 +713,41 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon): self.assertRecordValues(invoice.line_ids.filtered(lambda l: l.account_id.internal_type == 'receivable'), [{ 'balance': 686.54 }]) + + def test_invoice_with_100_percent_division_tax_incl(self): + """ + Check if the price unit remain the same after affecting a tax + 100%, price_include and amount_type 'division' + """ + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'currency_id': self.currency_data['currency'].id, + 'invoice_date': '2018-01-01', + 'date': '2018-01-01', + 'invoice_line_ids': [(0, 0, { + 'name': 'xxxx', + 'quantity': 1, + 'price_unit': 500, + })] + }) + + division_tax_4_incl = self.env['account.tax'].create({ + 'name': '100% incl', + 'amount_type': 'division', + 'amount': 100, + 'price_include': True, + 'include_base_amount': True, + 'sequence': 50, + }) + + self.assertRecordValues(invoice.invoice_line_ids, [ + {'price_unit': 500} + ]) + with Form(invoice) as inv_form: + with inv_form.invoice_line_ids.edit(0) as line_form: + line_form.tax_ids.add(division_tax_4_incl) + + self.assertRecordValues(invoice.invoice_line_ids, [ + {'price_unit': 500} + ])