Add volume
issue4738 review9241002
This commit is contained in:
1 parent
1e9a425bc3
commit
e6d31cf13e
3 files changed
+61
-1
No files matched your search
@@ -1,6 +1,9 @@
|
||||
* Add volume
|
||||
|
||||
Version 3.6.0 - 2015-04-20
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Add support for PyPy
|
||||
|
||||
Version 3.4.0 - 2014-10-20
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
|
||||
|
||||
+55
-1
@@ -2,7 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval, Bool, Id
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
|
||||
__all__ = ['Template']
|
||||
__metaclass__ = PoolMeta
|
||||
@@ -58,6 +58,23 @@ class Template:
|
||||
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)),
|
||||
states={
|
||||
'invisible': Eval('type').in_(NON_MEASURABLE),
|
||||
'readonly': (Bool(Eval('length'))
|
||||
& Bool(Eval('height')) & Bool(Eval('width'))),
|
||||
},
|
||||
depends=['type', 'volume_digits'])
|
||||
volume_uom = fields.Many2One('product.uom', 'Volume Uom',
|
||||
domain=[('category', '=', Id('product', 'uom_cat_volume'))],
|
||||
states={
|
||||
'invisible': Eval('type').in_(NON_MEASURABLE),
|
||||
'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)),
|
||||
states={
|
||||
@@ -101,6 +118,43 @@ class Template:
|
||||
def default_width_digits():
|
||||
return 2
|
||||
|
||||
@fields.depends('volume', 'volume_uom',
|
||||
'length', 'length_uom',
|
||||
'height', 'height_uom',
|
||||
'width', 'width_uom')
|
||||
def on_change_with_volume(self):
|
||||
pool = Pool()
|
||||
ModelData = pool.get('ir.model.data')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
if not all([self.volume_uom, self.length, self.length_uom,
|
||||
self.height, self.height_uom, self.width, self.width_uom]):
|
||||
if all([self.length, self.height, self.width]):
|
||||
return
|
||||
return self.volume
|
||||
|
||||
meter = Uom(ModelData.get_id('product', 'uom_meter'))
|
||||
cubic_meter = Uom(ModelData.get_id('product', 'uom_cubic_meter'))
|
||||
|
||||
length = Uom.compute_qty(
|
||||
self.length_uom, self.length, meter, round=False)
|
||||
height = Uom.compute_qty(
|
||||
self.height_uom, self.height, meter, round=False)
|
||||
width = Uom.compute_qty(
|
||||
self.width_uom, self.width, meter, round=False)
|
||||
|
||||
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
|
||||
|
||||
@@ -13,6 +13,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="width"/>
|
||||
<field name="width"/>
|
||||
<field name="width_uom"/>
|
||||
<label name="volume"/>
|
||||
<field name="volume"/>
|
||||
<field name="volume_uom"/>
|
||||
<label name="weight"/>
|
||||
<field name="weight"/>
|
||||
<field name="weight_uom"/>
|
||||
|
||||
Reference in new issue
Block a user