~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to product_listprice_upgrade/wizard/wizard_product_listprice.py

  • Committer: Harshad Modi
  • Date: 2008-03-03 09:34:42 UTC
  • Revision ID: hmo@tinyerp.com-8adb20bb4b1f80ed4376d8e7334769274c4b1bfe
product_listprice_upgrade :
The aim of this module is to allow the automatic upgrade of the field 'List Price' on each product.
    * added a new price type called 'Internal Pricelist' (currently, we have only 2 price types: Sale and Purchase Pricelist)
    * Created a wizard button in the menu Products>Pricelist called 'Upgrade Product List Price'
    * When we have completed the wizard and click on 'Upgrade', it will change the field 'List Price' for all products contained in the categories that we have selected in the wizard

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
 
 
30
 
 
31
import pooler
 
32
import time
 
33
import wizard
 
34
 
 
35
_pricelist_form = '''<?xml version="1.0"?>
 
36
<form string="Upgrade list price">
 
37
    <separator string="Select a pricelist " colspan="4"/>
 
38
    <field name="pricelist" colspan="4" nolabel="1"/>
 
39
    <separator string="Select Product Categories " colspan="4"/>
 
40
    <field name="product_category" colspan="4" nolabel="1"/>
 
41
    <newline/>
 
42
    <field name="upgrade" />
 
43
</form>'''
 
44
 
 
45
_done_form = '''<?xml version="1.0"?>
 
46
<form string="Upgraded list price of prodcuts">
 
47
    <field name="update_products"/>
 
48
 
 
49
</form>'''
 
50
 
 
51
_done_fields = {
 
52
    'update_products': {'string':'Upgraded list price of Products', 'type':'float', 'readonly': True},
 
53
 
 
54
 
 
55
}
 
56
 
 
57
class wizard_product_pricelist(wizard.interface):
 
58
 
 
59
 
 
60
    def _get_pricelist(self, cr, uid, context):
 
61
        pricelist_obj=pooler.get_pool(cr.dbname).get('product.pricelist')
 
62
        ids=pricelist_obj.search(cr, uid, [('type', '=', 'internal'),])
 
63
        pricelists=pricelist_obj.browse(cr, uid, ids)
 
64
        return [(pricelist.id, pricelist.name ) for pricelist in pricelists]
 
65
 
 
66
    def _upgrade_listprice(self, cr, uid, data, context):
 
67
        self.update_products=0
 
68
        categories_ids=data['form']['product_category']
 
69
        pricelist_obj=pooler.get_pool(cr.dbname).get('product.pricelist')
 
70
        cat_obj = pooler.get_pool(cr.dbname).get('product.category')
 
71
        product_obj = pooler.get_pool(cr.dbname).get('product.product')
 
72
        pricelist_id=data['form']['pricelist']
 
73
 
 
74
        def _upgrade(category_id):
 
75
            if data['form']['upgrade']==True:
 
76
                child_ids=cat_obj.search(cr, uid, [('parent_id', '=', category_id),])
 
77
                for child_id in child_ids:
 
78
                    _upgrade(child_id)
 
79
            product_ids=product_obj.search(cr, uid, [('categ_id', '=', category_id),])
 
80
            for product_id in product_ids:
 
81
                list_price=pricelist_obj.price_get(cr, uid, [pricelist_id], product_id, 1)
 
82
                product_obj.write(cr, uid, [product_id], {
 
83
                            'list_price': list_price[pricelist_id]})
 
84
                self.update_products += 1
 
85
 
 
86
        for category_id in categories_ids[0][2]:
 
87
            _upgrade(category_id)
 
88
 
 
89
        return {'update_products':self.update_products}
 
90
 
 
91
    _pricelist_fields = {
 
92
        'pricelist': {'string':'Pricelist', 'type':'many2one', 'relation': 'product.pricelist','domain':[('type','=','internal')], 'required':True},
 
93
        'product_category': {'string':'Product Category', 'type':'many2many', 'relation': 'product.category', 'required':True},
 
94
        'upgrade' : {'string':'Upgrade Child categories', 'type':'boolean', 'default': lambda x,y,z: True}
 
95
    }
 
96
 
 
97
    states = {
 
98
        'init': {
 
99
            'actions': [],
 
100
            'result': {'type':'form', 'arch':_pricelist_form, 'fields':_pricelist_fields, 'state':[('end','Cancel'),('upgrade','Upgrade')]}
 
101
        },
 
102
        'upgrade':{
 
103
             'actions':[_upgrade_listprice],
 
104
             'result':{'type': 'form', 'arch': _done_form, 'fields': _done_fields,'state':[('end', 'End')]}
 
105
       }
 
106
    }
 
107
wizard_product_pricelist('product.listprice')
 
 
b'\\ No newline at end of file'