changeset 2ada6c1d8568 in modules/product_price_list:default
details:
https://hg.tryton.org/modules/product_price_list?cmd=changeset;node=2ada6c1d8568
description:
Add unit per price list
We add a selection field on price list to define how to get the unit.
But also we remove the digits constraint on the quantity as it is
compared
against an non-rounded value.
issue8442
review255621002
diffstat:
CHANGELOG | 1 +
price_list.py | 22 ++++++++++++----------
view/price_list_form.xml | 6 ++++++
view/price_list_tree.xml | 1 +
4 files changed, 20 insertions(+), 10 deletions(-)
diffs (102 lines):
diff -r 1fa982cea16a -r 2ada6c1d8568 CHANGELOG
--- a/CHANGELOG Wed Jun 05 09:18:09 2019 +0200
+++ b/CHANGELOG Mon Jul 08 18:43:25 2019 +0200
@@ -1,3 +1,4 @@
+* Add unit per price list
* Make price list deactivable
Version 5.2.0 - 2019-05-06
diff -r 1fa982cea16a -r 2ada6c1d8568 price_list.py
--- a/price_list.py Wed Jun 05 09:18:09 2019 +0200
+++ b/price_list.py Mon Jul 08 18:43:25 2019 +0200
@@ -32,6 +32,10 @@
"It defines the currency of the price list."))
tax_included = fields.Boolean('Tax Included',
help="Check if result's formula includes taxes.")
+ unit = fields.Selection([
+ ('product_default', "Product Default"),
+ ], "Unit", required=True,
+ help="The unit in which the quantity is expressed.")
lines = fields.One2Many('product.price_list.line', 'price_list', 'Lines',
help="Add price formulas for different criterias.")
@@ -43,6 +47,10 @@
def default_tax_included():
return False
+ @classmethod
+ def default_unit(cls):
+ return 'product_default'
+
def get_context_formula(self, party, product, unit_price, quantity, uom,
pattern=None):
return {
@@ -51,6 +59,9 @@
},
}
+ def get_uom(self, product):
+ return product.default_uom
+
def compute(self, party, product, unit_price, quantity, uom,
pattern=None):
'Compute price based on price list of party'
@@ -72,7 +83,7 @@
c.id for c in parents(product.categories_all)]
pattern['product'] = product.id
pattern['quantity'] = Uom.compute_qty(uom, quantity,
- product.default_uom, round=False) if product else quantity
+ self.get_uom(product), round=False) if product else quantity
context = self.get_context_formula(
party, product, unit_price, quantity, uom, pattern=pattern)
@@ -96,12 +107,8 @@
help="Apply only to this product.")
quantity = fields.Float(
'Quantity',
- digits=(16, Eval('unit_digits', 2)),
domain=['OR', ('quantity', '>=', 0), ('quantity', '=', None)],
- depends=['unit_digits'],
help="Apply only when quantity is greater.")
- unit_digits = fields.Function(fields.Integer('Unit Digits'),
- 'on_change_with_unit_digits')
formula = fields.Char('Formula', required=True,
help=('Python expression that will be evaluated with:\n'
'- unit_price: the original unit_price'))
@@ -110,11 +117,6 @@
def default_formula():
return 'unit_price'
- @fields.depends('product')
- def on_change_with_unit_digits(self, name=None):
- if self.product:
- return self.product.default_uom.digits
-
@classmethod
def validate(cls, lines):
super(PriceListLine, cls).validate(lines)
diff -r 1fa982cea16a -r 2ada6c1d8568 view/price_list_form.xml
--- a/view/price_list_form.xml Wed Jun 05 09:18:09 2019 +0200
+++ b/view/price_list_form.xml Mon Jul 08 18:43:25 2019 +0200
@@ -14,6 +14,12 @@
<label name="company"/>
<field name="company"/>
+
+ <newline/>
+
+ <label name="unit"/>
+ <field name="unit"/>
+
<notebook colspan="4">
<page name="lines">
<field name="lines" colspan="4"
diff -r 1fa982cea16a -r 2ada6c1d8568 view/price_list_tree.xml
--- a/view/price_list_tree.xml Wed Jun 05 09:18:09 2019 +0200
+++ b/view/price_list_tree.xml Mon Jul 08 18:43:25 2019 +0200
@@ -4,4 +4,5 @@
<tree>
<field name="name"/>
<field name="tax_included"/>
+ <field name="unit"/>
</tree>