Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] shipment_advice: Add bulk loaded total volume and bulk weight #155

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions shipment_advice/models/shipment_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
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",
Expand Down Expand Up @@ -202,11 +207,23 @@
"""
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"))

Check warning on line 226 in shipment_advice/models/shipment_advice.py

View check run for this annotation

Codecov / codecov/patch

shipment_advice/models/shipment_advice.py#L225-L226

Added lines #L225 - L226 were not covered by tests

@api.depends("planned_move_ids", "loaded_move_line_ids")
def _compute_picking_ids(self):
Expand Down
3 changes: 2 additions & 1 deletion shipment_advice/tests/test_shipment_advice_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions shipment_advice/views/shipment_advice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@
<field name="picking_id" />
<field name="product_id" />
<field name="lot_id" />
<field name="reserved_uom_qty" />
<field name="qty_done" />
<field
name="reserved_uom_qty"
sum="Total reserved"
/>
<field name="qty_done" sum="Total done" />
<field name="product_uom_id" />
<field name="state" />
</tree>
Expand All @@ -250,7 +253,20 @@
class="oe_subtotal_footer_separator"
/>
</strong>
<div
class="oe_subtotal_footer_separator oe_inline o_td_label"
>
<label for="total_volume" />
</div>
<strong>
<field
name="total_volume"
nolabel="1"
class="oe_subtotal_footer_separator"
/>
</strong>
</group>

</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
Expand All @@ -276,6 +292,7 @@
<field name="departure_date" />
<field name="ref" />
<field name="total_load" />
<field name="total_volume" />
<field
name="warehouse_id"
groups="stock.group_stock_multi_warehouses"
Expand Down
Loading