[FIX] account: fix total recomputation when having 100% tax

Create a tax as follows:
* Tax Computation: Percentage of Price Tax Included
* Tax Scope: Purchase
* Amount: 100%
* Included in Price
* Affect Base of Subsequent Taxes
Create a vendor bill with the tax on the line
Change unit price

The total does not change

This occur because when having 100% tax debit/credit are unchanged.
So the onchange `_onchange_mark_recompute_taxes` is not triggered and
the tax lines are not updated, thus not changing the
total (as in this case the invoice total is just the tax value)

opw-2370861

closes odoo/odoo#61555

X-original-commit: 9e203cc016b45875f699ffab24fe3f8382a97303
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2020-11-09 16:04:03 +00:00
parent 4f69f742c1
commit 4a0054a409
2 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -3335,7 +3335,7 @@ class AccountMoveLine(models.Model):
# ONCHANGE METHODS
# -------------------------------------------------------------------------
@api.onchange('amount_currency', 'currency_id', 'debit', 'credit', 'tax_ids', 'account_id')
@api.onchange('amount_currency', 'currency_id', 'debit', 'credit', 'tax_ids', 'account_id', 'price_unit')
def _onchange_mark_recompute_taxes(self):
''' Recompute the dynamic onchange based on taxes.
If the edited line is a tax line, don't recompute anything as the user must be able to
@@ -266,6 +266,44 @@ class TestInvoiceTaxes(AccountTestInvoicingCommon):
self.assertAlmostEqual(abs(ref_tax_lines.filtered(lambda x: x.account_id == account_1).balance), 37.8, 2, "Refund tax line on account 1 should amount to 37.8 (90% of 42)")
self.assertEqual(ref_tax_lines.mapped('tax_tag_ids'), ref_tax_tag, "Refund tax lines should have the right tag")
def test_division_tax(self):
'''
Test that when using division tax, with percentage amount
100% any change on price unit is correctly reflected on
the whole move.
Complete scenario:
- Create a division tax, 100% amount, included in price.
- Create an invoice, with only the mentioned tax
- Change price_unit of the aml
- Total price of the move should change as well
'''
sale_tax = self.env['account.tax'].create({
'name': 'tax',
'type_tax_use': 'sale',
'amount_type': 'division',
'amount': 100,
'price_include': True,
'include_base_amount': True,
})
invoice = self._create_invoice([(100, sale_tax)])
self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{
'name': sale_tax.name,
'tax_base_amount': 0.0,
'balance': -100,
}])
# change price unit, everything should change as well
with Form(invoice) as invoice_form:
with invoice_form.line_ids.edit(0) as line_edit:
line_edit.price_unit = 200
self.assertRecordValues(invoice.line_ids.filtered('tax_line_id'), [{
'name': sale_tax.name,
'tax_base_amount': 0.0,
'balance': -200,
}])
def test_misc_journal_entry_tax_tags_sale(self):
sale_tax = self.env['account.tax'].create({
'name': 'tax',