From b584462895567fbf7f6c052d05aabedce47d89ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Grand-Guillaume?= Date: Fri, 12 Aug 2011 14:53:16 +0200 Subject: [PATCH] [ADD] Commit of the modules used by C2C to move in our new public branch (lp:c2c-addons/6.1 rev 2) --- base_product_merge/__init__.py | 1 + base_product_merge/__openerp__.py | 57 +++++ base_product_merge/wizard/__init__.py | 1 + .../wizard/base_product_merge.py | 242 ++++++++++++++++++ .../wizard/base_product_merge_view.xml | 39 +++ 5 files changed, 340 insertions(+) create mode 100644 base_product_merge/__init__.py create mode 100644 base_product_merge/__openerp__.py create mode 100644 base_product_merge/wizard/__init__.py create mode 100644 base_product_merge/wizard/base_product_merge.py create mode 100644 base_product_merge/wizard/base_product_merge_view.xml diff --git a/base_product_merge/__init__.py b/base_product_merge/__init__.py new file mode 100644 index 000000000..35e5825cc --- /dev/null +++ b/base_product_merge/__init__.py @@ -0,0 +1 @@ +import wizard diff --git a/base_product_merge/__openerp__.py b/base_product_merge/__openerp__.py new file mode 100644 index 000000000..8e4b97098 --- /dev/null +++ b/base_product_merge/__openerp__.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) +# All Right Reserved +# +# Author : Guewen Baconnier (Camptocamp) +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +{ + "name" : "Base Products Merge", + "version" : "1.0", + "author" : "Camptocamp", + "category" : "Generic Modules/Base", + "description":""" +To merge 2 products, select them in the list view and execute the Action "Merge Products". + +The selected products are deactivated and a new one is created with : +- When a value is the same on each resources : the value +- When a value is different between the resources : you can choose the value to keep in a selection list +- When a value is set on a resource and is empty on the second one : the value is set on the resource +- All many2many relations of the 2 resources are created on the new resource. +- All the one2many relations (invoices, sale_orders, ...) are updated in order to link to the new resource. + +""", + "website": "http://camptocamp.com", + "depends" : ['product'], + "init_xml" : [], + "demo_xml" : [], + "update_xml" : [ + "wizard/base_product_merge_view.xml", + ], + "active": False, + "installable": True +} diff --git a/base_product_merge/wizard/__init__.py b/base_product_merge/wizard/__init__.py new file mode 100644 index 000000000..31d078526 --- /dev/null +++ b/base_product_merge/wizard/__init__.py @@ -0,0 +1 @@ +import base_product_merge diff --git a/base_product_merge/wizard/base_product_merge.py b/base_product_merge/wizard/base_product_merge.py new file mode 100644 index 000000000..d89cef478 --- /dev/null +++ b/base_product_merge/wizard/base_product_merge.py @@ -0,0 +1,242 @@ +# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA +# @author Guewen Baconnier +# Original code from module base_partner_merge by Tiny and Camptocamp +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +# TODO : create a base_merge module to provide abstractions for merges ? + +from osv import fields, osv +from tools.translate import _ +import tools + + +class base_product_merge(osv.osv_memory): + """ + Merges two products + """ + _name = 'base.product.merge' + _description = 'Merges two products' + + _columns = { + } + + _values = {} + + MERGE_SKIP_FIELDS = ['product_tmpl_id'] + + def _build_form(self, cr, uid, field_datas, value1, value2): + formxml = ''' +
+ ''' % _('Merge') + update_values = {} + update_fields = {} + columns = {} + + for fid, fname, fdescription, ttype, required, relation, readonly in field_datas: + if fname in self.MERGE_SKIP_FIELDS: + continue + + val1 = value1[fname] + val2 = value2[fname] + my_selection = [] + size = 24 + + if (val1 and val2) and (val1 == val2): + if ttype in ('many2one'): + update_values.update({fname: val1.id}) + elif ttype in ('many2many'): + update_values.update({fname: [(6, 0, map(lambda x: x.id, val1))]}) + else: + update_values.update({fname: val1}) + + if (val1 and val2) and (val1 != val2) and not readonly: + if ttype in ('char', 'text', 'selection'): + my_selection = [(val1, val1), (val2, val2)] + size = max(len(val1), len(val2)) + if ttype in ('float', 'integer'): + my_selection = [(str(val1), str(val1)), (str(val2), str(val2))] + if ttype in ('many2one'): + my_selection = [(str(val1.id), val1.name), + (str(val2.id), val2.name)] + if ttype in ('many2many'): + update_values.update({fname: [(6, 0, list(set(map(lambda x: x.id, val1 + val2))))]}) + if my_selection: + if not required: + my_selection.append((False, '')) + columns.update({fname: fields.selection(my_selection, fdescription, required=required, size=size)}) + update_fields.update({fname: {'string': fdescription, 'type': 'selection', 'selection': my_selection, 'required': required}}) + formxml += '\n' % (fname,) + if (val1 and not val2) or (not val1 and val2): + if ttype == 'many2one': + update_values.update({fname: val1 and val1.id or val2 and val2.id}) + elif ttype == 'many2many': + update_values.update({fname: [(6, 0, map(lambda x: x.id, val1 or val2))]}) + elif ttype == 'one2many': + #skip one2many values + pass + else: + update_values.update({fname: val1 or val2}) + + formxml += """ + + +