Skip to content

Commit

Permalink
sh_reception_packaging_dimension: refactor to allow module to extend
Browse files Browse the repository at this point in the history
  • Loading branch information
TDu committed Oct 31, 2023
1 parent 273c525 commit 0271954
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
44 changes: 22 additions & 22 deletions shopfloor_reception_packaging_dimension/services/reception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.osv import expression

from odoo.addons.base_rest.components.service import to_int
from odoo.addons.component.core import Component
from odoo.addons.shopfloor.utils import to_float
Expand All @@ -21,34 +23,32 @@ def _before_state__set_quantity(self, picking, line, message=None):
)
return super()._before_state__set_quantity(picking, line, message=message)

def _get_domain_packaging_needs_dimension(self):
return expression.OR(
[
[("packaging_length", "=", 0)],
[("packaging_length", "=", False)],
[("width", "=", 0)],
[("width", "=", False)],
[("height", "=", 0)],
[("height", "=", False)],
[("max_weight", "=", 0)],
[("max_weight", "=", False)],
[("qty", "=", 0)],
[("qty", "=", False)],
[("barcode", "=", False)],
]
)

def _get_next_packaging_to_set_dimension(self, product, previous_packaging=None):
"""Return for a product the next packaging needing dimension to be set."""
next_packaging_id = previous_packaging.id + 1 if previous_packaging else 0
domain = [
domain_dimension = self._get_domain_packaging_needs_dimension()
domain_packaging_id = [
("product_id", "=", product.id),
("id", ">=", next_packaging_id),
"|",
"|",
"|",
"|",
"|",
"|",
"|",
"|",
"|",
"|",
("packaging_length", "=", 0),
("packaging_length", "=", False),
("width", "=", 0),
("width", "=", False),
("height", "=", 0),
("height", "=", False),
("max_weight", "=", 0),
("max_weight", "=", False),
("qty", "=", 0),
("qty", "=", False),
("barcode", "=", False),
]
domain = expression.AND([domain_packaging_id, domain_dimension])
return self.env["product.packaging"].search(domain, order="id", limit=1)

def _response_for_set_packaging_dimension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,26 @@ def test_scan_product_ask_for_dimension(self):
response, self.picking, selected_move_line, self.product_a_packaging
)

# TODO : Have questions on how the lot information is commited by the frontend
#
# def test_scan_lot_ask_for_dimension(self):
# self.product_a.tracking = "none"
# self.assertTrue(self.product_a.packaging_ids)
# response = self.service.dispatch(
# "set_lot_confirmation_action",
# params={
# "picking_id": self.picking.id,
# "barcode": self.product_a.barcode,
# },
# )
# self.data.picking(self.picking)
# selected_move_line = self.picking.move_line_ids.filtered(
# lambda l: l.product_id == self.product_a
# )
# self._assert_response_set_dimension(
# response, self.picking, selected_move_line, self.product_a_packaging
# )
def test_scan_lot_ask_for_dimension(self):
self.product_a.tracking = "none"
selected_move_line = self.picking.move_line_ids.filtered(
lambda l: l.product_id == self.product_a
)
self.assertTrue(self.product_a.packaging_ids)
response = self.service.dispatch(
"set_lot_confirm_action",
params={
"picking_id": self.picking.id,
"selected_line_id": selected_move_line.id,
},
)
self.data.picking(self.picking)
selected_move_line = self.picking.move_line_ids.filtered(
lambda l: l.product_id == self.product_a
)
self._assert_response_set_dimension(
response, self.picking, selected_move_line, self.product_a_packaging
)

def test_set_packaging_dimension(self):
selected_move_line = self.picking.move_line_ids.filtered(
Expand Down

0 comments on commit 0271954

Please sign in to comment.