From 00fe2a4ba2eb7a72e5cc3664821b1a15aa5a4784 Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Thu, 23 Jun 2022 15:07:23 +0000 Subject: [PATCH] [FIX] base: retrieve last rates only from current company Steps to reproduce: - Install accounting module - Ensure there is 2 companies - Activate both companies (with company switcher) - Go to Accounting -> Configuration -> Currencies - Select currency `EUR` - Add a rate and set second company as company - Disable second company (with company switcher) - Click on `Show Currency Rates` in action menu - Click on create Issue: Access Error Cause: Currency Rate model have a compute field `rate`. This last one calls `_get_latest_rate` that will retrieve the last rate for the currency. To do so, it will first retrieve all rates for the currency (that might include rates with company not same as the current one) before fitering regarding company. Solution: Use sudo(). Same issue/fix for `_get_last_rates_for_companies`. opw-2832708 closes odoo/odoo#96714 X-original-commit: dda5c9084b9913968e67c8b280de870c81227e16 Signed-off-by: Nasreddin Boulif (bon) --- odoo/addons/base/models/res_currency.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/res_currency.py b/odoo/addons/base/models/res_currency.py index 0c94bf1153b..bd19d7ebc99 100644 --- a/odoo/addons/base/models/res_currency.py +++ b/odoo/addons/base/models/res_currency.py @@ -349,7 +349,7 @@ class CurrencyRate(models.Model): return super().create([self._sanitize_vals(vals) for vals in vals_list]) def _get_latest_rate(self): - return self.currency_id.rate_ids.filtered(lambda x: ( + return self.currency_id.rate_ids.sudo().filtered(lambda x: ( x.rate and x.company_id == (self.company_id or self.env.company) and x.name < (self.name or fields.Date.today()) @@ -357,7 +357,7 @@ class CurrencyRate(models.Model): def _get_last_rates_for_companies(self, companies): return { - company: company.currency_id.rate_ids.filtered(lambda x: ( + company: company.currency_id.rate_ids.sudo().filtered(lambda x: ( x.rate and x.company_id == company or not x.company_id )).sorted('name')[-1:].rate or 1