Skip to content

Commit

Permalink
Merge commit 'refs/pull/829/head' of github.com:OCA/wms into merge-br…
Browse files Browse the repository at this point in the history
…anch-2477-BSCOS-4214-26a8f722
  • Loading branch information
JuMiSanAr committed Mar 15, 2024
2 parents 3781abe + a2d4c9e commit d57fee6
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 45 deletions.
82 changes: 56 additions & 26 deletions shopfloor_delivery_shipment/services/delivery_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,6 @@ def _data_for_content_to_load_from_pickings(self, shipment_advice):
It returns a dict where keys are source locations and values are
dictionaries listing package_levels and move_lines that remain to load
from transfers partially loaded in a shipment.
E.g:
{
"SRC_LOCATION1": {
"package_levels": [{PKG_LEVEL_DATA}, ...],
"move_lines": [{MOVE_LINE_DATA}, ...],
},
"SRC_LOCATION2": {
...
},
}
"""
domain = self._find_move_lines_domain(shipment_advice)
# Restrict to lines not loaded
Expand All @@ -593,46 +582,87 @@ def _data_for_content_to_load_from_pickings(self, shipment_advice):
pickings_partially_loaded = loaded_lines.picking_id
domain += [("picking_id", "in", pickings_partially_loaded.ids)]
move_lines = self.env["stock.move.line"].search(domain)
return self._prepare_data_for_content(move_lines)
return self._prepare_data_for_content(move_lines, group_by_sale=False)

def _data_for_content_to_load_from_picking(
self, shipment_advice, picking=None, location=None
):
"""Return a dictionary where keys are source locations
and values are dictionaries listing package_levels and move_lines
loaded or to load.
"""
# Grab move lines to sort, restricted to the current delivery
if picking:
move_lines = self._find_move_lines_to_process_from_picking(
shipment_advice, picking
)
elif location:
move_lines = self._find_move_lines_from_location(shipment_advice, location)
group_by_sale = bool(location)
return self._prepare_data_for_content(move_lines, group_by_sale=group_by_sale)

def _prepare_data_for_content(self, move_lines, group_by_sale=False):
"""Returns data for package levels and/or move lines.
The data is grouped by source location with a key for package levels and
a key for move lines.
The package levels can be grouped by related sales order and if they are not
they will be all stored into a key whose name is only spaces.
The move lines are not grouped by sales.
E.g:
{
"SRC_LOCATION1": {
"package_levels": [{PKG_LEVEL_DATA}, ...],
"package_levels": {
"sale 01": [{PKG_LEVEL_DATA}, ...],
"sale 02": [{PKG_LEVEL_DATA}, ...],
" ": [{PKG_LEVEL_DATA}, ...],
}
"move_lines": [{MOVE_LINE_DATA}, ...],
},
"SRC_LOCATION2": {
...
},
}
"""
# Grab move lines to sort, restricted to the current delivery
if picking:
move_lines = self._find_move_lines_to_process_from_picking(
shipment_advice, picking
)
elif location:
move_lines = self._find_move_lines_from_location(shipment_advice, location)
return self._prepare_data_for_content(move_lines)

def _prepare_data_for_content(self, move_lines):
empty_group_name = "null"
data = collections.OrderedDict()
package_level_ids = []

# Sort and group move lines by source location and prepare the data
for move_line in move_lines.sorted(lambda ml: ml.location_id.name):
sales_started = []
if group_by_sale:
sales_started = move_lines.shipment_advice_id.loaded_picking_ids.sale_id
# Grouping by sales (the packages) sort starting from last position
# 2 the lines NOT in a sales order whose loading has started.
# 1 the lines in a sales being loaded and the line is done.
# 0 the lines in a sales being loaded and not yet done
move_lines = move_lines.sorted(
lambda ml: 2
if ml.move_id.sale_line_id.order_id not in sales_started
else (1 if ml.package_level_id.is_done else 0)
)
else:
move_lines = move_lines.sorted(lambda ml: ml.location_id.name)

for move_line in move_lines:
location_data = data.setdefault(move_line.location_id.name, {})
if move_line.package_level_id:
pl_data = location_data.setdefault("package_levels", [])
pl_data = location_data.setdefault(
"package_levels", collections.OrderedDict()
)
if move_line.package_level_id.id in package_level_ids:
continue
pl_data.append(self.data.package_level(move_line.package_level_id))
if group_by_sale:
group_name = (
move_line.move_id.sale_line_id.order_id.name or empty_group_name
)
else:
group_name = empty_group_name
pl_group_data = pl_data.setdefault(group_name, [])
pl_group_data.append(
self.data.package_level(move_line.package_level_id)
)
package_level_ids.append(move_line.package_level_id.id)
else:
location_data.setdefault("move_lines", []).append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def assert_response_scan_document(
shipment_advice, picking
)
if lines_to_load:
data["content"] = self.service._prepare_data_for_content(lines_to_load)
group_by_sale = bool(location)
data["content"] = self.service._prepare_data_for_content(
lines_to_load, group_by_sale=group_by_sale
)
self.assert_response(
response,
next_state="scan_document",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_scan_document_shipment_not_planned_lot_not_planned(self):
)
# 'package_levels' key contains the package available from the same delivery
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down Expand Up @@ -187,7 +187,7 @@ def test_scan_document_lot_already_loaded(self):
)
# 'package_levels' key contains the package available from the same delivery
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def test_scan_document_shipment_not_planned_package_not_planned(self):
self.service.data.move_lines(self.picking1.move_line_ids_without_package),
)
# 'package_levels' key contains the package which has been loaded
# grouped in a dict
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(package_level),
)

Expand Down Expand Up @@ -141,8 +142,9 @@ def test_scan_document_package_already_loaded(self):
self.service.data.move_lines(self.picking1.move_line_ids_without_package),
)
# 'package_levels' key contains the package which has been loaded
# grouped in a dic
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(package_level),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_scan_document_shipment_planned_picking_planned(self):
)
# 'package_levels' key contains the packages
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down Expand Up @@ -199,7 +199,7 @@ def test_scan_document_shipment_not_planned_picking_partially_planned(self):
self.assertNotIn("move_lines", content[location_src])
# 'package_levels' key contains the not planned packages
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down Expand Up @@ -261,6 +261,6 @@ def test_scan_document_shipment_not_planned_picking_partially_loaded(self):
self.assertNotIn("move_lines", content[location_src])
# 'package_levels' key contains the already loaded package levels
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ def test_scan_document_shipment_not_planned_product_not_planned(self):
),
)
# 'package_levels' key contains the package available from the same delivery
# grouped in a dict
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down Expand Up @@ -184,7 +185,7 @@ def test_scan_document_product_already_loaded(self):
)
# 'package_levels' key contains the package available from the same delivery
self.assertEqual(
content[location_src]["package_levels"],
content[location_src]["package_levels"]["null"],
self.service.data.package_levels(self.picking1.package_level_ids),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ const DeliveryShipment = {
<v-card-title>{{ name }}</v-card-title>
<v-card-subtitle> {{ package_level_process(value.package_levels) }}</v-card-subtitle>
</v-card>
<item-detail-card
v-for="packlevel in value.package_levels"
:key="make_state_component_key(['shipment-pack', packlevel.id])"
:record="packlevel.package_src"
:options="pack_options(packlevel)"
:card_color="pack_color(packlevel)"
/>
<div v-for="(value, name, index) in value.package_levels">
<v-card v-if="name!=='null'" color="grey lighten-1" class="detail v-card mt-5 main mb-2">
<v-card-title>{{ name }}</v-card-title>
</v-card>
<item-detail-card
v-for="packlevel in value"
:key="make_state_component_key(['shipment-pack', packlevel.id])"
:record="packlevel.package_src"
:options="pack_options(packlevel)"
:card_color="pack_color(packlevel)"
/>
</div>
<item-detail-card
v-for="line in value.move_lines"
:key="make_state_component_key(['shipment-product', line.product.id])"
Expand Down Expand Up @@ -248,8 +255,10 @@ const DeliveryShipment = {
return this.utils.colors.color_for(color);
},
package_level_process(package_levels) {
const package_level_count = package_levels.length;
const done_package_level_count = package_levels.reduce((acc, next) => {
// Package data can be grouped by sales order, put them all in one array
const all_package_levels = Object.values(package_levels).flat();
const package_level_count = all_package_levels.length;
const done_package_level_count = all_package_levels.reduce((acc, next) => {
return next.is_done ? acc + 1 : acc;
}, 0);
return `Progress: ${done_package_level_count} / ${package_level_count}`;
Expand Down

0 comments on commit d57fee6

Please sign in to comment.