From 58599512188a22b5a4d6d1dd4fb2d8918d5e655f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon=20=28ACSONE=29?= Date: Sat, 14 Jul 2018 10:46:04 +0200 Subject: [PATCH] [FIX] account_credit_control: more accurate usage of sudo() to avoid multi-company issues (#666) Step to reproduce: * Define 2 companies A and B. * Configure Policies only for company A (set the list of accounts) * Set Admin user on company B Try to change the policy on a partner on campany A. An error message will appear explaining that the account is not allowed on the policy. The reason is that partner.property_account_receivable_id is evaluate in sudo() the contains the value of company B. --- account_credit_control/__manifest__.py | 2 +- account_credit_control/models/res_partner.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/account_credit_control/__manifest__.py b/account_credit_control/__manifest__.py index 47e301a5c..62c250909 100644 --- a/account_credit_control/__manifest__.py +++ b/account_credit_control/__manifest__.py @@ -3,7 +3,7 @@ # Copyright 2018 Access Bookings Ltd (https://accessbookings.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). {'name': 'Account Credit Control', - 'version': '11.0.1.0.0', + 'version': '11.0.1.0.1', 'author': "Camptocamp,Odoo Community Association (OCA),Okia,Access Bookings", 'maintainer': 'Camptocamp', 'category': 'Finance', diff --git a/account_credit_control/models/res_partner.py b/account_credit_control/models/res_partner.py index edfcef0d1..2bc20e8a8 100644 --- a/account_credit_control/models/res_partner.py +++ b/account_credit_control/models/res_partner.py @@ -53,12 +53,12 @@ class ResPartner(models.Model): def _check_credit_policy(self): """ Ensure that policy on partner are limited to the account policy """ # sudo needed for those w/o permission that duplicate records - for partner in self.sudo(): + for partner in self: if (not partner.property_account_receivable_id or - not partner.credit_policy_id): + not partner.sudo().credit_policy_id): continue account = partner.property_account_receivable_id - policy = partner.credit_policy_id + policy = partner.sudo().credit_policy_id try: policy.check_policy_against_account(account) except UserError as err: