Merge lp:~camptocamp/stock-logistic-warehouse/7.0-port-base_product_merge into lp:stock-logistic-warehouse

Proposed by Yannick Vaucher @ Camptocamp
Status: Work in progress
Proposed branch: lp:~camptocamp/stock-logistic-warehouse/7.0-port-base_product_merge
Merge into: lp:stock-logistic-warehouse
Diff against target: 391 lines (+154/-125)
4 files modified
base_product_merge/__init__.py (+2/-0)
base_product_merge/__openerp__.py (+34/-40)
base_product_merge/wizard/base_product_merge.py (+80/-49)
base_product_merge/wizard/base_product_merge_view.xml (+38/-36)
To merge this branch: bzr merge lp:~camptocamp/stock-logistic-warehouse/7.0-port-base_product_merge
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp Needs Resubmitting
Review via email: mp+162121@code.launchpad.net
To post a comment you must log in.
34. By Yannick Vaucher @ Camptocamp

[FIX] wrong call to super

35. By Alexandre Fayolle - camptocamp

[REF] fix spacing

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

just curious: why do we need the _columns in BaseProductMerge for 7.0 and not in the original code?

More importantly: are we sure about this:
"""All the one2many relations (invoices, sale_orders, ...) are updated in order to link to the new resource."""

It sounds very very dangerous to me. Or maybe this is only for some of the targeted invoices and sale orders?

review: Needs Information
36. By Yannick Vaucher @ Camptocamp

[FIX] base_product_merge - add missing import of osv.osv for raising exception

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

No idea why _columns are filled it comes from the port from OpenERP

About the update it updates the relation for all one2many but those fields:

MERGE_SKIP_FIELDS = ['product_tmpl_id', 'product_image']

There is no WHERE filtering in the execution of update so nothing is targeted.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

I set it in work in progress as it certainly needs some refactoring

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

The source code management for this project has been moved to https://github.com/OCA/stock-logistics-warehouse

Could you resubmit this MP on the new site?

review: Needs Resubmitting

Unmerged revisions

36. By Yannick Vaucher @ Camptocamp

[FIX] base_product_merge - add missing import of osv.osv for raising exception

35. By Alexandre Fayolle - camptocamp

[REF] fix spacing

34. By Yannick Vaucher @ Camptocamp

[FIX] wrong call to super

33. By Yannick Vaucher @ Camptocamp

[IMP] base_product_merge - retab xml view

32. By Yannick Vaucher @ Camptocamp

[IMP] base_product_merge - Update license to AGPL

31. By Yannick Vaucher @ Camptocamp

[IMP] base_product_merge - use orm.TransientModel instead of osv_memory alias

30. By Yannick Vaucher @ Camptocamp

