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

Subscribers

People subscribed via source and target branches