From 8845e671c2eb0389593a124c01face7c3ee50198 Mon Sep 17 00:00:00 2001 From: Luis Tores Date: Thu, 27 Jun 2013 19:22:06 -0700 Subject: [PATCH 1/4] [ADD][partner_do_merge]Added wizard for merge partner by partner --- partner_do_merge/__openerp__.py | 1 + partner_do_merge/wizard/__init__.py | 1 + partner_do_merge/wizard/base_partner_merge.py | 27 +++++--- partner_do_merge/wizard/merge_by_partner.py | 67 +++++++++++++++++++ partner_do_merge/wizard/merge_by_partner.xml | 36 ++++++++++ 5 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 partner_do_merge/wizard/merge_by_partner.py create mode 100644 partner_do_merge/wizard/merge_by_partner.xml diff --git a/partner_do_merge/__openerp__.py b/partner_do_merge/__openerp__.py index 29a246270..91af2bb01 100644 --- a/partner_do_merge/__openerp__.py +++ b/partner_do_merge/__openerp__.py @@ -50,6 +50,7 @@ created an action menu in the partner view ], 'data': [ 'wizard/base_partner_merge_view.xml', + 'wizard/merge_by_partner.xml', ], 'js': [ ], diff --git a/partner_do_merge/wizard/__init__.py b/partner_do_merge/wizard/__init__.py index 65c9179ec..30b45aaab 100644 --- a/partner_do_merge/wizard/__init__.py +++ b/partner_do_merge/wizard/__init__.py @@ -1 +1,2 @@ import base_partner_merge +import merge_by_partner diff --git a/partner_do_merge/wizard/base_partner_merge.py b/partner_do_merge/wizard/base_partner_merge.py index 412b1f5ce..f020f9bdf 100644 --- a/partner_do_merge/wizard/base_partner_merge.py +++ b/partner_do_merge/wizard/base_partner_merge.py @@ -312,7 +312,7 @@ class MergePartnerAutomatic(osv.TransientModel): dst_partner.id) @mute_logger('openerp.osv.expression', 'openerp.osv.orm') - def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None): + def _merge(self, cr, uid, partner_ids, dst_partner=None, remove=None,context=None): proxy = self.pool.get('res.partner') partner_ids = proxy.exists(cr, uid, list(partner_ids), context=context) @@ -375,9 +375,13 @@ class MergePartnerAutomatic(osv.TransientModel): ", ".join('%s<%s>(ID %s)' % (p.name, p.email or 'n/a', p.id) for p in src_partners))) - - for partner in src_partners: - partner.unlink() + + if remove == False: + for partner in src_partners: + partner.write({'active' : False}) + else: + for partner in src_partners: + partner.unlink() def clean_emails(self, cr, uid, context=None): """ @@ -478,13 +482,13 @@ class MergePartnerAutomatic(osv.TransientModel): for key in self._columns.keys() if key.startswith(group_by_str) ] - + groups = [ field for field in fields if getattr(this, '%s%s' % (group_by_str, field), False) ] - + if not groups: raise osv.except_osv(_('Error'), _("""You have to specify a filter for your @@ -536,7 +540,7 @@ class MergePartnerAutomatic(osv.TransientModel): }) this.write(values) - + return { 'type': 'ir.actions.act_window', 'res_model': this._name, @@ -628,7 +632,7 @@ class MergePartnerAutomatic(osv.TransientModel): groups = self._compute_selected_groupby(this) query = self._generate_query(groups, this.maximum_group) self._process_query(cr, uid, ids, query, context=context) - + return self._next_screen(cr, uid, this, context) def automatic_process_cb(self, cr, uid, ids, context=None): @@ -773,12 +777,17 @@ class MergePartnerAutomatic(osv.TransientModel): return self._next_screen(cr, uid, this, context) + def merge_pbp(self, cr, uid, partner_ids, dst_partner_id, context=None): + self._merge(cr, uid, partner_ids, dst_partner_id, False,\ + context=context) + return True + def merge_cb(self, cr, uid, ids, context=None): assert is_integer_list(ids) context = dict(context or {}, active_test=False) this = self.browse(cr, uid, ids[0], context=context) - + partner_ids = set(map(int, this.partner_ids)) if not partner_ids: this.write({'state': 'finished'}) diff --git a/partner_do_merge/wizard/merge_by_partner.py b/partner_do_merge/wizard/merge_by_partner.py new file mode 100644 index 000000000..2821b38ab --- /dev/null +++ b/partner_do_merge/wizard/merge_by_partner.py @@ -0,0 +1,67 @@ +# -*- encoding: utf-8 -*- +########################################################################### +# Module Writen to OpenERP, Open Source Management Solution +# +# Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/ +# All Rights Reserved. +# info Vauxoo (info@vauxoo.com) +############################################################################ +# Coded by: Luis Torres (luis_t@vauxoo.com) +############################################################################ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv import osv, fields +from openerp import SUPERUSER_ID + +class wizard_merge_partner_by_partner(osv.osv_memory): + _name = 'wizard.merge.partner.by.partner' + + def default_get(self, cr, uid, fields, context=None): + partner_obj = self.pool.get('res.partner') + partner = partner_obj.browse(cr, uid, context.get('active_id'),\ + context=context) + res = {'partner_id' : partner.id , 'partner_ids' : [partner.id]} + return res + + _columns = { + 'partner_id' : fields.many2one('res.partner', 'Partner', readonly=True, + required=True, help='Correct partner to complete data'), + 'partner_ids': fields.many2many('res.partner', 'partners_to_merge', + 'partner_id', 'wizard_id', 'Partner to merge', help='Partners to '\ + 'merge'), + } + + def merge_cb(self, cr, uid, ids, context=None): + base_partner_obj = self.pool.get('base.partner.merge.automatic.wizard') + partner_obj = self.pool.get('res.partner') + for data in self.browse(cr, uid, ids, context=context): + dst_partner = data.partner_id + partner_ids = set(map(int, data.partner_ids)) + if len(partner_ids) >= 2: + base_partner_obj.merge_pbp(cr, SUPERUSER_ID, partner_ids,\ + dst_partner, context=context) + adminpac_ids = {} + for partner in data.partner_ids: + if partner.adminpaq_id: + adminpac_ids.update({partner.id : partner.adminpaq_id}) + if len(adminpac_ids) == 1: + partner_obj.write(cr, uid, adminpac_ids.keys()[0], { + 'adminpaq_id' : 0}) + partner_obj.write(cr, uid, data.partner_id.id, { + 'adminpaq_id' : adminpac_ids.values()[0]}) + return True + + diff --git a/partner_do_merge/wizard/merge_by_partner.xml b/partner_do_merge/wizard/merge_by_partner.xml new file mode 100644 index 000000000..efbad65de --- /dev/null +++ b/partner_do_merge/wizard/merge_by_partner.xml @@ -0,0 +1,36 @@ + + + + + view.merge.partner.by.partner.wizard + wizard.merge.partner.by.partner + +
+ + + + + + + + +
+
+
+
+
+ + + +
+
From 9c23e5b44c8ae92148fadddbedb24403f1fb6daf Mon Sep 17 00:00:00 2001 From: Luis Tores Date: Wed, 3 Jul 2013 00:18:07 -0700 Subject: [PATCH 2/4] [IMP][partner_do_merge]Remove option that partner merged are removeds --- partner_do_merge/wizard/base_partner_merge.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/partner_do_merge/wizard/base_partner_merge.py b/partner_do_merge/wizard/base_partner_merge.py index f020f9bdf..27928dd30 100644 --- a/partner_do_merge/wizard/base_partner_merge.py +++ b/partner_do_merge/wizard/base_partner_merge.py @@ -312,7 +312,7 @@ class MergePartnerAutomatic(osv.TransientModel): dst_partner.id) @mute_logger('openerp.osv.expression', 'openerp.osv.orm') - def _merge(self, cr, uid, partner_ids, dst_partner=None, remove=None,context=None): + def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None): proxy = self.pool.get('res.partner') partner_ids = proxy.exists(cr, uid, list(partner_ids), context=context) @@ -376,12 +376,8 @@ class MergePartnerAutomatic(osv.TransientModel): (p.name, p.email or 'n/a', p.id) for p in src_partners))) - if remove == False: - for partner in src_partners: - partner.write({'active' : False}) - else: - for partner in src_partners: - partner.unlink() + for partner in src_partners: + partner.write({'active' : False}) def clean_emails(self, cr, uid, context=None): """ @@ -778,8 +774,7 @@ class MergePartnerAutomatic(osv.TransientModel): return self._next_screen(cr, uid, this, context) def merge_pbp(self, cr, uid, partner_ids, dst_partner_id, context=None): - self._merge(cr, uid, partner_ids, dst_partner_id, False,\ - context=context) + self._merge(cr, uid, partner_ids, dst_partner_id, context=context) return True def merge_cb(self, cr, uid, ids, context=None): From 7ac839d59f141858271b4e9d22193415f0f77ecf Mon Sep 17 00:00:00 2001 From: Luis Tores Date: Thu, 4 Jul 2013 15:54:08 -0700 Subject: [PATCH 3/4] [IMP][partner_do_merge]Added function for save in a many2many the partners merged --- partner_do_merge/__openerp__.py | 1 + partner_do_merge/model/partner.py | 4 ++++ partner_do_merge/view/res_partner_view.xml | 21 +++++++++++++++++++++ partner_do_merge/wizard/merge_by_partner.py | 7 +++++++ 4 files changed, 33 insertions(+) create mode 100644 partner_do_merge/view/res_partner_view.xml diff --git a/partner_do_merge/__openerp__.py b/partner_do_merge/__openerp__.py index 91af2bb01..7461e5585 100644 --- a/partner_do_merge/__openerp__.py +++ b/partner_do_merge/__openerp__.py @@ -51,6 +51,7 @@ created an action menu in the partner view 'data': [ 'wizard/base_partner_merge_view.xml', 'wizard/merge_by_partner.xml', + 'view/res_partner_view.xml', ], 'js': [ ], diff --git a/partner_do_merge/model/partner.py b/partner_do_merge/model/partner.py index c9a1bd8c1..36b9cf6f5 100644 --- a/partner_do_merge/model/partner.py +++ b/partner_do_merge/model/partner.py @@ -66,6 +66,10 @@ class res_partner(osv.Model): store=_display_name_store_triggers), 'id': fields.integer('Id', readonly=True), 'create_date': fields.datetime('Create Date', readonly=True), + 'partner_merged_ids' : fields.many2many('res.partner',\ + 'partners_mergeds', 'partner_active', 'partner_id', 'Relation '\ + 'with partner merged', domain=['|', ('active','=',True), (\ + 'active','=',False)], readonly=True) } diff --git a/partner_do_merge/view/res_partner_view.xml b/partner_do_merge/view/res_partner_view.xml new file mode 100644 index 000000000..615860a99 --- /dev/null +++ b/partner_do_merge/view/res_partner_view.xml @@ -0,0 +1,21 @@ + + + + + + view.partner.form.inh.partner.merge.form + form + res.partner + + + + + + + + + + + + + diff --git a/partner_do_merge/wizard/merge_by_partner.py b/partner_do_merge/wizard/merge_by_partner.py index 2821b38ab..da4e9c0b9 100644 --- a/partner_do_merge/wizard/merge_by_partner.py +++ b/partner_do_merge/wizard/merge_by_partner.py @@ -62,6 +62,13 @@ class wizard_merge_partner_by_partner(osv.osv_memory): 'adminpaq_id' : 0}) partner_obj.write(cr, uid, data.partner_id.id, { 'adminpaq_id' : adminpac_ids.values()[0]}) + list_partners = data.partner_ids + if dst_partner in data.partner_ids: + list_partners.remove(dst_partner) + partner_mergeds = [] + for x in list_partners: + partner_mergeds.append(x.id) + partner_obj.write(cr, uid, dst_partner.id, {'partner_merged_ids' : [(6, 0, partner_mergeds)]}, context=context) return True From dbbb442b0881189c10efefb16017342ec0281001 Mon Sep 17 00:00:00 2001 From: Luis Tores Date: Wed, 14 Aug 2013 12:15:40 -0500 Subject: [PATCH 4/4] [IMP][partner_do_merge]Remove code that use particular fields --- partner_do_merge/wizard/merge_by_partner.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/partner_do_merge/wizard/merge_by_partner.py b/partner_do_merge/wizard/merge_by_partner.py index da4e9c0b9..77dd4894c 100644 --- a/partner_do_merge/wizard/merge_by_partner.py +++ b/partner_do_merge/wizard/merge_by_partner.py @@ -53,15 +53,6 @@ class wizard_merge_partner_by_partner(osv.osv_memory): if len(partner_ids) >= 2: base_partner_obj.merge_pbp(cr, SUPERUSER_ID, partner_ids,\ dst_partner, context=context) - adminpac_ids = {} - for partner in data.partner_ids: - if partner.adminpaq_id: - adminpac_ids.update({partner.id : partner.adminpaq_id}) - if len(adminpac_ids) == 1: - partner_obj.write(cr, uid, adminpac_ids.keys()[0], { - 'adminpaq_id' : 0}) - partner_obj.write(cr, uid, data.partner_id.id, { - 'adminpaq_id' : adminpac_ids.values()[0]}) list_partners = data.partner_ids if dst_partner in data.partner_ids: list_partners.remove(dst_partner)