Skip to content
Snippets Groups Projects
Commit 6e8f1d11 authored by Nicolas Martinelli's avatar Nicolas Martinelli
Browse files

[FIX] purchase: rounding in anglo-saxon

When anglo-saxon accounting is enabled and the valuation of a product is
'real_time', rounding errors might occur in the price difference between
the invoice price and the product price. It occurs when the product
price precision is larger than the accounting precision.

To avoid these rounding errors, we calculate the difference as the
difference between the price before update and the price after update.

opw-686730
parent 2d217952
Branches
Tags
No related merge requests found
......@@ -163,13 +163,14 @@ class AccountInvoice(models.Model):
#line['tax_ids'] is like [(4, tax_id, None), (4, tax_id2, None)...]
taxes = self.env['account.tax'].browse([x[1] for x in line['tax_ids']])
price_unit = taxes.with_context(round=False).compute_all(price_unit, currency=inv.currency_id, quantity=1.0)['total_excluded']
price_before = line.get('price', 0.0)
line.update({'price': round(valuation_price_unit * line['quantity'], account_prec)})
diff_res.append({
'type': 'src',
'name': i_line.name[:64],
'price_unit': round(price_unit - valuation_price_unit, product_prec),
'quantity': line['quantity'],
'price': round((price_unit - valuation_price_unit) * line['quantity'], account_prec),
'price': round(price_before - line.get('price', 0.0), account_prec),
'account_id': acc,
'product_id': line['product_id'],
'uom_id': line['uom_id'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment