[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 7b49f5836c
opw:2176384,2167106
closes odoo/odoo#43621
X-original-commit: 92737f21acf9b044df99e111fceffc08e05abe65
Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
committed by
Goffin Simon
parent
e3ad9c8976
commit
2f900d4f1c
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user