From 834852b7384d27733da3c15ac099a8cbb2dcc835 Mon Sep 17 00:00:00 2001 From: Gil Arasa Verge Date: Sat, 16 Nov 2024 12:14:34 +0100 Subject: [PATCH] [IMP] shipment_advice: Add bulk loaded total volume and bulk weight --- shipment_advice/models/shipment_advice.py | 21 +++++++++++++++++-- .../tests/test_shipment_advice_load.py | 3 ++- shipment_advice/views/shipment_advice.xml | 21 +++++++++++++++++-- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/shipment_advice/models/shipment_advice.py b/shipment_advice/models/shipment_advice.py index e50e566f..58bd7b07 100644 --- a/shipment_advice/models/shipment_advice.py +++ b/shipment_advice/models/shipment_advice.py @@ -106,6 +106,11 @@ def _default_warehouse_id(self): digits=(16, 2), compute="_compute_total_load", ) + total_volume = fields.Float( + string="Total volume (m3)", + digits=(16, 2), + compute="_compute_total_volume", + ) planned_move_ids = fields.One2many( comodel_name="stock.move", inverse_name="shipment_advice_id", @@ -203,11 +208,23 @@ def _check_include_package_level(self, package_level): """ return True - @api.depends("loaded_move_line_ids.result_package_id.shipping_weight") + @api.depends( + "loaded_move_line_ids.result_package_id.shipping_weight", + "loaded_move_line_without_package_ids.product_id.weight", + ) def _compute_total_load(self): for shipment in self: packages = shipment.loaded_move_line_ids.result_package_id - shipment.total_load = sum(packages.mapped("shipping_weight")) + without_packages = shipment.loaded_move_line_without_package_ids + shipment.total_load = sum(packages.mapped("shipping_weight")) + sum( + without_packages.mapped("product_id.weight") + ) + + @api.depends("loaded_move_line_without_package_ids.product_id.volume") + def _compute_total_volume(self): + for shipment in self: + without_packages = shipment.loaded_move_line_without_package_ids + shipment.total_volume = sum(without_packages.mapped("product_id.volume")) @api.depends("planned_move_ids", "loaded_move_line_ids") def _compute_picking_ids(self): diff --git a/shipment_advice/tests/test_shipment_advice_load.py b/shipment_advice/tests/test_shipment_advice_load.py index 889419f9..8471f5d7 100644 --- a/shipment_advice/tests/test_shipment_advice_load.py +++ b/shipment_advice/tests/test_shipment_advice_load.py @@ -64,7 +64,8 @@ def test_shipment_advice_load_picking_already_planned(self): ) lines = wiz.shipment_advice_id.loaded_move_line_ids lines[1].result_package_id.shipping_weight = 10.0 - self.assertEqual(wiz.shipment_advice_id.total_load, 10.0) + # Consider package weight + bulk weight (0.01) + self.assertEqual(wiz.shipment_advice_id.total_load, 10.0 + 0.01) self.assertEqual(len(wiz.shipment_advice_id.loaded_move_line_ids), 3) self.assertEqual( wiz.shipment_advice_id.loaded_move_lines_without_package_count, 1 diff --git a/shipment_advice/views/shipment_advice.xml b/shipment_advice/views/shipment_advice.xml index fcb4718e..be5e31d7 100644 --- a/shipment_advice/views/shipment_advice.xml +++ b/shipment_advice/views/shipment_advice.xml @@ -222,8 +222,11 @@ - - + + @@ -250,7 +253,20 @@ class="oe_subtotal_footer_separator" /> + + + + +
@@ -276,6 +292,7 @@ +