From afdf1d2df88f2d227e5d395af0a2e42b92a3929d Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Wed, 14 Oct 2015 11:56:38 +0200 Subject: [PATCH 1/4] 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) From f045c2fea537fff014ab52c99704d6873a218ba5 Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Tue, 13 Oct 2015 11:19:50 +0200 Subject: [PATCH 2/4] silent pylint --- base_partner_merge/__init__.py | 3 ++- base_partner_merge/__openerp__.py | 5 ++--- base_partner_merge/base_partner_merge.py | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/base_partner_merge/__init__.py b/base_partner_merge/__init__.py index e3fc7010c..cc544c45c 100644 --- a/base_partner_merge/__init__.py +++ b/base_partner_merge/__init__.py @@ -1 +1,2 @@ -from . import base_partner_merge +# -*- coding: utf-8 -*- +from . import base_partner_merge # NOQA diff --git a/base_partner_merge/__openerp__.py b/base_partner_merge/__openerp__.py index 8aae98264..38ed6399a 100644 --- a/base_partner_merge/__openerp__.py +++ b/base_partner_merge/__openerp__.py @@ -1,11 +1,10 @@ +# -*- coding: utf-8 -*- { 'name': 'Base Partner Merge', 'author': "OpenERP S.A.,Odoo Community Association (OCA)", 'category': 'Generic Modules/Base', 'version': '8.0.0.1.0', - 'description': """ -backport module, to be removed when we switch to saas2 on the private servers -""", + 'license': 'AGPL-3', 'depends': [ 'base', 'mail' diff --git a/base_partner_merge/base_partner_merge.py b/base_partner_merge/base_partner_merge.py index 7d4843ebf..c03c0b2af 100644 --- a/base_partner_merge/base_partner_merge.py +++ b/base_partner_merge/base_partner_merge.py @@ -15,9 +15,9 @@ from openerp.tools import mute_logger from .validate_email import validate_email import openerp -from openerp.osv import orm -from openerp.osv import fields -from openerp.osv.orm import browse_record +import openerp.osv.fields as fields +from openerp.osv.orm import TransientModel, browse_record +from openerp.exceptions import except_orm from openerp.tools.translate import _ pattern = re.compile(r"&(\w+?);") @@ -58,7 +58,7 @@ def is_integer_list(ids): return all(isinstance(i, (int, long)) for i in ids) -class MergePartnerLine(orm.TransientModel): +class MergePartnerLine(TransientModel): _name = 'base.partner.merge.line' _columns = { @@ -71,7 +71,7 @@ class MergePartnerLine(orm.TransientModel): _order = 'min_id asc' -class MergePartnerAutomatic(orm.TransientModel): +class MergePartnerAutomatic(TransientModel): """ The idea behind this wizard is to create a list of potential partners to merge. We use two objects, the first one is the wizard for the end-user. @@ -338,7 +338,7 @@ class MergePartnerAutomatic(orm.TransientModel): if parent_id and parent_id != dst_partner.id: try: dst_partner.write({'parent_id': parent_id}) - except (orm.except_orm, orm.except_orm): + except except_orm: _logger.info('Skip recursive partner hierarchies for ' 'parent_id %s of partner: %s', parent_id, dst_partner.id) @@ -353,7 +353,7 @@ class MergePartnerAutomatic(orm.TransientModel): return if len(partner_ids) > 3: - raise orm.except_orm( + raise except_orm( _('Error'), _("For safety reasons, you cannot merge more than 3 contacts " "together. You can re-open the wizard several times if " @@ -363,7 +363,7 @@ class MergePartnerAutomatic(orm.TransientModel): len(set(partner.email for partner in proxy.browse(cr, uid, partner_ids, context=context))) > 1): - raise orm.except_orm( + raise except_orm( _('Error'), _("All contacts must have the same email. Only the " "Administrator can merge contacts with different emails.")) @@ -388,7 +388,7 @@ class MergePartnerAutomatic(orm.TransientModel): [('partner_id', 'in', [partner.id for partner in src_partners])], context=context)): - raise orm.except_orm( + raise except_orm( _('Error'), _("Only the destination contact may be linked to existing " "Journal Items. Please ask the Administrator if you need to" @@ -525,9 +525,9 @@ class MergePartnerAutomatic(orm.TransientModel): ] if not groups: - raise orm.except_orm(_('Error'), - _("You have to specify a filter for your " - "selection")) + raise except_orm(_('Error'), + _("You have to specify a filter for your " + "selection")) return groups From 18cc35f9ae18e2054c29d3eecb2b3e15d335fbf6 Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Tue, 13 Oct 2015 15:35:10 +0200 Subject: [PATCH 3/4] add readme to make runbot happy --- base_partner_merge/README.rst | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 base_partner_merge/README.rst diff --git a/base_partner_merge/README.rst b/base_partner_merge/README.rst new file mode 100644 index 000000000..3dfc86a60 --- /dev/null +++ b/base_partner_merge/README.rst @@ -0,0 +1,44 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================== +Base Partner Merge +================== + + +This module implements merging of multiple partners +depending on thier similarity + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + + +Credits +======= + +Contributors +------------ + +* Firstname Lastname +* Second Person + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. From 5227ed3a3dcc65c540eb23eee36f2e36f0aa7651 Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Mon, 2 Nov 2015 11:33:07 +0100 Subject: [PATCH 4/4] fix typo in README.rst, add myself to contributors --- base_partner_merge/README.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/base_partner_merge/README.rst b/base_partner_merge/README.rst index 3dfc86a60..d570d0607 100644 --- a/base_partner_merge/README.rst +++ b/base_partner_merge/README.rst @@ -8,7 +8,7 @@ Base Partner Merge This module implements merging of multiple partners -depending on thier similarity +depending on their similarity Bug Tracker =========== @@ -25,8 +25,7 @@ Credits Contributors ------------ -* Firstname Lastname -* Second Person +* Charbel Jacquin Maintainer ----------