Merge lp:~therp-nl/openerp-product-attributes/7-0_fixed_price_extended into lp:~product-core-editors/openerp-product-attributes/7.0

Proposed by Ronald Portier (Therp) on 2014-03-30
Status: Needs review
Proposed branch: lp:~therp-nl/openerp-product-attributes/7-0_fixed_price_extended
Merge into: lp:~product-core-editors/openerp-product-attributes/7.0
Diff against target: 199 lines (+135/-10)
2 files modified
product_pricelist_fixed_price/model/product_pricelist_item.py (+100/-10)
product_pricelist_fixed_price/view/product_pricelist_item_view.xml (+35/-0)
To merge this branch: bzr merge lp:~therp-nl/openerp-product-attributes/7-0_fixed_price_extended
Reviewer Review Type Date Requested Status
Laetitia Gangloff (Acsone) (community) Resubmit on 2014-07-09
Product Core Editors 2014-03-30 Pending
Therp 2014-03-30 Pending
Serv. Tecnológicos Avanzados - Pedro M. Baeza 2014-03-30 Pending
Review via email: mp+213378@code.launchpad.net

Description of the change

This enhanced fixed pricelist item with the following;

- Make fixed pricelists items work when set through xmlrpc
- Make sure a fixed pricelist item does not have non zero values for rounding, or min. or max. margin
- Make sure a fixed pricelist item refers to a product
- Make fixed price attribute visible in product pricelist item tree view
- Hide all fields that should have non zero values when a pricelist item is set to fixed price.

To post a comment you must log in.
240. By Ronald Portier (Therp) on 2014-03-30

[FIX] base and base_ext fields should be kept synchronized.
[FIX] base_ext should get correct initial value when module is installed.

241. By Ronald Portier (Therp) on 2014-04-18

[FIX] Wrong test in check fixed price.

This project is now hosted on https://github.com/OCA/product-attribute. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Resubmit

Unmerged revisions

241. By Ronald Portier (Therp) on 2014-04-18

[FIX] Wrong test in check fixed price.

240. By Ronald Portier (Therp) on 2014-03-30

[FIX] base and base_ext fields should be kept synchronized.
[FIX] base_ext should get correct initial value when module is installed.

239. By Ronald Portier (Therp) on 2014-03-30

[FIX] Forgot to make irrelevant fields for fixed prices invisible in form.

238. By Ronald Portier (Therp) on 2014-03-30

[ENH] Make sure fixed prices have consistent values when set through
    xml-rpc calls.
[ENH] Make sured fixed prices have consistent values when prices had non-zero
    values for rounding or minimum and maximum marges before being changed
    into fixed price.
