[FIX] account: error in Base amount tax

opw-1917605

Before this commit, when accounting is set to global rounding, the base
amount per tax is not correctly calculated.

Now, the Base amount per tax is calculated adding the rounded lines.

To test this issue, you need to set to global rounding and create a
customer invoice with the following lines :
line 1 = Qty:40; unit price:2.27; tax:15%; discount: 10%
line 2 = Qty:21; unit price:2.77; tax:15%; discount: 10%
line 3 = Qty:21; unit price:2.77; tax:15%; discount: 10%

When the invoce is printed, you would notice that the amount is 186.43
and it should be 186.42.

closes odoo/odoo#30021
This commit is contained in:
Jorge Pinna Puissant
2019-01-08 13:13:36 +00:00
parent d4024a713c
commit b131658966
2 changed files with 66 additions and 1 deletions
+3 -1
View File
@@ -642,6 +642,7 @@ class AccountInvoice(models.Model):
@api.multi
def get_taxes_values(self):
tax_grouped = {}
round_curr = self.currency_id.round
for line in self.invoice_line_ids:
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
@@ -651,9 +652,10 @@ class AccountInvoice(models.Model):
if key not in tax_grouped:
tax_grouped[key] = val
tax_grouped[key]['base'] = round_curr(val['base'])
else:
tax_grouped[key]['amount'] += val['amount']
tax_grouped[key]['base'] += val['base']
tax_grouped[key]['base'] += round_curr(val['base'])
return tax_grouped
@api.multi
@@ -107,3 +107,66 @@ class TestAccountCustomerInvoice(AccountTestUsers):
# I clicked on refund button.
self.account_invoice_refund_0.invoice_refund()
def test_customer_invoice_tax(self):
self.env.user.company_id.tax_calculation_rounding_method = 'round_globally'
payment_term = self.env.ref('account.account_payment_term_advance')
journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0]
partner3 = self.env.ref('base.res_partner_3')
account_id = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id
tax = self.env['account.tax'].create({
'name': 'Tax 15.0',
'amount': 15.0,
'amount_type': 'percent',
'type_tax_use': 'sale',
})
invoice_line_data = [
(0, 0,
{
'product_id': self.env.ref('product.product_product_1').id,
'quantity': 40.0,
'account_id': account_id,
'name': 'product test 1',
'discount' : 10.00,
'price_unit': 2.27,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
),
(0, 0,
{
'product_id': self.env.ref('product.product_product_2').id,
'quantity': 21.0,
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
'name': 'product test 2',
'discount' : 10.00,
'price_unit': 2.77,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
),
(0, 0,
{
'product_id': self.env.ref('product.product_product_3').id,
'quantity': 21.0,
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
'name': 'product test 3',
'discount' : 10.00,
'price_unit': 2.77,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
)
]
invoice = self.env['account.invoice'].create(dict(
name="Test Customer Invoice",
reference_type="none",
payment_term_id=payment_term.id,
journal_id=journalrec.id,
partner_id=partner3.id,
invoice_line_ids=invoice_line_data
))
self.assertEquals(invoice.amount_untaxed, sum([x.base for x in invoice.tax_line_ids]))