[FIX] account: Currency rate conversion issue in vendor bill
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
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user