[ENH] Make fixed price visible in tree view.
[ENH] Make product required for fixed price.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product_pricelist_fixed_price/model/product_pricelist_item.py'
2--- product_pricelist_fixed_price/model/product_pricelist_item.py 2014-02-05 20:46:30 +0000
3+++ product_pricelist_fixed_price/model/product_pricelist_item.py 2014-04-18 09:49:50 +0000
4@@ -4,6 +4,7 @@
5 # OpenERP, Open Source Management Solution
6 # Copyright (c) 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
7 # Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
8+# 2014 Therp BV (http://www.therp.nl)
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published
12@@ -19,17 +20,22 @@
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #
15 ##############################################################################
16+'''All functionality to enable fixed prices in pricelists.'''
17 from openerp.osv import orm, fields
18 from openerp.tools.translate import _
19
20
21+FIXED_PRICE_TYPE = -3
22+
23 class product_pricelist_item(orm.Model):
24+ '''Inherit existing model to add functionality for fixed prices'''
25 _inherit = 'product.pricelist.item'
26
27 def _price_field_get_ext(self, cr, uid, context=None):
28- result = super(product_pricelist_item, self)._price_field_get(
29- cr, uid, context=context)
30- result.append((-3, _('Fixed Price')))
31+ result = super(
32+ product_pricelist_item, self)._price_field_get(
33+ cr, uid, context=context)
34+ result.append((FIXED_PRICE_TYPE, _('Fixed Price')))
35 return result
36
37 _columns = {
38@@ -41,11 +47,95 @@
39 'base_ext': -1,
40 }
41
42+ def _check_fixed_price(self, cr, uid, ids):
43+ '''Ensure fixed prices always refer to a specific product.'''
44+ for this_obj in self.browse(cr, uid, ids):
45+ if not this_obj.base_ext == FIXED_PRICE_TYPE:
46+ return True
47+ if not this_obj.product_id:
48+ raise orm.except_orm(
49+ _('Validation error!'),
50+ _('Product required for fixed price item.')
51+ )
52+ # Values for price_discount and price_round will not be checked,
53+ # because create and write will automagically set appropiate
54+ # values.
55+ return True
56+
57+ _constraints = [
58+ (_check_fixed_price,
59+ 'invalid values for fixed price', ['base_ext']),
60+ ]
61+
62+ def _auto_end(self, cr, context=None):
63+ '''Make sure that after updating database tables for this module,
64+ existing values in pricelist item are set correctly.'''
65+ cr.execute(
66+ 'update product_pricelist_item'
67+ ' set base_ext = base'
68+ ' where base_ext != -3 and base != base_ext'
69+ )
70+ return super(product_pricelist_item, self)._auto_end(
71+ cr, context=context)
72+
73+ def _modify_vals(self, cr, uid, vals, browse_obj=None, context=None):
74+ '''Ensure consistent values for fixed pricelist items.
75+ The passed vals parameter is used for both input and output.
76+ base should be 1 if base-ext = -1, in all other cases base and
77+ base_ext should be the same. The value passed should be leading,
78+ with the exception that a fixed price item should never be changed
79+ into something else through base.'''
80+ # Check wether any action is needed
81+ if not ('base_ext' in vals or 'base' in vals):
82+ return
83+ # Get base and base_ext values
84+ if 'base_ext' in vals:
85+ base_ext = vals['base_ext']
86+ base = (base_ext == FIXED_PRICE_TYPE) and 1 or base_ext
87+ else:
88+ # getting here we are sure base is in vals
89+ base = vals['base']
90+ # check against changing fixed price (should not happen)
91+ if browse_obj:
92+ assert browse_obj.base_ext != FIXED_PRICE_TYPE, (
93+ _('Can not change fixed pricelist item through base'))
94+ base_ext = base
95+ # Synchronize base and base_ext values
96+ vals.update({
97+ 'base_ext': base_ext,
98+ 'base': base,
99+ })
100+ # Make sure other values valid for fixed price
101+ if base_ext == FIXED_PRICE_TYPE:
102+ vals.update({
103+ 'price_discount': -1.0,
104+ 'price_round': 0.0,
105+ 'price_min_margin': 0.0,
106+ 'price_max_margin': 0.0,
107+ })
108+
109+ def create(self, cr, uid, vals, context=None):
110+ '''override create to get computed values'''
111+ self._modify_vals(cr, uid, vals, browse_obj=None, context=context)
112+ return super(product_pricelist_item, self).create(
113+ cr, uid, vals, context)
114+
115+ def write(self, cr, uid, ids, vals, context=None):
116+ '''override write to get computed values.
117+ We need the loop, because computed values might depend on existing
118+ values.'''
119+ for object_id in ids:
120+ browse_records = self.browse(
121+ cr, uid, [object_id], context=context)
122+ browse_obj = browse_records[0]
123+ self._modify_vals(
124+ cr, uid, vals, browse_obj=browse_obj, context=context)
125+ super(product_pricelist_item, self).write(
126+ cr, uid, [object_id], vals, context=context)
127+ return True
128+
129 def onchange_base_ext(self, cr, uid, ids, base_ext, context=None):
130- if base_ext == -3:
131- # Simulate be based on first found price that allows the trick
132- return {
133- 'value': {'base': 1,
134- 'price_discount': -1,}
135- }
136- return {'value': {'base': base_ext}}
137+ vals = {'base_ext': base_ext}
138+ self._modify_vals(cr, uid, vals, context=context)
139+ return {'value': vals}
140+
141
142=== modified file 'product_pricelist_fixed_price/view/product_pricelist_item_view.xml'
143--- product_pricelist_fixed_price/view/product_pricelist_item_view.xml 2014-02-05 20:46:30 +0000
144+++ product_pricelist_fixed_price/view/product_pricelist_item_view.xml 2014-04-18 09:49:50 +0000
145@@ -2,6 +2,25 @@
146 <openerp>
147 <data>
148
149+ <record
150+ id="product_pricelist_item_fixedprice_tree"
151+ model="ir.ui.view">
152+ <field name="name">product.pricelist.item.fixedprice.tree</field>
153+ <field name="model">product.pricelist.item</field>
154+ <field
155+ name="inherit_id"
156+ ref="product.product_pricelist_item_tree_view"
157+ />
158+ <field name="arch" type="xml">
159+ <field name="base" position="attributes">
160+ <attribute name="invisible">True</attribute>
161+ </field>
162+ <field name="base" position="after">
163+ <field name="base_ext" />
164+ </field>
165+ </field>
166+ </record>
167+
168 <record id="product_pricelist_item_fixedprice_form" model="ir.ui.view">
169 <field name="name">product.pricelist.item.fixedprice</field>
170 <field name="model">product.pricelist.item</field>
171@@ -10,6 +29,10 @@
172 <group string="Price Computation" position="attributes">
173 <attribute name="col">6</attribute>
174 </group>
175+ <field name="product_id" position="attributes">
176+ <attribute name="attrs"
177+ >{'required':[('base_ext','=',-3)]}</attribute>
178+ </field>
179 <field name="base" position="attributes">
180 <attribute name="invisible">True</attribute>
181 </field>
182@@ -28,6 +51,18 @@
183 <label string=" ) + " position="attributes">
184 <attribute name="attrs">{'invisible': [('base_ext', '=', -3)]}</attribute>
185 </label>
186+ <field name="price_round" position="attributes">
187+ <attribute name="attrs"
188+ >{'invisible': [('base_ext', '=', -3)]}</attribute>
189+ </field>
190+ <field name="price_min_margin" position="attributes">
191+ <attribute name="attrs"
192+ >{'invisible': [('base_ext', '=', -3)]}</attribute>
193+ </field>
194+ <field name="price_max_margin" position="attributes">
195+ <attribute name="attrs"
196+ >{'invisible': [('base_ext', '=', -3)]}</attribute>
197+ </field>
198 </field>
199 </record>
200

Subscribers

People subscribed via source and target branches