openerp-l10n-pt-pt team mailing list archive
-
openerp-l10n-pt-pt team
-
Mailing list archive
-
Message #00023
[Merge] lp:~gdukai/openobject-addons/product_price_update into lp:~openerp-community/openobject-addons/trunk-addons-community
Dukai Gábor has proposed merging lp:~gdukai/openobject-addons/product_price_update into lp:~openerp-community/openobject-addons/trunk-addons-community.
Requested reviews:
Dukai Gábor (gdukai)
--
https://code.launchpad.net/~gdukai/openobject-addons/product_price_update/+merge/5187
Your team OpenERP & OpenObject Community is subscribed to branch lp:~openerp-community/openobject-addons/trunk-addons-community.
=== added directory 'product_price_update'
=== added file 'product_price_update/__init__.py'
--- product_price_update/__init__.py 1970-01-01 00:00:00 +0000
+++ product_price_update/__init__.py 2009-03-02 16:14:11 +0000
@@ -0,0 +1,4 @@
+# -*- encoding: utf-8 -*-
+import pricelist
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
=== added file 'product_price_update/__terp__.py'
--- product_price_update/__terp__.py 1970-01-01 00:00:00 +0000
+++ product_price_update/__terp__.py 2009-03-02 16:14:11 +0000
@@ -0,0 +1,44 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Copyright (C) 2009 Gábor Dukai
+# Parts of this module are based on product_listprice_upgrade
+#
+# 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 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ "name":"Product price update",
+ "version":"1.0",
+ "author":"Gábor Dukai",
+ "website" : "http://exploringopenerp.blogspot.com",
+ "category":"Generic Modules/Inventory Control",
+ "description": """
+ The aim of this module is to allow the automatic update of the price fields of products.
+ * added a new pricelist type called 'Internal Pricelist' (currently, we have only 2 pricelist types: Sale and Purchase Pricelist)
+ * Created a wizard button in the menu Products>Pricelist called 'Update Product Prices'
+ * 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.
+ """,
+ "depends":["product"],
+ "demo_xml":[],
+ "update_xml":[
+ 'security/ir.model.access.csv',
+ 'pricelist_view.xml',
+ 'pricelist_data.xml'],
+ "license": "GPL-3",
+ "active":False,
+ "installable":True,
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
=== added file 'product_price_update/pricelist.py'
--- product_price_update/pricelist.py 1970-01-01 00:00:00 +0000
+++ product_price_update/pricelist.py 2009-04-02 15:32:09 +0000
@@ -0,0 +1,101 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Copyright (C) 2009 Gábor Dukai
+# Parts of this module are based on product_listprice_upgrade
+#
+# 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 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from osv import fields, osv
+from tools.misc import debug
+
+class product_price_update_wizard(osv.osv_memory):
+ """This is the main part of the module. After filling in the form, a
+ button calls action_update() to update the prices."""
+ _name = 'product.price.update.wizard'
+
+ _columns = {
+ 'price_type_id': fields.many2one('product.price.type', 'Price to Update', \
+ required=True, change_default=True),
+ 'pricelist_id': fields.many2one('product.pricelist', 'Select a Pricelist', \
+ required=True, domain=[('type', '=', 'internal')]),
+ 'categ_ids': fields.many2many('product.category', 'product_category_rel', \
+ 'pricewizard_ids', 'categ_ids', 'Select Product Categories', required=True),
+ 'upgrade': fields.boolean('Update child categories'),
+ }
+
+ _defaults = {
+ 'upgrade': lambda *a: 1,
+ }
+
+ def action_update(self, cr, uid, ids, context=None):
+ """The recursive _update() function is called for every selected
+ product category. _update() uses the selected pricelist to calculate
+ the prices and the results are written to the product object."""
+ pricelist_obj = self.pool.get('product.pricelist')
+ cat_obj = self.pool.get('product.category')
+ prod_obj = self.pool.get('product.product')
+
+ wiz = self.browse(cr, uid, ids[0])
+ done = set()
+ self.updated_products = 0
+ def _update(categ_id):
+ if wiz.upgrade:
+ child_ids = cat_obj.search(cr, uid, [('parent_id', '=', categ_id),])
+ for child_id in child_ids:
+ _update(child_id)
+ #if both parent and child categories are given in wiz.categ_ids, then
+ #the child categories would be computed twice because of the recursion
+ if categ_id not in done:
+ prod_ids = prod_obj.search(cr, uid, [('categ_id', '=', categ_id),])
+ for prod_id in prod_ids:
+ price = pricelist_obj.price_get(cr, uid, \
+ [wiz.pricelist_id.id], prod_id, 1)
+ prod_obj.write(cr, uid, [prod_id], {
+ wiz.price_type_id.field: price[wiz.pricelist_id.id]})
+ self.updated_products += 1
+ done.add(categ_id)
+ for categ_id in (br.id for br in wiz.categ_ids):
+ _update(categ_id)
+ return {
+ "context" : {'updated_field': wiz.price_type_id.name,
+ 'updated_products': self.updated_products,},
+ 'view_type': 'form',
+ "view_mode": 'form',
+ 'res_model': 'product.price.update.wizard.done',
+ 'type': 'ir.actions.act_window',
+ 'target':'new',
+ }
+
+
+product_price_update_wizard()
+
+class product_price_update_wizard_done(osv.osv_memory):
+ """Displays the main wizard's results. This is called with the
+ return statement of the main wizard and context is used to pass
+ the field values."""
+ _name = 'product.price.update.wizard.done'
+
+ _columns = {
+ 'updated_field': fields.char('Updated price type', size=30, readonly=True),
+ 'updated_products': fields.float('Number of updated products', readonly=True),
+ }
+
+ _defaults = {
+ 'updated_field': lambda self, cr, uid, c: c['updated_field'],
+ 'updated_products': lambda self, cr, uid, c: c['updated_products'],
+ }
+
+product_price_update_wizard_done()
\ No newline at end of file
=== added file 'product_price_update/pricelist_data.xml'
--- product_price_update/pricelist_data.xml 1970-01-01 00:00:00 +0000
+++ product_price_update/pricelist_data.xml 2009-03-02 16:14:11 +0000
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<openerp>
+ <data noupdate="1">
+
+ <record model="product.pricelist.type" id="pricelist_type_internal">
+ <field name="name">Internal Pricelist</field>
+ <field name="key">internal</field>
+ </record>
+ </data>
+</openerp>
=== added file 'product_price_update/pricelist_view.xml'
--- product_price_update/pricelist_view.xml 1970-01-01 00:00:00 +0000
+++ product_price_update/pricelist_view.xml 2009-03-04 08:18:44 +0000
@@ -0,0 +1,51 @@
+<?xml version="1.0" ?>
+<openerp>
+ <data>
+ <record id="view_price_update_wizard_done" model="ir.ui.view">
+ <field name="name">Updated the price of products</field>
+ <field name="model">product.price.update.wizard.done</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form col="2" string="Updated the price of products">
+ <field name="updated_field"/>
+ <field name="updated_products"/>
+ <group col="1" colspan="1">
+ <button icon="gtk-ok" special="cancel" string="End"/>
+ </group>
+ </form>
+ </field>
+ </record>
+ <record id="view_price_update_wizard" model="ir.ui.view">
+ <field name="name">Update Product Prices</field>
+ <field name="model">product.price.update.wizard</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Update Product Prices">
+ <separator colspan="4" string="Price to Update"/>
+ <field colspan="4" name="price_type_id" nolabel="1"/>
+ <separator colspan="4" string="Select a Pricelist"/>
+ <field colspan="4" name="pricelist_id" nolabel="1"/>
+ <separator colspan="4" string="Select Product Categories"/>
+ <field colspan="4" name="categ_ids" nolabel="1"/>
+ <field name="upgrade"/>
+ <newline/>
+ <group col="2" colspan="2">
+ <button icon="gtk-cancel" special="cancel" string="Cancel"/>
+ <button icon="gtk-ok" name="action_update" string="Update" type="object"/>
+ </group>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_price_update_wizard" model="ir.actions.act_window">
+ <field name="name">Update Product Prices</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">product.price.update.wizard</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
+ <menuitem id="menu_wizard_pricelist_update" parent="product.menu_product_pricelist_main" action="action_price_update_wizard"/>
+ </data>
+</openerp>
=== added directory 'product_price_update/security'
=== added file 'product_price_update/security/ir.model.access.csv'
--- product_price_update/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ product_price_update/security/ir.model.access.csv 2009-03-02 16:14:11 +0000
@@ -0,0 +1,3 @@
+"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
+"access_product_price_update_wizard","product.price.update.wizard","model_product_price_update_wizard","product.group_product_manager",1,1,1,1
+"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
References