diff options
| author | jem-odoo <jem@openerp.com> | 2018-08-24 10:02:26 +0200 |
|---|---|---|
| committer | jem-odoo <jem@openerp.com> | 2018-08-24 15:48:26 +0200 |
| commit | a7eb6832d197eb8a02fdc918b8065551136c5e2b (patch) | |
| tree | 4a7bd76488409c21b456b5642ce423f4b30adfec | |
| parent | 3c4c6b955dd4ebef1e84434add031edc97b656f7 (diff) | |
[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 e8f01b94ce8f4aeed7e573821bcfd73d6c20024c, 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.
| -rw-r--r-- | addons/pos_sale/models/pos_order.py | 2 | ||||
| -rw-r--r-- | addons/sale/models/sale.py | 2 | ||||
| -rw-r--r-- | addons/sale_timesheet/tests/test_reporting.py | 1 |
3 files changed, 2 insertions, 3 deletions
diff --git a/addons/pos_sale/models/pos_order.py b/addons/pos_sale/models/pos_order.py index 03d31171c26..afd3e8fb0ae 100644 --- a/addons/pos_sale/models/pos_order.py +++ b/addons/pos_sale/models/pos_order.py @@ -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) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index cf470e3b631..4a33ad90511 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -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() diff --git a/addons/sale_timesheet/tests/test_reporting.py b/addons/sale_timesheet/tests/test_reporting.py index ae784456e1a..78b3744474f 100644 --- a/addons/sale_timesheet/tests/test_reporting.py +++ b/addons/sale_timesheet/tests/test_reporting.py @@ -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({ |
