[FIX] account, stock_account: anglo saxong cost price currency rounding

When selling in a foreign currency,
A double currency rate change, one in each way, was applied when creating the good cost
move line of the invoice, which leaded to some precision loss when the decimal accuracy was
set with a number of digits greater than the currencies digits rounding

e.g.
Product cost price: 52.56422
CAD to USD rate: 0.7383

The product cost price is always in the company currency
while `_anglo_saxon_sale_move_lines` always returned the price
in the currency of the invoice. A first conversion rate was applied
from the company currency to the invoice currency.

52.56422 * 0.7383 = 38.808163625999995, rounded to 38.81

Then, when validating the invoice, and creating the move line,
the price was then converted again, to the company currency,
as the debit/credit of a move line is always in the company currency:
38.81 / 0.7383 = 52.566707300555336, rounded to 52.57

The cost price of the product in the good cost move line was therefore
set to 52.57, insteaf of 52.56, because of this precision loss.

With this revision, we avoid to do the currency rate conversion
two times, in both ways, to avoid the precision loss.

opw-702045
This commit is contained in:
Denis Ledoux
2016-12-28 14:19:18 +01:00
parent 66732acabf
commit dfcc0c40b1
2 changed files with 16 additions and 5 deletions
+4 -3
View File
@@ -633,9 +633,10 @@ class AccountInvoice(models.Model):
for line in invoice_move_lines:
if self.currency_id != company_currency:
currency = self.currency_id.with_context(date=self.date_invoice or fields.Date.context_today(self))
line['currency_id'] = currency.id
line['amount_currency'] = currency.round(line['price'])
line['price'] = currency.compute(line['price'], company_currency)
if not ('currency_id' in line and 'amount_currency' in line):
line['currency_id'] = currency.id
line['amount_currency'] = currency.round(line['price'])
line['price'] = currency.compute(line['price'], company_currency)
else:
line['currency_id'] = False
line['amount_currency'] = False
+12 -2
View File
@@ -83,13 +83,21 @@ class account_invoice(osv.osv):
cacc = accounts['expense'].id
if dacc and cacc:
price_unit = i_line._get_anglo_saxon_price_unit()
if inv.currency_id.id != company_currency:
currency_id = inv.currency_id.id
amount_currency = self.env['account.invoice.line']._get_price(inv, company_currency, i_line, price_unit)
else:
currency_id = False
amount_currency = False
return [
{
'type':'src',
'name': i_line.name[:64],
'price_unit': price_unit,
'quantity': i_line.quantity,
'price': self.env['account.invoice.line']._get_price(inv, company_currency, i_line, price_unit),
'price': price_unit * i_line.quantity,
'currency_id': currency_id,
'amount_currency': amount_currency,
'account_id':dacc,
'product_id':i_line.product_id.id,
'uom_id':i_line.uom_id.id,
@@ -101,7 +109,9 @@ class account_invoice(osv.osv):
'name': i_line.name[:64],
'price_unit': price_unit,
'quantity': i_line.quantity,
'price': -1 * self.env['account.invoice.line']._get_price(inv, company_currency, i_line, price_unit),
'price': -1 * price_unit * i_line.quantity,
'currency_id': currency_id,
'amount_currency': -1 * amount_currency,
'account_id':cacc,
'product_id':i_line.product_id.id,
'uom_id':i_line.uom_id.id,