[FIX] base: make partner.company_type properly writeable

In 7eab8e26d3 res.partner was converted
to the new API, at that point company_type was changed from a stored
field manually synchronised with is_company (through create/write
overrides) into a proper computed field.

However to make it "editable" it was simply marked as
"readonly=False", which means even though UI-wise it looks editable
editing it does not actually do anything (things work in the partners
form because there's also an onchange which updates is_company on the
fly).

Fix by implementing an inverse function and actually do this
correctly.

Fixes #20623
This commit is contained in:
Xavier Morel
2017-11-02 13:14:59 +01:00
parent 75b7f62783
commit e134dde867
+5 -1
View File
@@ -201,7 +201,7 @@ class Partner(models.Model, FormatAddress):
# company_type is only an interface field, do not use it in business logic
company_type = fields.Selection(string='Company Type',
selection=[('person', 'Individual'), ('company', 'Company')],
compute='_compute_company_type', readonly=False)
compute='_compute_company_type', inverse='_write_company_type')
company_id = fields.Many2one('res.company', 'Company', index=True, default=_default_company)
color = fields.Integer(string='Color Index', default=0)
user_ids = fields.One2many('res.users', 'partner_id', string='Users', auto_join=True)
@@ -372,6 +372,10 @@ class Partner(models.Model, FormatAddress):
for partner in self:
partner.company_type = 'company' if partner.is_company else 'person'
def _write_company_type(self):
for partner in self:
partner.is_company = partner.company_type == 'company'
@api.onchange('company_type')
def onchange_company_type(self):
self.is_company = (self.company_type == 'company')