From afdf1d2df88f2d227e5d395af0a2e42b92a3929d Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Wed, 14 Oct 2015 11:56:38 +0200 Subject: [PATCH] Correct mail followers merging. Fixes #179 --- base_partner_merge/base_partner_merge.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/base_partner_merge/base_partner_merge.py b/base_partner_merge/base_partner_merge.py index 4331c50fc..7d4843ebf 100644 --- a/base_partner_merge/base_partner_merge.py +++ b/base_partner_merge/base_partner_merge.py @@ -241,6 +241,24 @@ class MergePartnerAutomatic(orm.TransientModel): (field_id, '=', src.id)] ids = proxy.search(cr, openerp.SUPERUSER_ID, domain, context=context) + if model == 'mail.followers': + # mail.followers have a set semantic + # unlink records that whould trigger a duplicate constraint + # on rewrite + src_objs = proxy.browse(cr, openerp.SUPERUSER_ID, + ids) + target_domain = [(field_model, '=', 'res.partner'), + (field_id, '=', dst_partner.id)] + target_ids = proxy.search(cr, openerp.SUPERUSER_ID, + target_domain, context=context) + dst_followers = proxy.browse(cr, openerp.SUPERUSER_ID, + target_ids).mapped('partner_id') + to_unlink = src_objs.filtered(lambda obj: + obj.partner_id in dst_followers) + to_rewrite = src_objs - to_unlink + to_unlink.unlink() + ids = to_rewrite.ids + return proxy.write(cr, openerp.SUPERUSER_ID, ids, {field_id: dst_partner.id}, context=context)