From 0956fc3c838eaaf8e60a1935f91890936e2e3a93 Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Fri, 9 Feb 2024 08:40:50 +0100 Subject: [PATCH] shopfloor: add option to exclude package types in product info --- shopfloor/__manifest__.py | 1 + shopfloor/actions/data.py | 12 ++++++-- shopfloor/models/__init__.py | 2 ++ shopfloor/models/res_company.py | 17 ++++++++++ shopfloor/models/res_config_settings.py | 13 ++++++++ shopfloor/views/res_config_settings.xml | 41 +++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 shopfloor/models/res_company.py create mode 100644 shopfloor/models/res_config_settings.py create mode 100644 shopfloor/views/res_config_settings.xml diff --git a/shopfloor/__manifest__.py b/shopfloor/__manifest__.py index 24f053bf1bc..105b10e1cc2 100644 --- a/shopfloor/__manifest__.py +++ b/shopfloor/__manifest__.py @@ -49,6 +49,7 @@ "data": [ "data/shopfloor_scenario_data.xml", "security/groups.xml", + "views/res_config_settings.xml", "views/shopfloor_menu.xml", "views/stock_picking_type.xml", "views/stock_location.xml", diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py index aaefbc06dc2..2858ed2a831 100644 --- a/shopfloor/actions/data.py +++ b/shopfloor/actions/data.py @@ -309,9 +309,17 @@ def _product_parser(self): ("seller_ids:supplier_code", self._product_supplier_code), ] - def _product_packaging(self, rec, field): + def _product_packaging(self, rec, field, apply_excluded=True): + packagings = rec.packaging_ids.filtered(lambda x: x.qty) + if apply_excluded: + excluded_packaging_types = ( + self.env.user.company_id.shopfloor_excluded_product_packaging_ids + ) + packagings = packagings.filtered( + lambda x: x.packaging_type_id not in excluded_packaging_types + ) return self._jsonify( - rec.packaging_ids.filtered(lambda x: x.qty), + packagings, self._packaging_parser, multi=True, ) diff --git a/shopfloor/models/__init__.py b/shopfloor/models/__init__.py index 7147bddd21a..e053ca6af8f 100644 --- a/shopfloor/models/__init__.py +++ b/shopfloor/models/__init__.py @@ -1,4 +1,6 @@ from . import priority_postpone_mixin +from . import res_company +from . import res_config_settings from . import shopfloor_menu from . import shopfloor_app from . import stock_picking_type diff --git a/shopfloor/models/res_company.py b/shopfloor/models/res_company.py new file mode 100644 index 00000000000..bba50a69662 --- /dev/null +++ b/shopfloor/models/res_company.py @@ -0,0 +1,17 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + shopfloor_excluded_product_packaging_ids = fields.Many2many( + comodel_name="product.packaging.type", + string="Packagings Excluded from Product Information", + help=( + "Used to prevent certain package types from being returned " + "to the shopfloor app when querying for product information." + ), + ) diff --git a/shopfloor/models/res_config_settings.py b/shopfloor/models/res_config_settings.py new file mode 100644 index 00000000000..670b01078c1 --- /dev/null +++ b/shopfloor/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2020 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + shopfloor_excluded_product_packaging_ids = fields.Many2many( + related="company_id.shopfloor_excluded_product_packaging_ids", + readonly=False, + ) diff --git a/shopfloor/views/res_config_settings.xml b/shopfloor/views/res_config_settings.xml new file mode 100644 index 00000000000..163898a196a --- /dev/null +++ b/shopfloor/views/res_config_settings.xml @@ -0,0 +1,41 @@ + + + + + + res.config.settings.view.form.inherit.shopfloor + res.config.settings + + + +

Shopfloor

+
+
+
+
+
+
+
+
+
+ +