changeset 78a98bdfedee in modules/stock_shipment_measurements:default
details:
https://hg.tryton.org/modules/stock_shipment_measurements?cmd=changeset&node=78a98bdfedee
description:
Add volume dimensions to package
issue11214
review397221003
diffstat:
stock.py | 37 ++++++++++++++++++++++--------
tests/test_stock_shipment_measurements.py | 7 +++++-
view/shipment_form_package.xml | 4 +++
view/shipment_list_package.xml | 3 +-
4 files changed, 39 insertions(+), 12 deletions(-)
diffs (112 lines):
diff -r 54ce1bd8b873 -r 78a98bdfedee stock.py
--- a/stock.py Thu Feb 03 23:13:27 2022 +0100
+++ b/stock.py Mon Mar 07 00:30:47 2022 +0100
@@ -402,13 +402,20 @@
def _measurements_location_condition(cls, package, move, location):
return move.to_location == location.id
- def get_total_measurements(self, name):
+ def get_total_measurements(self, name, round=True):
pool = Pool()
Uom = pool.get('product.uom')
+ field = name[len('total_'):]
- field = name[len('total_'):]
- measurement = ((getattr(self, field) or 0)
- + sum(p.get_total_measurements(name) for p in self.children))
+ if name == 'total_volume' and self.packaging_volume is not None:
+ return Uom.compute_qty(
+ self.packaging_volume_uom, self.packaging_volume,
+ self.volume_uom, round=round)
+
+ measurement = (
+ (getattr(self, field) or 0)
+ + sum(p.get_total_measurements(name, round=False)
+ for p in self.children))
if name == 'total_weight':
if self.additional_weight:
measurement += Uom.compute_qty(
@@ -418,19 +425,29 @@
measurement += Uom.compute_qty(
self.packaging_weight_uom, self.packaging_weight,
self.weight_uom, round=False)
- return measurement
+ if round:
+ return getattr(self, field + '_uom').round(measurement)
+ else:
+ return measurement
class MeasurementsPackageMixin:
__slots__ = ()
packages_weight = fields.Function(
- fields.Float("Packages Weight", digits=None,
- help="The total weight of the packages in kg."),
- 'get_packages_weight')
+ fields.Float("Packages Weight", digits='weight_uom',
+ help="The total weight of the packages."),
+ 'get_packages_measurements')
+ packages_volume = fields.Function(
+ fields.Float("Packages Volume", digits='volume_uom',
+ help="The total volume of the packages."),
+ 'get_packages_measurements')
- def get_packages_weight(self, name):
- return sum(p.total_weight for p in self.root_packages)
+ def get_packages_measurements(self, name):
+ name = name[len('packages_'):]
+ uom = getattr(self, name + '_uom')
+ return uom.round(
+ sum(getattr(p, 'total_' + name)for p in self.root_packages))
class ShipmentOutPackage(MeasurementsPackageMixin, metaclass=PoolMeta):
diff -r 54ce1bd8b873 -r 78a98bdfedee tests/test_stock_shipment_measurements.py
--- a/tests/test_stock_shipment_measurements.py Thu Feb 03 23:13:27 2022 +0100
+++ b/tests/test_stock_shipment_measurements.py Mon Mar 07 00:30:47 2022 +0100
@@ -198,6 +198,8 @@
package_root.type = package_type
package_root.shipment = shipment
package_root.additional_weight = 1
+ package_root.packaging_volume = 3
+ package_root.packaging_volume_uom = liter
package_root.save()
package = Package()
@@ -214,7 +216,10 @@
self.assertEqual(package.volume, 2)
self.assertEqual(package_root.total_weight, 11)
- self.assertEqual(package_root.total_volume, 2)
+ self.assertEqual(package_root.total_volume, 3)
+
+ self.assertEqual(package.total_weight, 10)
+ self.assertEqual(package.total_volume, 2)
def suite():
diff -r 54ce1bd8b873 -r 78a98bdfedee view/shipment_form_package.xml
--- a/view/shipment_form_package.xml Thu Feb 03 23:13:27 2022 +0100
+++ b/view/shipment_form_package.xml Mon Mar 07 00:30:47 2022 +0100
@@ -6,4 +6,8 @@
<label name="packages_weight"/>
<field name="packages_weight"/>
</xpath>
+ <xpath expr="//field[@name='volume']" position="after">
+ <label name="packages_volume"/>
+ <field name="packages_volume"/>
+ </xpath>
</data>
diff -r 54ce1bd8b873 -r 78a98bdfedee view/shipment_list_package.xml
--- a/view/shipment_list_package.xml Thu Feb 03 23:13:27 2022 +0100
+++ b/view/shipment_list_package.xml Mon Mar 07 00:30:47 2022 +0100
@@ -3,6 +3,7 @@
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='weight']" position="after">
- <field name="packages_weight"/>
+ <field name="packages_weight" optional="1"/>
+ <field name="packages_volume" optional="1"/>
</xpath>
</data>