From 2f900d4f1ca74c49a7a3db8d2c024c0d79ce662f Mon Sep 17 00:00:00 2001 From: Damien Bouvy <dbo@odoo.com> Date: Mon, 20 Jan 2020 09:18:00 +0000 Subject: [PATCH] [FIX] account, base: Creating contacts from their parent or setting their parent Bug in 13.0 regarding company_id field of partners when creating them from their parent contact or when setting their parent. The field 'company_id' of res.partner is set by an onchange on 'parent_id' to that of it's parent; unfortunately the field is readonly if parent_id is set and not set to force_save. Furthermore, creating a child partner from the main one (in the 'Contact' tab of the main partner form view) does not follow the same behaviour (company_id is unset in that case, meaning that children don't have the same company as their parent). Since the company_id is already set by an onchange when we change 'parent_id' and set to readonly in that case, I assume the expected behaviour is actually that children partners should have the same company as their parent by default. Fine tuning of 7b49f5836c0f4a491631d27acb74ddd0106c86b1 opw:2176384,2167106 closes odoo/odoo#43621 X-original-commit: 92737f21acf9b044df99e111fceffc08e05abe65 Signed-off-by: Simon Goffin (sig) <sig@openerp.com> --- odoo/addons/base/models/res_partner.py | 8 ++++++++ odoo/addons/base/views/res_partner_views.xml | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index 4428c80671e3..83d14da10e38 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -135,6 +135,14 @@ class Partner(models.Model): def _default_category(self): return self.env['res.partner.category'].browse(self._context.get('category_id')) + @api.model + def default_get(self, default_fields): + """Add the company of the parent as default if we are creating a child partner.""" + values = super().default_get(default_fields) + if 'parent_id' in default_fields and values.get('parent_id'): + values['company_id'] = self.browse(values.get('parent_id')).company_id.id + return values + name = fields.Char(index=True) display_name = fields.Char(compute='_compute_display_name', store=True, index=True) date = fields.Date(index=True) diff --git a/odoo/addons/base/views/res_partner_views.xml b/odoo/addons/base/views/res_partner_views.xml index 6b7a4635501f..cbb68cfe01ef 100644 --- a/odoo/addons/base/views/res_partner_views.xml +++ b/odoo/addons/base/views/res_partner_views.xml @@ -378,6 +378,7 @@ <field name="email" widget="email"/> <field name="phone" widget="phone"/> <field name="mobile" widget="phone"/> + <field name="company_id" invisible="1"/> </group> <group colspan="1"> <field name="image_1920" widget="image" class="oe_avatar" nolabel="1" options="{'image_preview': 'image_128'}"/> @@ -398,7 +399,7 @@ </group> <group name="misc" string="Misc"> <field name="ref" string="Reference"/> - <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}" attrs="{'readonly': [('parent_id', '!=', False)]}"/> + <field name="company_id" groups="base.group_multi_company" options="{'no_create': True}" attrs="{'readonly': [('parent_id', '!=', False)]}" force_save="1"/> <field name="industry_id" attrs="{'invisible': [('is_company', '=', False)]}" options="{'no_create': True}"/> </group> </group> -- GitLab