Skip to content

Commit

Permalink
[FIX] account: error in Base amount tax
Browse files Browse the repository at this point in the history
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#30021
  • Loading branch information
jpp-odoo committed Jan 8, 2019
1 parent d4024a7 commit b131658
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
4 changes: 3 additions & 1 deletion addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ def _prepare_tax_line_vals(self, line, tax):
@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']
Expand All @@ -651,9 +652,10 @@ def get_taxes_values(self):

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
Expand Down
63 changes: 63 additions & 0 deletions addons/account/tests/test_account_customer_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,66 @@ def test_customer_invoice(self):

# 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]))

0 comments on commit b131658

Please sign in to comment.