From 889aa7849743c871954cd6d677136a59a3fefd9d Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Tue, 20 Feb 2024 09:05:50 +0100 Subject: [PATCH] shopfloor: allow option to not display vendor packagings --- shopfloor/actions/data.py | 30 +++++++++++++++++++++++++++--- shopfloor/models/shopfloor_menu.py | 20 ++++++++++++++++++++ shopfloor/views/shopfloor_menu.xml | 7 +++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py index aaefbc06dc..98dd502475 100644 --- a/shopfloor/actions/data.py +++ b/shopfloor/actions/data.py @@ -188,7 +188,11 @@ def _lot_parser(self): @ensure_model("stock.move.line") def move_line(self, record, with_picking=False, **kw): - record = record.with_context(location=record.location_id.id) + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + location=record.location_id.id, + display_vendor_packagings=display_vendor_packagings, + ) parser = self._move_line_parser if with_picking: parser += [("picking_id:picking", self._picking_parser)] @@ -234,7 +238,11 @@ def _move_line_parser(self): @ensure_model("stock.move") def move(self, record, **kw): - record = record.with_context(location=record.location_id.id) + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + location=record.location_id.id, + display_vendor_packagings=display_vendor_packagings, + ) parser = self._move_parser return self._jsonify(record, parser) @@ -256,6 +264,10 @@ def _move_parser(self): @ensure_model("stock.package_level") def package_level(self, record, **kw): + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + display_vendor_packagings=display_vendor_packagings + ) return self._jsonify(record, self._package_level_parser) def package_levels(self, records, **kw): @@ -291,6 +303,10 @@ def _package_level_parser(self): @ensure_model("product.product") def product(self, record, **kw): + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + display_vendor_packagings=display_vendor_packagings + ) return self._jsonify(record, self._product_parser, **kw) def products(self, record, **kw): @@ -310,8 +326,16 @@ def _product_parser(self): ] def _product_packaging(self, rec, field): + display_vendor_packagings = rec.env.context["display_vendor_packagings"] + packagings = rec.packaging_ids + if display_vendor_packagings: + packagings = packagings.filtered(lambda x: x.qty) + else: + packagings = packagings.filtered( + lambda x: x.qty and not x.packaging_type_id.is_vendor_packaging + ) return self._jsonify( - rec.packaging_ids.filtered(lambda x: x.qty), + packagings, self._packaging_parser, multi=True, ) diff --git a/shopfloor/models/shopfloor_menu.py b/shopfloor/models/shopfloor_menu.py index 7521a67db4..9fcd5497e7 100644 --- a/shopfloor/models/shopfloor_menu.py +++ b/shopfloor/models/shopfloor_menu.py @@ -53,6 +53,11 @@ to scan a destination package. """ +DISPLAY_VENDOR_PACKAGINGS_HELP = """ +When enabled, the user will be able to see the vendor packagings +in the frontend, e.g. in the qty picker. +""" + class ShopfloorMenu(models.Model): _inherit = "shopfloor.menu" @@ -226,6 +231,14 @@ class ShopfloorMenu(models.Model): allow_alternative_destination_package_is_possible = fields.Boolean( compute="_compute_allow_alternative_destination_package_is_possible" ) + display_vendor_packagings = fields.Boolean( + string="Display vendor packagings", + default=False, + help=DISPLAY_VENDOR_PACKAGINGS_HELP, + ) + display_vendor_packagings_is_possible = fields.Boolean( + compute="_compute_display_vendor_packagings_is_possible", + ) @api.onchange("unload_package_at_destination") def _onchange_unload_package_at_destination(self): @@ -455,3 +468,10 @@ def _compute_allow_alternative_destination_package_is_possible(self): menu.allow_alternative_destination_package_is_possible = ( menu.scenario_id.has_option("allow_alternative_destination_package") ) + + @api.depends("scenario_id") + def _compute_display_vendor_packagings_is_possible(self): + for menu in self: + menu.display_vendor_packagings_is_possible = menu.scenario_id.has_option( + "display_vendor_packagings" + ) diff --git a/shopfloor/views/shopfloor_menu.xml b/shopfloor/views/shopfloor_menu.xml index 868dc85c6c..ec5391f74a 100644 --- a/shopfloor/views/shopfloor_menu.xml +++ b/shopfloor/views/shopfloor_menu.xml @@ -168,6 +168,13 @@ /> + + + +