-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_storage_type: condition context
Give in evaluation context what is being moved
- Loading branch information
Showing
3 changed files
with
56 additions
and
10 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Copyright 2019-2021 Camptocamp SA | ||
# Copyright 2019-2021 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# Copyright 2019 Camptocamp SA | ||
# Copyright 2019 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
import logging | ||
|
||
|
@@ -425,7 +425,9 @@ def _get_package_type_putaway_strategy( | |
return dest_location | ||
|
||
for package_sequence in package_locations: | ||
if not package_sequence.can_be_applied(putaway_location, quants, product): | ||
if not package_sequence.can_be_applied( | ||
putaway_location, quants, package, product, quantity | ||
): | ||
continue | ||
pref_loc = package_sequence.location_id | ||
storage_locations = pref_loc.get_storage_locations(products=product) | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2019 Camptocamp SA | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import _, fields, models | ||
|
||
|
@@ -82,10 +83,12 @@ def button_show_locations(self): | |
] | ||
return action | ||
|
||
def can_be_applied(self, putaway_location, quant, product): | ||
def can_be_applied(self, putaway_location, quant, package, product, quantity): | ||
"""Check if conditions are met.""" | ||
self.ensure_one() | ||
for cond in self.location_sequence_cond_ids: | ||
if not cond.evaluate(self, putaway_location, quant, product): | ||
if not cond.evaluate( | ||
self, putaway_location, quant, package, product, quantity | ||
): | ||
return False | ||
return True |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2022 ACSONE SA/NV | ||
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
import logging | ||
import textwrap | ||
|
@@ -58,7 +59,9 @@ def _default_code_snippet_docs(self): | |
* condition | ||
* putaway_location | ||
* quant (recordset) | ||
* package | ||
* product | ||
* quantity | ||
* env | ||
* datetime | ||
* dateutil | ||
|
@@ -71,7 +74,13 @@ def _default_code_snippet_docs(self): | |
""" | ||
|
||
def _get_code_snippet_eval_context( | ||
self, storage_location_sequence, putaway_location, quant, product | ||
self, | ||
storage_location_sequence, | ||
putaway_location, | ||
quant, | ||
package, | ||
product, | ||
quantity, | ||
): | ||
"""Prepare the context used when evaluating python code | ||
:returns: dict -- evaluation context given to safe_eval | ||
|
@@ -83,7 +92,9 @@ def _get_code_snippet_eval_context( | |
"condition": self, | ||
"putaway_location": putaway_location, | ||
"quant": quant, | ||
"package": package, | ||
"product": product, | ||
"quantity": quantity, | ||
"datetime": safe_eval.datetime, | ||
"dateutil": safe_eval.dateutil, | ||
"time": safe_eval.time, | ||
|
@@ -93,12 +104,25 @@ def _get_code_snippet_eval_context( | |
), | ||
} | ||
|
||
def _exec_code(self, storage_location_sequence, putaway_location, quant, product): | ||
def _exec_code( | ||
self, | ||
storage_location_sequence, | ||
putaway_location, | ||
quant, | ||
package, | ||
product, | ||
quantity, | ||
): | ||
self.ensure_one() | ||
if not self._code_snippet_valued(): | ||
return False | ||
eval_ctx = self._get_code_snippet_eval_context( | ||
storage_location_sequence, putaway_location, quant, product | ||
storage_location_sequence, | ||
putaway_location, | ||
quant, | ||
package, | ||
product, | ||
quantity, | ||
) | ||
snippet = self.code_snippet | ||
safe_eval.safe_eval(snippet, eval_ctx, mode="exec", nocopy=True) | ||
|
@@ -113,13 +137,17 @@ def _exec_code(self, storage_location_sequence, putaway_location, quant, product | |
"* putaway sequence: %s\n" | ||
"* putaway location: %s\n" | ||
"* quants: %s\n" | ||
"* package: %s\n" | ||
"* product: %s\n" | ||
"* quantity: %s\n" | ||
% ( | ||
self.name, | ||
storage_location_sequence.id, | ||
putaway_location.name, | ||
quant.ids, | ||
package.display_name, | ||
product.display_name, | ||
quantity, | ||
) | ||
) | ||
return result | ||
|
@@ -135,11 +163,24 @@ def _code_snippet_valued(self): | |
] | ||
) | ||
|
||
def evaluate(self, storage_location_sequence, putaway_location, quant, product): | ||
def evaluate( | ||
self, | ||
storage_location_sequence, | ||
putaway_location, | ||
quant, | ||
package, | ||
product, | ||
quantity, | ||
): | ||
self.ensure_one() | ||
if self.condition_type == "code": | ||
return self._exec_code( | ||
storage_location_sequence, putaway_location, quant, product | ||
storage_location_sequence, | ||
putaway_location, | ||
quant, | ||
package, | ||
product, | ||
quantity, | ||
) | ||
condition_type = self.condition_type | ||
raise exceptions.UserError( | ||
|