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
1=== modified file 'base_product_merge/__init__.py'
2--- base_product_merge/__init__.py 2011-08-12 12:53:16 +0000
3+++ base_product_merge/__init__.py 2013-05-13 08:54:24 +0000
4@@ -1,1 +1,3 @@
5 import wizard
6+
7+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
8\ No newline at end of file
9
10=== modified file 'base_product_merge/__openerp__.py'
11--- base_product_merge/__openerp__.py 2013-02-13 08:46:41 +0000
12+++ base_product_merge/__openerp__.py 2013-05-13 08:54:24 +0000
13@@ -1,41 +1,30 @@
14 # -*- coding: utf-8 -*-
15 ##############################################################################
16 #
17-# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com)
18-# All Right Reserved
19-#
20-# Author : Guewen Baconnier (Camptocamp)
21-#
22-# WARNING: This program as such is intended to be used by professional
23-# programmers who take the whole responsability of assessing all potential
24-# consequences resulting from its eventual inadequacies and bugs
25-# End users who are looking for a ready-to-use solution with commercial
26-# garantees and support are strongly adviced to contract a Free Software
27-# Service Company
28-#
29-# This program is Free Software; you can redistribute it and/or
30-# modify it under the terms of the GNU General Public License
31-# as published by the Free Software Foundation; either version 2
32-# of the License, or (at your option) any later version.
33-#
34-# This program is distributed in the hope that it will be useful,
35-# but WITHOUT ANY WARRANTY; without even the implied warranty of
36-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37-# GNU General Public License for more details.
38-#
39-# You should have received a copy of the GNU General Public License
40-# along with this program; if not, write to the Free Software
41-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42+# Author: Guewen Baconnier
43+# Copyright 2011 Camptocamp SA
44+#
45+# This program is free software: you can redistribute it and/or modify
46+# it under the terms of the GNU Affero General Public License as
47+# published by the Free Software Foundation, either version 3 of the
48+# License, or (at your option) any later version.
49+#
50+# This program is distributed in the hope that it will be useful,
51+# but WITHOUT ANY WARRANTY; without even the implied warranty of
52+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53+# GNU Affero General Public License for more details.
54+#
55+# You should have received a copy of the GNU Affero General Public License
56+# along with this program. If not, see <http://www.gnu.org/licenses/>.
57 #
58 ##############################################################################
59
60 {
61- "name" : "Base Products Merge",
62- "version" : "1.0",
63- "author" : "Camptocamp",
64- "category" : "Generic Modules/Base",
65- "description":"""
66-To merge 2 products, select them in the list view and execute the Action "Merge Products".
67+ 'name' : 'Base Products Merge',
68+ 'version' : '1.0',
69+ 'category' : 'Generic Modules/Base',
70+ 'description':'''
71+To merge 2 products, select them in the list view and execute the Action 'Merge Products'.
72
73 The selected products are deactivated and a new one is created with :
74 - When a value is the same on each resources : the value
75@@ -44,14 +33,19 @@
76 - All many2many relations of the 2 resources are created on the new resource.
77 - All the one2many relations (invoices, sale_orders, ...) are updated in order to link to the new resource.
78
79-""",
80- "website": "http://camptocamp.com",
81- "depends" : ['product'],
82- "init_xml" : [],
83- "demo_xml" : [],
84- "update_xml" : [
85- "wizard/base_product_merge_view.xml",
86+''',
87+ 'author' : 'Camptocamp',
88+ 'website': 'http://camptocamp.com',
89+ 'depends' : ['product', 'purchase'],
90+ 'data' : [
91+ 'wizard/base_product_merge_view.xml',
92 ],
93- "active": False,
94- "installable": False
95+ 'demo' : [],
96+ 'test' : [],
97+ 'installable': True,
98+ 'auto_install' : False,
99+ 'application' : False,
100+
101 }
102+
103+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
104
105=== modified file 'base_product_merge/wizard/base_product_merge.py'
106--- base_product_merge/wizard/base_product_merge.py 2011-08-12 12:53:16 +0000
107+++ base_product_merge/wizard/base_product_merge.py 2013-05-13 08:54:24 +0000
108@@ -1,59 +1,78 @@
109 # -*- coding: utf-8 -*-
110-# -*- coding: utf-8 -*-
111 ##############################################################################
112 #
113-# Copyright (c) 2011 Camptocamp SA
114-# @author Guewen Baconnier
115-# Original code from module base_partner_merge by Tiny and Camptocamp
116-#
117-# WARNING: This program as such is intended to be used by professional
118-# programmers who take the whole responsability of assessing all potential
119-# consequences resulting from its eventual inadequacies and bugs
120-# End users who are looking for a ready-to-use solution with commercial
121-# garantees and support are strongly adviced to contract a Free Software
122-# Service Company
123-#
124-# This program is Free Software; you can redistribute it and/or
125-# modify it under the terms of the GNU General Public License
126-# as published by the Free Software Foundation; either version 2
127-# of the License, or (at your option) any later version.
128-#
129-# This program is distributed in the hope that it will be useful,
130-# but WITHOUT ANY WARRANTY; without even the implied warranty of
131-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132-# GNU General Public License for more details.
133-#
134-# You should have received a copy of the GNU General Public License
135-# along with this program; if not, write to the Free Software
136-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
137+# Author: Guewen Baconnier
138+# Copyright 2011 Camptocamp SA
139+#
140+# This program is free software: you can redistribute it and/or modify
141+# it under the terms of the GNU Affero General Public License as
142+# published by the Free Software Foundation, either version 3 of the
143+# License, or (at your option) any later version.
144+#
145+# This program is distributed in the hope that it will be useful,
146+# but WITHOUT ANY WARRANTY; without even the implied warranty of
147+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148+# GNU Affero General Public License for more details.
149+#
150+# You should have received a copy of the GNU Affero General Public License
151+# along with this program. If not, see <http://www.gnu.org/licenses/>.
152 #
153 ##############################################################################
154
155 # TODO : create a base_merge module to provide abstractions for merges ?
156
157-from osv import fields, osv
158+from openerp.osv import orm, fields, osv
159 from tools.translate import _
160 import tools
161-
162-
163-class base_product_merge(osv.osv_memory):
164- """
165- Merges two products
166- """
167+from osv.orm import browse_record
168+
169+class BaseProductMerge(orm.TransientModel):
170+ """ Merges two products """
171 _name = 'base.product.merge'
172- _description = 'Merges two products'
173+ _description = 'Merges Two Products'
174
175 _columns = {
176- }
177-
178+ 'uom_po_id': fields.selection([('', '')], 'Purchase Unit of Measure',),
179+ 'seller_id': fields.selection([('', '')], 'Seller',),
180+ 'seller_info_id': fields.selection([('', '')], 'SellerInfo'),
181+ 'supply_method': fields.selection([('', '')], 'Supply method',),
182+ 'seller_delay': fields.selection([('', '')], 'Supplier Lead Time',),
183+ 'type': fields.selection([('', '')], 'Product Type',),
184+ 'uom_id': fields.selection ([('', '')], 'Default Unit Of Measure',),
185+ 'list_price': fields.selection ([('', '')], 'Sale Price',),
186+ 'standard_price': fields.selection ([('', '')], 'Cost Price',),
187+ 'name': fields.selection ([('', '')], 'Name' ,),
188+ 'procure_method': fields.selection ([('', '')], 'Procurement Method',),
189+ 'sale_delay': fields.selection ([('', '')], 'Customer Lead Time'),
190+ 'categ_id': fields.selection ([('', '')], 'Category',),
191+ 'code': fields.selection ([('', '')], 'Reference' ,),
192+ 'default_code': fields.selection ([('', '')], 'Reference',),
193+ 'name_template': fields.selection ([('', '')], 'Name',),
194+ 'partner_ref': fields.selection ([('', '')], 'Customer',),
195+ 'lst_price': fields.selection ([('', '')], 'Public Price',),
196+ 'warranty': fields.selection ([('', '')], 'Warranty',),
197+ 'produce_delay': fields.selection ([('', '')], 'Manufacturing Lead Time',),
198+ 'product_manager': fields.selection ([('', '')], 'Product Manager',),
199+ 'state': fields.selection ([('', '')], 'Status',),
200+ 'loc_rack': fields.selection ([('', '')], 'Rack',),
201+ 'loc_row': fields.selection ([('', '')], 'Row',),
202+ 'loc_case': fields.selection ([('', '')], 'Case',),
203+ 'description': fields.selection ([('', '')], 'Description',),
204+ 'description_sale': fields.selection ([('', '')], 'Sale Description',),
205+ 'description_purchase': fields.selection ([('', '')], 'Purchase Description',)
206+ }
207+
208 _values = {}
209
210- MERGE_SKIP_FIELDS = ['product_tmpl_id']
211+ MERGE_SKIP_FIELDS = ['product_tmpl_id', 'product_image']
212
213 def _build_form(self, cr, uid, field_datas, value1, value2):
214 formxml = '''<?xml version="1.0"?>
215- <form string="%s">
216- <separator colspan="4" string="Select datas for new record"/>''' % _('Merge')
217+ <form string="%s" version="7.0">
218+ <separator colspan="4" string="Select datas for new record"/>
219+ <group>
220+ ''' % _('Merge')
221+
222 update_values = {}
223 update_fields = {}
224 columns = {}
225@@ -61,7 +80,6 @@
226 for fid, fname, fdescription, ttype, required, relation, readonly in field_datas:
227 if fname in self.MERGE_SKIP_FIELDS:
228 continue
229-
230 val1 = value1[fname]
231 val2 = value2[fname]
232 my_selection = []
233@@ -82,8 +100,16 @@
234 if ttype in ('float', 'integer'):
235 my_selection = [(str(val1), str(val1)), (str(val2), str(val2))]
236 if ttype in ('many2one'):
237- my_selection = [(str(val1.id), val1.name),
238- (str(val2.id), val2.name)]
239+ val1_name = val1.name
240+ val2_name = val2.name
241+
242+ if isinstance(val1_name, browse_record):
243+ val1_name = val1_name.name
244+ if isinstance(val2_name, browse_record):
245+ val2_name = val2_name.name
246+
247+ my_selection = [(str(val1.id), val1_name),
248+ (str(val2.id), val2_name)]
249 if ttype in ('many2many'):
250 update_values.update({fname: [(6, 0, list(set(map(lambda x: x.id, val1 + val2))))]})
251 if my_selection:
252@@ -104,11 +130,14 @@
253 update_values.update({fname: val1 or val2})
254
255 formxml += """
256+ </group>
257 <separator colspan="4"/>
258 <group col="4" colspan="4">
259 <label string="" colspan="2"/>
260- <button special="cancel" string="Cancel" icon="gtk-cancel"/>
261- <button name="action_merge" string="Merge" type="object" icon="gtk-ok"/>
262+ <footer>
263+ <button special="cancel" string="Cancel" icon="gtk-cancel"/>
264+ <button name="action_merge" string="Merge" type="object" icon="gtk-ok"/>
265+ </footer>
266 </group>
267 </form>"""
268 return formxml, update_fields, update_values, columns
269@@ -122,10 +151,13 @@
270 return True
271
272 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
273- res = super(base_product_merge, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
274+ if context is None:
275+ context = {}
276+ res = super(BaseProductMerge, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
277 resource_ids = context.get('active_ids') or []
278
279- self.check_resources_to_merge(cr, uid, resource_ids, context)
280+ if resource_ids:
281+ self.check_resources_to_merge(cr, uid, resource_ids, context)
282
283 if not len(resource_ids) == 2:
284 return res
285@@ -161,7 +193,7 @@
286 @param ids: id of the wizard
287 @param context: A standard dictionary for contextual values
288
289- @return : dict to open the new product in a view
290+ @return: dict to open the new product in a view
291 """
292 record_id = context and context.get('active_id', False) or False
293 pool = self.pool
294@@ -171,7 +203,7 @@
295
296 res.update(self._values)
297 resource_ids = context.get('active_ids') or []
298-
299+
300 self.check_resources_to_merge(cr, uid, resource_ids, context)
301
302 resource1 = resource_ids[0]
303@@ -238,5 +270,4 @@
304 """
305 pass
306
307-base_product_merge()
308-
309+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
310
311=== modified file 'base_product_merge/wizard/base_product_merge_view.xml'
312--- base_product_merge/wizard/base_product_merge_view.xml 2011-11-07 14:29:04 +0000
313+++ base_product_merge/wizard/base_product_merge_view.xml 2013-05-13 08:54:24 +0000
314@@ -1,39 +1,41 @@
315 <?xml version="1.0"?>
316 <openerp>
317- <data>
318-
319- <record model="ir.ui.view" id="view_base_product_merge_form">
320- <field name="name">base.product.merge.form</field>
321- <field name="model">base.product.merge</field>
322- <field name="type">form</field>
323- <field name="arch" type="xml">
324- <form string="Merge Products">
325- <label string="Merge Products"/>
326- <button special="cancel" string="Cancel" icon="gtk-cancel"/>
327- </form>
328- </field>
329- </record>
330-
331-
332- <record id="action_base_product_merge_form" model="ir.actions.act_window">
333- <field name="name">Merge Products</field>
334- <field name="type">ir.actions.act_window</field>
335- <field name="res_model">base.product.merge</field>
336- <field name="view_type">form</field>
337- <field name="view_mode">form</field>
338- <field name="view_id" ref="view_base_product_merge_form"/>
339- <field name="target">new</field>
340- </record>
341-
342- <record id="ir_val_base_product_merge_form" model="ir.values">
343- <field name="model_id" ref="product.model_product_product" />
344- <field name="object" eval="1" />
345- <field name="name">Merge Products</field>
346- <field name="key2">client_action_multi</field>
347- <field name="value" eval="'ir.actions.act_window,' + str(ref('action_base_product_merge_form'))"/>
348- <field name="key">action</field>
349- <field name="model">product.product</field>
350- </record>
351-
352- </data>
353+ <data>
354+
355+ <record model="ir.ui.view" id="view_base_product_merge_form">
356+ <field name="name">base.product.merge.form</field>
357+ <field name="model">base.product.merge</field>
358+ <field name="arch" type="xml">
359+ <form string="Merge Products" version="7.0">
360+ <group>
361+ <label string="Merge Products"/>
362+ </group>
363+ <footer>
364+ <button special="cancel" string="Cancel" icon="gtk-cancel"/>
365+ </footer>
366+ </form>
367+ </field>
368+ </record>
369+
370+ <record id="action_base_product_merge" model="ir.actions.act_window">
371+ <field name="name">Merge Products</field>
372+ <field name="type">ir.actions.act_window</field>
373+ <field name="res_model">base.product.merge</field>
374+ <field name="view_type">form</field>
375+ <field name="view_mode">form</field>
376+ <field name="view_id" ref="view_base_product_merge_form"/>
377+ <field name="target">new</field>
378+ </record>
379+
380+ <record id="action_base_product_merge_form" model="ir.values">
381+ <field name="model_id" ref="product.model_product_product" />
382+ <field name="object" eval="1" />
383+ <field name="name">Merge Products</field>
384+ <field name="key2">client_action_multi</field>
385+ <field name="value" eval="'ir.actions.act_window,' + str(ref('action_base_product_merge'))"/>
386+ <field name="key">action</field>
387+ <field name="model">product.product</field>
388+ </record>
389+
390+ </data>
391 </openerp>

Subscribers

People subscribed via source and target branches