changeset 3309d91c9587 in modules/product_measurements:default
details:
https://hg.tryton.org/modules/product_measurements?cmd=changeset&node=3309d91c9587
description:
Use DigitsMixin for quantity of measurements
issue10779
review373641016
diffstat:
product.py | 85 ++++++++++---------------------------------------------------
1 files changed, 15 insertions(+), 70 deletions(-)
diffs (154 lines):
diff -r fa9f606f5ff6 -r 3309d91c9587 product.py
--- a/product.py Sun Jul 04 17:54:47 2021 +0200
+++ b/product.py Wed Oct 06 00:56:39 2021 +0200
@@ -10,12 +10,12 @@
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
- length = fields.Float('Length',
- digits=(16, Eval('length_digits', 2)),
+ length = fields.Float(
+ "Length", digits='length_uom',
states={
'invisible': Eval('type').in_(NON_MEASURABLE),
},
- depends=['type', 'length_digits'])
+ depends=['type'])
length_uom = fields.Many2One('product.uom', 'Length Uom',
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
@@ -23,14 +23,12 @@
'required': Bool(Eval('length')),
},
depends=['type', 'length'])
- length_digits = fields.Function(fields.Integer('Length Digits'),
- 'on_change_with_length_digits')
- height = fields.Float('Height',
- digits=(16, Eval('height_digits', 2)),
+ height = fields.Float(
+ "Height", digits='height_uom',
states={
'invisible': Eval('type').in_(NON_MEASURABLE),
},
- depends=['type', 'height_digits'])
+ depends=['type'])
height_uom = fields.Many2One('product.uom', 'Height Uom',
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
@@ -38,14 +36,12 @@
'required': Bool(Eval('height')),
},
depends=['type', 'height'])
- height_digits = fields.Function(fields.Integer('Height Digits'),
- 'on_change_with_height_digits')
- width = fields.Float('Width',
- digits=(16, Eval('width_digits', 2)),
+ width = fields.Float(
+ "Width", digits='width_uom',
states={
'invisible': Eval('type').in_(NON_MEASURABLE),
},
- depends=['type', 'width_digits'])
+ depends=['type'])
width_uom = fields.Many2One('product.uom', 'Width Uom',
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
@@ -53,16 +49,14 @@
'required': Bool(Eval('width')),
},
depends=['type', 'width'])
- width_digits = fields.Function(fields.Integer('Width Digits'),
- 'on_change_with_width_digits')
- volume = fields.Float('Volume',
- digits=(16, Eval('volume_digits', 2)),
+ volume = fields.Float(
+ "Volume", digits='volume_uom',
states={
'invisible': Eval('type').in_(NON_MEASURABLE),
'readonly': (Bool(Eval('length'))
& Bool(Eval('height')) & Bool(Eval('width'))),
},
- depends=['type', 'volume_digits'])
+ depends=['type'])
volume_uom = fields.Many2One('product.uom', 'Volume Uom',
domain=[('category', '=', Id('product', 'uom_cat_volume'))],
states={
@@ -70,14 +64,12 @@
'required': Bool(Eval('volume')),
},
depends=['type', 'volume'])
- volume_digits = fields.Function(fields.Integer('Volume Digits'),
- 'on_change_with_volume_digits')
- weight = fields.Float('Weight',
- digits=(16, Eval('weight_digits', 2)),
+ weight = fields.Float(
+ "Weight", digits='weight_uom',
states={
'invisible': Eval('type').in_(NON_MEASURABLE),
},
- depends=['type', 'weight_digits'])
+ depends=['type'])
weight_uom = fields.Many2One('product.uom', 'Weight Uom',
domain=[('category', '=', Id('product', 'uom_cat_weight'))],
states={
@@ -85,35 +77,6 @@
'required': Bool(Eval('weight')),
},
depends=['type', 'weight'])
- weight_digits = fields.Function(fields.Integer('Weight Digits'),
- 'on_change_with_weight_digits')
-
- @fields.depends('length_uom')
- def on_change_with_length_digits(self, name=None):
- return (self.length_uom.digits if self.length_uom
- else self.default_length_digits())
-
- @staticmethod
- def default_length_digits():
- return 2
-
- @fields.depends('height_uom')
- def on_change_with_height_digits(self, name=None):
- return (self.height_uom.digits if self.height_uom
- else self.default_height_digits())
-
- @staticmethod
- def default_height_digits():
- return 2
-
- @fields.depends('width_uom')
- def on_change_with_width_digits(self, name=None):
- return (self.width_uom.digits if self.width_uom
- else self.default_width_digits())
-
- @staticmethod
- def default_width_digits():
- return 2
@fields.depends('volume', 'volume_uom',
'length', 'length_uom',
@@ -143,24 +106,6 @@
return Uom.compute_qty(
cubic_meter, length * height * width, self.volume_uom)
- @fields.depends('volume_uom')
- def on_change_with_volume_digits(self, name=None):
- return (self.volume_uom.digits if self.volume_uom
- else self.default_volume_digits())
-
- @staticmethod
- def default_volume_digits():
- return 2
-
- @fields.depends('weight_uom')
- def on_change_with_weight_digits(self, name=None):
- return (self.weight_uom.digits if self.weight_uom
- else self.default_weight_digits())
-
- @staticmethod
- def default_weight_digits():
- return 2
-
@classmethod
def view_attributes(cls):
return super(Template, cls).view_attributes() + [