From a21db141d4af26fc0b44ec390005db3bc5aa17e6 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 30 Apr 2018 17:58:00 +0200 Subject: [PATCH] [FIX] account: soften the constraint on company_id on partner's fp Have a partner with company_id = False Your user is currently in company A Before this commit, only FPs with no company id could be set on the partner After this commit, FP without company or belonging to company A are available The drawback is that since this computation takes place in an onchange, when you first arrive on the partner no filter is applied and you can choose whatever FP that appear This might cause access errors when it is misued related to #24256 closes #24507 --- addons/account/models/partner.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index af8d0105877..80b28be3887 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -394,8 +394,7 @@ class ResPartner(models.Model): required=True) property_account_position_id = fields.Many2one('account.fiscal.position', company_dependent=True, string="Fiscal Position", - help="The fiscal position will determine taxes and accounts used for the partner.", oldname="property_account_position", - domain="[('company_id', 'in', [company_id, False])]") + help="The fiscal position will determine taxes and accounts used for the partner.", oldname="property_account_position") property_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True, string='Customer Payment Terms', help="This payment term will be used instead of the default one for sales orders and customer invoices", oldname="property_payment_term") @@ -445,5 +444,9 @@ class ResPartner(models.Model): @api.onchange('company_id') def _onchange_company_id(self): + company = self.env['res.company'] if self.company_id: - return {'domain': {'property_account_position_id': [('company_id', 'in', [self.company_id.id, False])]}} + company = self.company_id + else: + company = self.env.user.company_id + return {'domain': {'property_account_position_id': [('company_id', 'in', [company.id, False])]}}