From 7b49f5836c0f4a491631d27acb74ddd0106c86b1 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" <lpe@odoo.com> Date: Thu, 5 Apr 2018 10:35:18 +0200 Subject: [PATCH] [FIX] account: partner's fiscal position chosen within its company Before this commit, a partner in a company could have a fiscal position belonging to another company Namely, the search view on the field property account position displayed every fiscal position This could create problems afterwards, when managing an invoice from a restricted rights user (with an access right error raising) After this commit, we soflty constrain the choice of the fiscal position to the ones belonging to the same company of the partner OPW 1833848 OPW 1827831 closes #24056 --- addons/account/models/partner.py | 8 +++++++- addons/account/views/partner_view.xml | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 4482b4e1c4c3..af8d01058773 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -394,7 +394,8 @@ 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") + help="The fiscal position will determine taxes and accounts used for the partner.", oldname="property_account_position", + domain="[('company_id', 'in', [company_id, False])]") 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") @@ -441,3 +442,8 @@ class ResPartner(models.Model): action['domain'] = literal_eval(action['domain']) action['domain'].append(('partner_id', 'child_of', self.id)) return action + + @api.onchange('company_id') + def _onchange_company_id(self): + if self.company_id: + return {'domain': {'property_account_position_id': [('company_id', 'in', [self.company_id.id, False])]}} diff --git a/addons/account/views/partner_view.xml b/addons/account/views/partner_view.xml index 2ef709802947..d944200a8b8c 100644 --- a/addons/account/views/partner_view.xml +++ b/addons/account/views/partner_view.xml @@ -95,6 +95,7 @@ <field name="priority" eval="20"/> <field name="arch" type="xml"> <field name="email" position="after"> + <field name="company_id" invisible="1"/> <field name="property_payment_term_id" widget="selection"/> <field name="property_account_position_id" options="{'no_create': True, 'no_open': True}"/> </field> -- GitLab