From 367fadc8d51f6169e2931270730357fdaed81986 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 5 Jun 2018 14:39:10 +0200 Subject: [PATCH] [FIX] account: Currency rate conversion issue in vendor bill MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Enable multi currencies - Make sure that the current rate of a foreign currency (i.e. $) is not 1.0 (i.e. 0.5) - Create a purchasable product with a cost (i.e. 100€) - Create a vendor bill in a foreign currency (i.e. $) - Add the product on the invoice Bug: The unit price was equal to 25$ instead of 50$ Technical reason: The function "_onchange_product_id" was called twice (the second time by function "_onchange_uom_id") and the price unit was converted twice in the currency of the vendor bill. The idea of this fix is to only convert in the currency when the unit price is set by the system. Fixes #24751 opw:1849212 --- addons/account/models/account_invoice.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index a22913be9d1..a42da9eab0a 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1169,6 +1169,13 @@ class AccountInvoiceLine(models.Model): return accounts['income'] return accounts['expense'] + def _set_currency(self): + company = self.invoice_id.company_id + currency = self.invoice_id.currency_id + if company and currency: + if company.currency_id != currency: + self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate + def _set_taxes(self): """ Used in on_change to set taxes and price.""" if self.invoice_id.type in ('out_invoice', 'out_refund'): @@ -1187,8 +1194,10 @@ class AccountInvoiceLine(models.Model): prec = self.env['decimal.precision'].precision_get('Product Price') if not self.price_unit or float_compare(self.price_unit, self.product_id.standard_price, precision_digits=prec) == 0: self.price_unit = fix_price(self.product_id.standard_price, taxes, fp_taxes) + self._set_currency() else: self.price_unit = fix_price(self.product_id.lst_price, taxes, fp_taxes) + self._set_currency() @api.onchange('product_id') def _onchange_product_id(self): @@ -1237,8 +1246,6 @@ class AccountInvoiceLine(models.Model): domain['uom_id'] = [('category_id', '=', product.uom_id.category_id.id)] if company and currency: - if company.currency_id != currency: - self.price_unit = self.price_unit * currency.with_context(dict(self._context or {}, date=self.invoice_id.date_invoice)).rate if self.uom_id and self.uom_id.id != product.uom_id.id: self.price_unit = self.env['product.uom']._compute_price(