From 34b79988a6e722999904dc917d2109b1e0bfe428 Mon Sep 17 00:00:00 2001 From: Nicolas JEUDY Date: Sat, 26 Nov 2016 10:23:47 +0100 Subject: [PATCH] [FIX] convert _fields_sync to new api --- .../models/res_partner.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/partner_contact_in_several_companies/models/res_partner.py b/partner_contact_in_several_companies/models/res_partner.py index 20b73f40f..0786760b7 100644 --- a/partner_contact_in_several_companies/models/res_partner.py +++ b/partner_contact_in_several_companies/models/res_partner.py @@ -129,7 +129,7 @@ class ResPartner(models.Model): if contact_vals: self.with_context(__update_contact_lock=True).write(contact_vals) - @api.model + @api.multi def _fields_sync(self, update_values): """Sync commercial fields and address fields from company and to children, contact fields from contact and to attached contact @@ -137,18 +137,17 @@ class ResPartner(models.Model): fields.related to the parent """ super(ResPartner, self)._fields_sync(update_values) - contact_fields = self._contact_fields() - # 1. From UPSTREAM: sync from parent contact - if update_values.get('contact_id'): - self._contact_sync_from_parent() - # 2. To DOWNSTREAM: sync contact fields to parent or related - elif any(field in contact_fields for field in update_values): - update_ids = [ - c.id for c in self.other_contact_ids if not c.is_company - ] - if self.contact_id: - update_ids.append(self.contact_id.id) - self.browse(update_ids).update_contact(update_values) + for record in self: + contact_fields = record._contact_fields() + # 1. From UPSTREAM: sync from parent contact + if update_values.get('contact_id'): + record._contact_sync_from_parent() + # 2. To DOWNSTREAM: sync contact fields to parent or related + elif any(field in contact_fields for field in update_values): + update_ids = record.other_contact_ids.filter(lambda p: not p.is_company) + if record.contact_id: + update_ids |= record.contact_id + update_ids.update_contact(update_values) @api.onchange('contact_id') def _onchange_contact_id(self):