diff --git a/base_partner_merge/README.rst b/base_partner_merge/README.rst new file mode 100644 index 000000000..d570d0607 --- /dev/null +++ b/base_partner_merge/README.rst @@ -0,0 +1,43 @@ +.. 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 their 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 +------------ + +* Charbel Jacquin + +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. 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 d9def5d34..14629f3b2 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. @@ -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) @@ -321,7 +339,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) @@ -336,7 +354,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 " @@ -346,7 +364,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.")) @@ -371,7 +389,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" @@ -508,9 +526,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