From 541d2ecb878bedf6524bec7075e9af7300d4c464 Mon Sep 17 00:00:00 2001 From: "Dylan Kiss (dyki)" Date: Wed, 20 Sep 2023 16:24:14 +0200 Subject: [PATCH] [FIX] account: allow creating move in branch without parent access When a user only has access to a branch and not to the parent, he can not create a new customer invoice or vendor bill, since we need to check the lock date on all ancestor companies (where the user might not have access to). This fix allows the user to create a new customer invoice or vendor bill again when only having access to a branch. Furthermore, in the above case we are also unable to assign a partner on the invoice/bill, since we are checking properties that might belong to an ancestor company we don't have access to. We also fixed that here, so a partner can be selected. task-3503204 Part-of: odoo/odoo#138942 --- addons/account/models/account_move.py | 2 +- addons/account/models/company.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index d8818f1d6e8..d28bc36c2f5 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1737,7 +1737,7 @@ class AccountMove(models.Model): @api.onchange('partner_id') def _onchange_partner_id(self): - self = self.with_company(self.journal_id.company_id) + self = self.with_company(self.journal_id.company_id._accessible_branches()[:1]) warning = {} if self.partner_id: diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 961d05e9185..26c6d9d1951 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -356,7 +356,8 @@ class ResCompany(models.Model): if self.user_has_groups('account.group_account_manager'): lock_date = self.fiscalyear_lock_date or date.min if self.parent_id: - lock_date = max(lock_date, self.parent_id._get_user_fiscal_lock_date()) + # We need to use sudo, since we might not have access to a parent company. + lock_date = max(lock_date, self.sudo().parent_id._get_user_fiscal_lock_date()) return lock_date def _get_violated_lock_dates(self, accounting_date, has_tax):