[MIG] portage of base_product_merge by OpenERP

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'base_product_merge/__init__.py'
--- base_product_merge/__init__.py 2011-08-12 12:53:16 +0000
+++ base_product_merge/__init__.py 2013-05-13 08:54:24 +0000
@@ -1,1 +1,3 @@
1import wizard1import wizard
2
3# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
2\ No newline at end of file4\ No newline at end of file
35
=== modified file 'base_product_merge/__openerp__.py'
--- base_product_merge/__openerp__.py 2013-02-13 08:46:41 +0000
+++ base_product_merge/__openerp__.py 2013-05-13 08:54:24 +0000
@@ -1,41 +1,30 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)4# Author: Guewen Baconnier
5# All Right Reserved5# Copyright 2011 Camptocamp SA
6#6#
7# Author : Guewen Baconnier (Camptocamp)7# This program is free software: you can redistribute it and/or modify
8#8# it under the terms of the GNU Affero General Public License as
9# WARNING: This program as such is intended to be used by professional9# published by the Free Software Foundation, either version 3 of the
10# programmers who take the whole responsability of assessing all potential10# License, or (at your option) any later version.
11# consequences resulting from its eventual inadequacies and bugs11#
12# End users who are looking for a ready-to-use solution with commercial12# This program is distributed in the hope that it will be useful,
13# garantees and support are strongly adviced to contract a Free Software13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# Service Company14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15#15# GNU Affero General Public License for more details.
16# This program is Free Software; you can redistribute it and/or16#
17# modify it under the terms of the GNU General Public License17# You should have received a copy of the GNU Affero General Public License
18# as published by the Free Software Foundation; either version 218# along with this program. If not, see <http://www.gnu.org/licenses/>.
19# of the License, or (at your option) any later version.
20#
21# This program is distributed in the hope that it will be useful,
22# but WITHOUT ANY WARRANTY; without even the implied warranty of
23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24# GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License
27# along with this program; if not, write to the Free Software
28# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29#19#
30##############################################################################20##############################################################################
3121
32{22{
33 "name" : "Base Products Merge",23 'name' : 'Base Products Merge',
34 "version" : "1.0",24 'version' : '1.0',
35 "author" : "Camptocamp",25 'category' : 'Generic Modules/Base',
36 "category" : "Generic Modules/Base",26 'description':'''
37 "description":"""27To merge 2 products, select them in the list view and execute the Action 'Merge Products'.
38To merge 2 products, select them in the list view and execute the Action "Merge Products".
3928
40The selected products are deactivated and a new one is created with :29The selected products are deactivated and a new one is created with :
41- When a value is the same on each resources : the value30- When a value is the same on each resources : the value
@@ -44,14 +33,19 @@
44- All many2many relations of the 2 resources are created on the new resource.33- All many2many relations of the 2 resources are created on the new resource.
45- All the one2many relations (invoices, sale_orders, ...) are updated in order to link to the new resource.34- All the one2many relations (invoices, sale_orders, ...) are updated in order to link to the new resource.
4635
47""",36''',
48 "website": "http://camptocamp.com",37 'author' : 'Camptocamp',
49 "depends" : ['product'],38 'website': 'http://camptocamp.com',
50 "init_xml" : [],39 'depends' : ['product', 'purchase'],
51 "demo_xml" : [],40 'data' : [
52 "update_xml" : [41 'wizard/base_product_merge_view.xml',
53 "wizard/base_product_merge_view.xml",
54 ],42 ],
55 "active": False,43 'demo' : [],
56 "installable": False44 'test' : [],
45 'installable': True,
46 'auto_install' : False,
47 'application' : False,
48
57}49}
50
51# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
5852
=== modified file 'base_product_merge/wizard/base_product_merge.py'
--- base_product_merge/wizard/base_product_merge.py 2011-08-12 12:53:16 +0000
+++ base_product_merge/wizard/base_product_merge.py 2013-05-13 08:54:24 +0000
@@ -1,59 +1,78 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2# -*- coding: utf-8 -*-
3##############################################################################2##############################################################################
4#3#
5# Copyright (c) 2011 Camptocamp SA4# Author: Guewen Baconnier
6# @author Guewen Baconnier5# Copyright 2011 Camptocamp SA
7# Original code from module base_partner_merge by Tiny and Camptocamp6#
8#7# This program is free software: you can redistribute it and/or modify
9# WARNING: This program as such is intended to be used by professional8# it under the terms of the GNU Affero General Public License as
10# programmers who take the whole responsability of assessing all potential9# published by the Free Software Foundation, either version 3 of the
11# consequences resulting from its eventual inadequacies and bugs10# License, or (at your option) any later version.
12# End users who are looking for a ready-to-use solution with commercial11#
13# garantees and support are strongly adviced to contract a Free Software12# This program is distributed in the hope that it will be useful,
14# Service Company13# but WITHOUT ANY WARRANTY; without even the implied warranty of
15#14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# This program is Free Software; you can redistribute it and/or15# GNU Affero General Public License for more details.
17# modify it under the terms of the GNU General Public License16#
18# as published by the Free Software Foundation; either version 217# You should have received a copy of the GNU Affero General Public License
19# of the License, or (at your option) any later version.18# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21# This program is distributed in the hope that it will be useful,
22# but WITHOUT ANY WARRANTY; without even the implied warranty of
23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24# GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License
27# along with this program; if not, write to the Free Software
28# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29#19#
30##############################################################################20##############################################################################
3121
32# TODO : create a base_merge module to provide abstractions for merges ?22# TODO : create a base_merge module to provide abstractions for merges ?
3323
34from osv import fields, osv24from openerp.osv import orm, fields, osv
35from tools.translate import _25from tools.translate import _
36import tools26import tools
3727from osv.orm import browse_record
3828
39class base_product_merge(osv.osv_memory):29class BaseProductMerge(orm.TransientModel):
40 """30 """ Merges two products """
41 Merges two products
42 """
43 _name = 'base.product.merge'31 _name = 'base.product.merge'
44 _description = 'Merges two products'32 _description = 'Merges Two Products'
4533
46 _columns = {34 _columns = {
47 }35 'uom_po_id': fields.selection([('', '')], 'Purchase Unit of Measure',),
48 36 'seller_id': fields.selection([('', '')], 'Seller',),
37 'seller_info_id': fields.selection([('', '')], 'SellerInfo'),
38 'supply_method': fields.selection([('', '')], 'Supply method',),
39 'seller_delay': fields.selection([('', '')], 'Supplier Lead Time',),
40 'type': fields.selection([('', '')], 'Product Type',),
41 'uom_id': fields.selection ([('', '')], 'Default Unit Of Measure',),
42 'list_price': fields.selection ([('', '')], 'Sale Price',),
43 'standard_price': fields.selection ([('', '')], 'Cost Price',),
44 'name': fields.selection ([('', '')], 'Name' ,),
45 'procure_method': fields.selection ([('', '')], 'Procurement Method',),
46 'sale_delay': fields.selection ([('', '')], 'Customer Lead Time'),
47 'categ_id': fields.selection ([('', '')], 'Category',),
48 'code': fields.selection ([('', '')], 'Reference' ,),
49 'default_code': fields.selection ([('', '')], 'Reference',),
50 'name_template': fields.selection ([('', '')], 'Name',),
51 'partner_ref': fields.selection ([('', '')], 'Customer',),
52 'lst_price': fields.selection ([('', '')], 'Public Price',),
53 'warranty': fields.selection ([('', '')], 'Warranty',),
54 'produce_delay': fields.selection ([('', '')], 'Manufacturing Lead Time',),
55 'product_manager': fields.selection ([('', '')], 'Product Manager',),
56 'state': fields.selection ([('', '')], 'Status',),
57 'loc_rack': fields.selection ([('', '')], 'Rack',),
58 'loc_row': fields.selection ([('', '')], 'Row',),
59 'loc_case': fields.selection ([('', '')], 'Case',),
60 'description': fields.selection ([('', '')], 'Description',),
61 'description_sale': fields.selection ([('', '')], 'Sale Description',),
62 'description_purchase': fields.selection ([('', '')], 'Purchase Description',)
63 }
64
49 _values = {}65 _values = {}
5066
51 MERGE_SKIP_FIELDS = ['product_tmpl_id']67 MERGE_SKIP_FIELDS = ['product_tmpl_id', 'product_image']
5268
53 def _build_form(self, cr, uid, field_datas, value1, value2):69 def _build_form(self, cr, uid, field_datas, value1, value2):
54 formxml = '''<?xml version="1.0"?>70 formxml = '''<?xml version="1.0"?>
55 <form string="%s">71 <form string="%s" version="7.0">
56 <separator colspan="4" string="Select datas for new record"/>''' % _('Merge')72 <separator colspan="4" string="Select datas for new record"/>
73 <group>
74 ''' % _('Merge')
75
57 update_values = {}76 update_values = {}
58 update_fields = {}77 update_fields = {}
59 columns = {}78 columns = {}
@@ -61,7 +80,6 @@
61 for fid, fname, fdescription, ttype, required, relation, readonly in field_datas:80 for fid, fname, fdescription, ttype, required, relation, readonly in field_datas:
62 if fname in self.MERGE_SKIP_FIELDS:81 if fname in self.MERGE_SKIP_FIELDS:
63 continue82 continue
64
65 val1 = value1[fname]83 val1 = value1[fname]
66 val2 = value2[fname]84 val2 = value2[fname]
67 my_selection = []85 my_selection = []
@@ -82,8 +100,16 @@
82 if ttype in ('float', 'integer'):100 if ttype in ('float', 'integer'):
83 my_selection = [(str(val1), str(val1)), (str(val2), str(val2))]101 my_selection = [(str(val1), str(val1)), (str(val2), str(val2))]
84 if ttype in ('many2one'):102 if ttype in ('many2one'):
85 my_selection = [(str(val1.id), val1.name),103 val1_name = val1.name
86 (str(val2.id), val2.name)]104 val2_name = val2.name
105
106 if isinstance(val1_name, browse_record):
107 val1_name = val1_name.name
108 if isinstance(val2_name, browse_record):
109 val2_name = val2_name.name
110
111 my_selection = [(str(val1.id), val1_name),
112 (str(val2.id), val2_name)]
87 if ttype in ('many2many'):113 if ttype in ('many2many'):
88 update_values.update({fname: [(6, 0, list(set(map(lambda x: x.id, val1 + val2))))]})114 update_values.update({fname: [(6, 0, list(set(map(lambda x: x.id, val1 + val2))))]})
89 if my_selection:115 if my_selection:
@@ -104,11 +130,14 @@
104 update_values.update({fname: val1 or val2})130 update_values.update({fname: val1 or val2})
105131
106 formxml += """132 formxml += """
133 </group>
107 <separator colspan="4"/>134 <separator colspan="4"/>
108 <group col="4" colspan="4">135 <group col="4" colspan="4">
109 <label string="" colspan="2"/>136 <label string="" colspan="2"/>
110 <button special="cancel" string="Cancel" icon="gtk-cancel"/>137 <footer>
111 <button name="action_merge" string="Merge" type="object" icon="gtk-ok"/>138 <button special="cancel" string="Cancel" icon="gtk-cancel"/>
139 <button name="action_merge" string="Merge" type="object" icon="gtk-ok"/>
140 </footer>
112 </group>141 </group>
113 </form>"""142 </form>"""
114 return formxml, update_fields, update_values, columns143 return formxml, update_fields, update_values, columns
@@ -122,10 +151,13 @@
122 return True151 return True
123152
124 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):153 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
125 res = super(base_product_merge, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)154 if context is None:
155 context = {}
156 res = super(BaseProductMerge, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
126 resource_ids = context.get('active_ids') or []157 resource_ids = context.get('active_ids') or []
127158
128 self.check_resources_to_merge(cr, uid, resource_ids, context)159 if resource_ids:
160 self.check_resources_to_merge(cr, uid, resource_ids, context)
129161
130 if not len(resource_ids) == 2:162 if not len(resource_ids) == 2:
131 return res163 return res
@@ -161,7 +193,7 @@
161 @param ids: id of the wizard193 @param ids: id of the wizard
162 @param context: A standard dictionary for contextual values194 @param context: A standard dictionary for contextual values
163195
164 @return : dict to open the new product in a view196 @return: dict to open the new product in a view
165 """197 """
166 record_id = context and context.get('active_id', False) or False198 record_id = context and context.get('active_id', False) or False
167 pool = self.pool199 pool = self.pool
@@ -171,7 +203,7 @@
171203
172 res.update(self._values)204 res.update(self._values)
173 resource_ids = context.get('active_ids') or []205 resource_ids = context.get('active_ids') or []
174 206
175 self.check_resources_to_merge(cr, uid, resource_ids, context)207 self.check_resources_to_merge(cr, uid, resource_ids, context)
176208
177 resource1 = resource_ids[0]209 resource1 = resource_ids[0]
@@ -238,5 +270,4 @@
238 """270 """
239 pass271 pass
240272
241base_product_merge()273# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
242
243274
=== modified file 'base_product_merge/wizard/base_product_merge_view.xml'
--- base_product_merge/wizard/base_product_merge_view.xml 2011-11-07 14:29:04 +0000
+++ base_product_merge/wizard/base_product_merge_view.xml 2013-05-13 08:54:24 +0000
@@ -1,39 +1,41 @@
1<?xml version="1.0"?>1<?xml version="1.0"?>
2<openerp>2<openerp>
3 <data>3 <data>
44
5 <record model="ir.ui.view" id="view_base_product_merge_form">5 <record model="ir.ui.view" id="view_base_product_merge_form">
6 <field name="name">base.product.merge.form</field>6 <field name="name">base.product.merge.form</field>
7 <field name="model">base.product.merge</field>7 <field name="model">base.product.merge</field>
8 <field name="type">form</field>8 <field name="arch" type="xml">
9 <field name="arch" type="xml">9 <form string="Merge Products" version="7.0">
10 <form string="Merge Products">10 <group>
11 <label string="Merge Products"/>11 <label string="Merge Products"/>
12 <button special="cancel" string="Cancel" icon="gtk-cancel"/>12 </group>
13 </form>13 <footer>
14 </field>14 <button special="cancel" string="Cancel" icon="gtk-cancel"/>
15 </record>15 </footer>
1616 </form>
1717 </field>
18 <record id="action_base_product_merge_form" model="ir.actions.act_window">18 </record>
19 <field name="name">Merge Products</field>19
20 <field name="type">ir.actions.act_window</field>20 <record id="action_base_product_merge" model="ir.actions.act_window">
21 <field name="res_model">base.product.merge</field>21 <field name="name">Merge Products</field>
22 <field name="view_type">form</field>22 <field name="type">ir.actions.act_window</field>
23 <field name="view_mode">form</field>23 <field name="res_model">base.product.merge</field>
24 <field name="view_id" ref="view_base_product_merge_form"/>24 <field name="view_type">form</field>
25 <field name="target">new</field>25 <field name="view_mode">form</field>
26 </record>26 <field name="view_id" ref="view_base_product_merge_form"/>
2727 <field name="target">new</field>
28 <record id="ir_val_base_product_merge_form" model="ir.values">28 </record>
29 <field name="model_id" ref="product.model_product_product" />29
30 <field name="object" eval="1" />30 <record id="action_base_product_merge_form" model="ir.values">
31 <field name="name">Merge Products</field>31 <field name="model_id" ref="product.model_product_product" />
32 <field name="key2">client_action_multi</field>32 <field name="object" eval="1" />
33 <field name="value" eval="'ir.actions.act_window,' + str(ref('action_base_product_merge_form'))"/>33 <field name="name">Merge Products</field>
34 <field name="key">action</field>34 <field name="key2">client_action_multi</field>
35 <field name="model">product.product</field>35 <field name="value" eval="'ir.actions.act_window,' + str(ref('action_base_product_merge'))"/>
36 </record>36 <field name="key">action</field>
3737 <field name="model">product.product</field>
38 </data>38 </record>
39
40 </data>
39</openerp>41</openerp>

Subscribers

People subscribed via source and target branches