-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72adc1b
commit dd78212
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
from . import models | ||
from . import wizards | ||
from .hooks import post_load_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,5 @@ | |
], | ||
"installable": True, | ||
"application": True, | ||
"post_load": "post_load_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2024 ForgeFlow, S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo.addons.stock.models.stock_picking import Picking | ||
|
||
|
||
# flake8: noqa: C901 | ||
def post_load_hook(): | ||
def _check_entire_pack(self): | ||
"""This function check if entire packs are moved in the picking""" | ||
for picking in self: | ||
origin_packages = picking.move_line_ids.mapped("package_id") | ||
for pack in origin_packages: | ||
if picking._check_move_lines_map_quant_package(pack): | ||
package_level_ids = picking.package_level_ids.filtered( | ||
lambda pl: pl.package_id == pack | ||
) | ||
move_lines_to_pack = picking.move_line_ids.filtered( | ||
lambda ml: ml.package_id == pack | ||
and not ml.result_package_id | ||
and ml.state not in ("done", "cancel") | ||
) | ||
if not package_level_ids: | ||
package_location = ( | ||
self._get_entire_pack_location_dest(move_lines_to_pack) | ||
or picking.location_dest_id.id | ||
) | ||
self.env["stock.package_level"].with_context( | ||
bypass_reservation_update=package_location | ||
).create( | ||
{ | ||
"picking_id": picking.id, | ||
"package_id": pack.id, | ||
"location_id": pack.location_id.id, | ||
"location_dest_id": package_location, | ||
"move_line_ids": [(6, 0, move_lines_to_pack.ids)], | ||
"company_id": picking.company_id.id, | ||
} | ||
) | ||
# Propagate the result package in the next move for disposable packages only. | ||
# Start Hook | ||
if ( | ||
pack.package_use == "disposable" | ||
and pack.location_id.usage != "customer" | ||
): | ||
# End Hook | ||
move_lines_to_pack.with_context( | ||
bypass_reservation_update=package_location | ||
).write({"result_package_id": pack.id}) | ||
|
||
else: | ||
move_lines_in_package_level = move_lines_to_pack.filtered( | ||
lambda ml: ml.move_id.package_level_id | ||
) | ||
move_lines_without_package_level = ( | ||
move_lines_to_pack - move_lines_in_package_level | ||
) | ||
|
||
if pack.package_use == "disposable": | ||
( | ||
move_lines_in_package_level | ||
| move_lines_without_package_level | ||
).result_package_id = pack | ||
move_lines_in_package_level.result_package_id = pack | ||
for ml in move_lines_in_package_level: | ||
ml.package_level_id = ml.move_id.package_level_id.id | ||
|
||
move_lines_without_package_level.package_level_id = ( | ||
package_level_ids[0] | ||
) | ||
for pl in package_level_ids: | ||
pl.location_dest_id = ( | ||
self._get_entire_pack_location_dest(pl.move_line_ids) | ||
or picking.location_dest_id.id | ||
) | ||
|
||
if not hasattr(Picking, "_check_entire_pack_original"): | ||
Picking._check_entire_pack_original = Picking._check_entire_pack | ||
Picking._check_entire_pack = _check_entire_pack |