From a042979ca15da71069a396b1aa95fd47145981bd Mon Sep 17 00:00:00 2001 From: Nicolas JEUDY Date: Sat, 3 Dec 2016 13:45:10 +0100 Subject: [PATCH] [FIX] model that same pattern for _fields_sync - add test ensure_once() --- .../models/res_partner.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/partner_contact_in_several_companies/models/res_partner.py b/partner_contact_in_several_companies/models/res_partner.py index cc8e57406..5c0ef5147 100644 --- a/partner_contact_in_several_companies/models/res_partner.py +++ b/partner_contact_in_several_companies/models/res_partner.py @@ -138,19 +138,19 @@ class ResPartner(models.Model): after create/update, just as if those were all modeled as fields.related to the parent """ + self.ensure_one() super(ResPartner, self)._fields_sync(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.filtered( - lambda p: not p.is_company) - if record.contact_id: - update_ids |= record.contact_id - update_ids.update_contact(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 = self.other_contact_ids.filtered( + lambda p: not p.is_company) + if self.contact_id: + update_ids |= self.contact_id + update_ids.update_contact(update_values) @api.onchange('contact_id') def _onchange_contact_id(self):