Skip to content

Commit

Permalink
Add check options on stock_location_package_restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Aug 25, 2023
1 parent 455e377 commit 3047463
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions stock_location_package_restriction/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
class StockMove(models.Model):
_inherit = "stock.move"

def _check_location_package_restriction(self):
"""
Check if the current stock.move can be executed
regarding a potential package restriction
def _check_location_package_restriction(
self, new_location=None, only_qty_done=True
):
"""Check if the moves can be done regarding potential package restrictions
By default will only check move lines with a quantity done and their set
destination location.
If `new_location` is set it will be use as destination location.
If `only_qty_done` is False the check is executed on all
related move lines.
"""
Package = self.env["stock.quant.package"]
error_msgs = []
dest_location = new_location or self.move_line_ids.location_dest_id
quants_grouped = self.env["stock.quant"].read_group(
[
("location_id", "in", self.move_line_ids.location_dest_id.ids),
("location_id", "in", dest_location.ids),
("location_id.package_restriction", "!=", NORESTRICTION),
("quantity", ">", 0),
],
Expand All @@ -31,13 +40,20 @@ def _check_location_package_restriction(self):
location_packages = {
g["location_id"][0]: set(g["package_id"]) for g in quants_grouped
}
lines_being_processed = self.move_line_ids.filtered(lambda line: line.qty_done)
lines_being_processed = (
self.move_line_ids.filtered(lambda line: line.qty_done)
if only_qty_done
else self.move_line_ids
)
for location, move_lines in groupby(
lines_being_processed, lambda m: m.location_dest_id
):

if location.package_restriction == NORESTRICTION:
continue

if new_location:
location = new_location

Check warning on line 56 in stock_location_package_restriction/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_location_package_restriction/models/stock_move.py#L56

Added line #L56 was not covered by tests
existing_package_ids = location_packages.get(location.id, set())
existing_packages = Package.browse(existing_package_ids).exists()
new_packages = Package.browse()
Expand Down

0 comments on commit 3047463

Please sign in to comment.