Merge lp:~gdukai/openobject-addons/product_price_update into lp:openobject-addons/extra-trunk

Proposed by Dukai Gábor
Status: Merged
Merge reported by: Dukai Gábor
Merged at revision: not available
Proposed branch: lp:~gdukai/openobject-addons/product_price_update
Merge into: lp:openobject-addons/extra-trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~gdukai/openobject-addons/product_price_update
Reviewer Review Type Date Requested Status
Husen Daudi Needs Information
Review via email: mp+6008@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dukai Gábor (gdukai) wrote :

This is a rewrite of the extra-addons/product_listprice_upgrade module.
It has several improvements over the original:
-Possible to update any price type not just the list price.
-Correctly uses recursion and checks to update a price only one time even if parent and child categories are selected.
-Rewritten using the new osv_memory objects (the old module used wizard.interface).
-Corrects a menu duplication.

Revision history for this message
Husen Daudi (husendaudi) wrote :

Hello Dukai Gábor,

The current code in trunk extra addons seems better than this merge proposal.
This part of code prevents useless calls.
if round(price_old, int(config['price_accuracy'])) != round(price_new, int(config['price_accuracy'])):
      prod_obj.write(cr, uid, [prod.id], {wiz.price_type_id.field: price_new})

Shall I merge this branch?

Thanks.
HDA

review: Needs Information
Revision history for this message
Dukai Gábor (gdukai) wrote :

