[FIX] sale,pos_sale: use correct method to find conversion currency rate
Before this commit, if the currency of the company is not the reference
currency (rate = 1.0), then the conversion will be applied on the
sale.report with currency rate.
Example in the demo data:
- Company currency is USD
- Reference currency is EUR
- Currency rate of USD is 1.5289 (after 6th June)
Creating a SO with a total of 1000 USD in the USD company will
display 654.065 on the sale.report (= 1000 / 1.5289).
The applied computation simply takes the rate of the company currency,
which is not exactly correct. This does not cause many problem since,
usually, companies set their currency as the reference one
(with rate = 1).
Since e8f01b94ce, the rate is stored,
offering the possibility to make the code more robust and covering
the case detailled above.
The correct computation to apply is the one defined in `_convert`
method: 1000 * (1.5289 / 1.5289) (amount * (src rate / dst rate)).
This commit makes the correct convertion rate stored, instead of
the currency rate.
Doing that allow us to keep currency rates in the sale_timesheet
reporting test case.
This commit is contained in:
@@ -13,4 +13,4 @@ class PosOrder(models.Model):
|
||||
def _compute_currency_rate(self):
|
||||
for order in self:
|
||||
date_order = order.date_order or fields.Datetime.now()
|
||||
order.currency_rate = order.pricelist_id.currency_id._get_rates(order.company_id, date_order).get(order.company_id.currency_id.id, 1.0)
|
||||
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.pricelist_id.currency_id, order.company_id.currency_id, order.company_id, date_order)
|
||||
|
||||
@@ -187,7 +187,7 @@ class SaleOrder(models.Model):
|
||||
@api.depends('pricelist_id', 'date_order', 'company_id')
|
||||
def _compute_currency_rate(self):
|
||||
for order in self:
|
||||
order.currency_rate = order.currency_id._get_rates(order.company_id, order.date_order).get(order.currency_id.id, 1.0)
|
||||
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.currency_id, order.company_id.currency_id, order.company_id, order.date_order)
|
||||
|
||||
def _compute_access_url(self):
|
||||
super(SaleOrder, self)._compute_access_url()
|
||||
|
||||
@@ -18,7 +18,6 @@ class TestReporting(TestCommonSaleTimesheetNoChart):
|
||||
# tweak demo data: force currency and remove confusing rates
|
||||
company_currency = cls.env.user.company_id.currency_id
|
||||
cls.env.ref('product.list0').currency_id = company_currency
|
||||
cls.env['res.currency.rate'].search([('currency_id', '=', company_currency.id), ('company_id', '=', cls.env.user.company_id.id)]).unlink() # there a rate to convert USD into USD in demo data
|
||||
|
||||
# expense product
|
||||
cls.product_expense = cls.env['product.product'].with_context(mail_notrack=True, mail_create_nolog=True).create({
|
||||
|
||||
Reference in New Issue
Block a user