Thank you for looking at this merge proposal.
By now, I have commit rights to extra-addons and committed the module myself. The latest version is the one in trunk-extra-addons.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'product_price_update'
2=== added file 'product_price_update/__init__.py'
3--- product_price_update/__init__.py 1970-01-01 00:00:00 +0000
4+++ product_price_update/__init__.py 2009-03-02 16:14:11 +0000
5@@ -0,0 +1,4 @@
6+# -*- encoding: utf-8 -*-
7+import pricelist
8+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
9+
10
11=== added file 'product_price_update/__terp__.py'
12--- product_price_update/__terp__.py 1970-01-01 00:00:00 +0000
13+++ product_price_update/__terp__.py 2009-03-02 16:14:11 +0000
14@@ -0,0 +1,44 @@
15+# -*- encoding: utf-8 -*-
16+##############################################################################
17+#
18+# Copyright (C) 2009 Gábor Dukai
19+# Parts of this module are based on product_listprice_upgrade
20+#
21+# This program is free software: you can redistribute it and/or modify
22+# it under the terms of the GNU General Public License as published by
23+# the Free Software Foundation, either version 3 of the License, or
24+# (at your option) any later version.
25+#
26+# This program is distributed in the hope that it will be useful,
27+# but WITHOUT ANY WARRANTY; without even the implied warranty of
28+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+# GNU General Public License for more details.
30+#
31+# You should have received a copy of the GNU General Public License
32+# along with this program. If not, see <http://www.gnu.org/licenses/>.
33+#
34+##############################################################################
35+{
36+ "name":"Product price update",
37+ "version":"1.0",
38+ "author":"Gábor Dukai",
39+ "website" : "http://exploringopenerp.blogspot.com",
40+ "category":"Generic Modules/Inventory Control",
41+ "description": """
42+ The aim of this module is to allow the automatic update of the price fields of products.
43+ * added a new pricelist type called 'Internal Pricelist' (currently, we have only 2 pricelist types: Sale and Purchase Pricelist)
44+ * Created a wizard button in the menu Products>Pricelist called 'Update Product Prices'
45+ * After filling in the wizard form and clicking on 'Update', it will change the selected price field of all products in the categories that we were selected in the wizard.
46+ """,
47+ "depends":["product"],
48+ "demo_xml":[],
49+ "update_xml":[
50+ 'security/ir.model.access.csv',
51+ 'pricelist_view.xml',
52+ 'pricelist_data.xml'],
53+ "license": "GPL-3",
54+ "active":False,
55+ "installable":True,
56+}
57+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
58+
59
60=== added file 'product_price_update/pricelist.py'
61--- product_price_update/pricelist.py 1970-01-01 00:00:00 +0000
62+++ product_price_update/pricelist.py 2009-04-02 15:32:09 +0000
63@@ -0,0 +1,101 @@
64+# -*- encoding: utf-8 -*-
65+##############################################################################
66+#
67+# Copyright (C) 2009 Gábor Dukai
68+# Parts of this module are based on product_listprice_upgrade
69+#
70+# This program is free software: you can redistribute it and/or modify
71+# it under the terms of the GNU General Public License as published by
72+# the Free Software Foundation, either version 3 of the License, or
73+# (at your option) any later version.
74+#
75+# This program is distributed in the hope that it will be useful,
76+# but WITHOUT ANY WARRANTY; without even the implied warranty of
77+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78+# GNU General Public License for more details.
79+#
80+# You should have received a copy of the GNU General Public License
81+# along with this program. If not, see <http://www.gnu.org/licenses/>.
82+#
83+##############################################################################
84+from osv import fields, osv
85+from tools.misc import debug
86+
87+class product_price_update_wizard(osv.osv_memory):
88+ """This is the main part of the module. After filling in the form, a
89+ button calls action_update() to update the prices."""
90+ _name = 'product.price.update.wizard'
91+
92+ _columns = {
93+ 'price_type_id': fields.many2one('product.price.type', 'Price to Update', \
94+ required=True, change_default=True),
95+ 'pricelist_id': fields.many2one('product.pricelist', 'Select a Pricelist', \
96+ required=True, domain=[('type', '=', 'internal')]),
97+ 'categ_ids': fields.many2many('product.category', 'product_category_rel', \
98+ 'pricewizard_ids', 'categ_ids', 'Select Product Categories', required=True),
99+ 'upgrade': fields.boolean('Update child categories'),
100+ }
101+
102+ _defaults = {
103+ 'upgrade': lambda *a: 1,
104+ }
105+
106+ def action_update(self, cr, uid, ids, context=None):
107+ """The recursive _update() function is called for every selected
108+ product category. _update() uses the selected pricelist to calculate
109+ the prices and the results are written to the product object."""
110+ pricelist_obj = self.pool.get('product.pricelist')
111+ cat_obj = self.pool.get('product.category')
112+ prod_obj = self.pool.get('product.product')
113+
114+ wiz = self.browse(cr, uid, ids[0])
115+ done = set()
116+ self.updated_products = 0
117+ def _update(categ_id):
118+ if wiz.upgrade:
119+ child_ids = cat_obj.search(cr, uid, [('parent_id', '=', categ_id),])
120+ for child_id in child_ids:
121+ _update(child_id)
122+ #if both parent and child categories are given in wiz.categ_ids, then
123+ #the child categories would be computed twice because of the recursion
124+ if categ_id not in done:
125+ prod_ids = prod_obj.search(cr, uid, [('categ_id', '=', categ_id),])
126+ for prod_id in prod_ids:
127+ price = pricelist_obj.price_get(cr, uid, \
128+ [wiz.pricelist_id.id], prod_id, 1)
129+ prod_obj.write(cr, uid, [prod_id], {
130+ wiz.price_type_id.field: price[wiz.pricelist_id.id]})
131+ self.updated_products += 1
132+ done.add(categ_id)
133+ for categ_id in (br.id for br in wiz.categ_ids):
134+ _update(categ_id)
135+ return {
136+ "context" : {'updated_field': wiz.price_type_id.name,
137+ 'updated_products': self.updated_products,},
138+ 'view_type': 'form',
139+ "view_mode": 'form',
140+ 'res_model': 'product.price.update.wizard.done',
141+ 'type': 'ir.actions.act_window',
142+ 'target':'new',
143+ }
144+
145+
146+product_price_update_wizard()
147+
148+class product_price_update_wizard_done(osv.osv_memory):
149+ """Displays the main wizard's results. This is called with the
150+ return statement of the main wizard and context is used to pass
151+ the field values."""
152+ _name = 'product.price.update.wizard.done'
153+
154+ _columns = {
155+ 'updated_field': fields.char('Updated price type', size=30, readonly=True),
156+ 'updated_products': fields.float('Number of updated products', readonly=True),
157+ }
158+
159+ _defaults = {
160+ 'updated_field': lambda self, cr, uid, c: c['updated_field'],
161+ 'updated_products': lambda self, cr, uid, c: c['updated_products'],
162+ }
163+
164+product_price_update_wizard_done()
165\ No newline at end of file
166
167=== added file 'product_price_update/pricelist_data.xml'
168--- product_price_update/pricelist_data.xml 1970-01-01 00:00:00 +0000
169+++ product_price_update/pricelist_data.xml 2009-03-02 16:14:11 +0000
170@@ -0,0 +1,10 @@
171+<?xml version="1.0"?>
172+<openerp>
173+ <data noupdate="1">
174+
175+ <record model="product.pricelist.type" id="pricelist_type_internal">
176+ <field name="name">Internal Pricelist</field>
177+ <field name="key">internal</field>
178+ </record>
179+ </data>
180+</openerp>
181
182=== added file 'product_price_update/pricelist_view.xml'
183--- product_price_update/pricelist_view.xml 1970-01-01 00:00:00 +0000
184+++ product_price_update/pricelist_view.xml 2009-03-04 08:18:44 +0000
185@@ -0,0 +1,51 @@
186+<?xml version="1.0" ?>
187+<openerp>
188+ <data>
189+ <record id="view_price_update_wizard_done" model="ir.ui.view">
190+ <field name="name">Updated the price of products</field>
191+ <field name="model">product.price.update.wizard.done</field>
192+ <field name="type">form</field>
193+ <field name="arch" type="xml">
194+ <form col="2" string="Updated the price of products">
195+ <field name="updated_field"/>
196+ <field name="updated_products"/>
197+ <group col="1" colspan="1">
198+ <button icon="gtk-ok" special="cancel" string="End"/>
199+ </group>
200+ </form>
201+ </field>
202+ </record>
203+ <record id="view_price_update_wizard" model="ir.ui.view">
204+ <field name="name">Update Product Prices</field>
205+ <field name="model">product.price.update.wizard</field>
206+ <field name="type">form</field>
207+ <field name="arch" type="xml">
208+ <form string="Update Product Prices">
209+ <separator colspan="4" string="Price to Update"/>
210+ <field colspan="4" name="price_type_id" nolabel="1"/>
211+ <separator colspan="4" string="Select a Pricelist"/>
212+ <field colspan="4" name="pricelist_id" nolabel="1"/>
213+ <separator colspan="4" string="Select Product Categories"/>
214+ <field colspan="4" name="categ_ids" nolabel="1"/>
215+ <field name="upgrade"/>
216+ <newline/>
217+ <group col="2" colspan="2">
218+ <button icon="gtk-cancel" special="cancel" string="Cancel"/>
219+ <button icon="gtk-ok" name="action_update" string="Update" type="object"/>
220+ </group>
221+ </form>
222+ </field>
223+ </record>
224+
225+ <record id="action_price_update_wizard" model="ir.actions.act_window">
226+ <field name="name">Update Product Prices</field>
227+ <field name="type">ir.actions.act_window</field>
228+ <field name="res_model">product.price.update.wizard</field>
229+ <field name="view_type">form</field>
230+ <field name="view_mode">form</field>
231+ <field name="target">new</field>
232+ </record>
233+
234+ <menuitem id="menu_wizard_pricelist_update" parent="product.menu_product_pricelist_main" action="action_price_update_wizard"/>
235+ </data>
236+</openerp>
237
238=== added directory 'product_price_update/security'
239=== added file 'product_price_update/security/ir.model.access.csv'
240--- product_price_update/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
241+++ product_price_update/security/ir.model.access.csv 2009-03-02 16:14:11 +0000
242@@ -0,0 +1,3 @@
243+"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
244+"access_product_price_update_wizard","product.price.update.wizard","model_product_price_update_wizard","product.group_product_manager",1,1,1,1
245+"access_product_price_update_wizard_done","product.price.update.wizard.done","model_product_price_update_wizard_done","product.group_product_manager",1,1,1,1

Subscribers

People subscribed via source and target branches