From 7d0d44b9d31faf3251b91df97a0e04c3b4608c33 Mon Sep 17 00:00:00 2001 From: JuMiSanAr Date: Wed, 21 Feb 2024 08:59:53 +0100 Subject: [PATCH] Add shopfloor_vendor_packaging --- .../odoo/addons/shopfloor_vendor_packaging | 1 + setup/shopfloor_vendor_packaging/setup.py | 6 ++ shopfloor/actions/data.py | 30 +--------- shopfloor/models/shopfloor_menu.py | 20 ------- shopfloor/views/shopfloor_menu.xml | 7 --- shopfloor_reception/__manifest__.py | 4 +- shopfloor_vendor_packaging/__init__.py | 2 + shopfloor_vendor_packaging/__manifest__.py | 19 +++++++ shopfloor_vendor_packaging/actions/data.py | 56 +++++++++++++++++++ .../models/shopfloor_menu.py | 29 ++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../views/shopfloor_menu.xml | 18 ++++++ 13 files changed, 139 insertions(+), 56 deletions(-) create mode 120000 setup/shopfloor_vendor_packaging/odoo/addons/shopfloor_vendor_packaging create mode 100644 setup/shopfloor_vendor_packaging/setup.py create mode 100644 shopfloor_vendor_packaging/__init__.py create mode 100644 shopfloor_vendor_packaging/__manifest__.py create mode 100644 shopfloor_vendor_packaging/actions/data.py create mode 100644 shopfloor_vendor_packaging/models/shopfloor_menu.py create mode 100644 shopfloor_vendor_packaging/readme/CONTRIBUTORS.rst create mode 100644 shopfloor_vendor_packaging/readme/DESCRIPTION.rst create mode 100644 shopfloor_vendor_packaging/views/shopfloor_menu.xml diff --git a/setup/shopfloor_vendor_packaging/odoo/addons/shopfloor_vendor_packaging b/setup/shopfloor_vendor_packaging/odoo/addons/shopfloor_vendor_packaging new file mode 120000 index 0000000000..3ec99323e1 --- /dev/null +++ b/setup/shopfloor_vendor_packaging/odoo/addons/shopfloor_vendor_packaging @@ -0,0 +1 @@ +../../../../shopfloor_vendor_packaging \ No newline at end of file diff --git a/setup/shopfloor_vendor_packaging/setup.py b/setup/shopfloor_vendor_packaging/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopfloor_vendor_packaging/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopfloor/actions/data.py b/shopfloor/actions/data.py index 98dd502475..aaefbc06dc 100644 --- a/shopfloor/actions/data.py +++ b/shopfloor/actions/data.py @@ -188,11 +188,7 @@ def _lot_parser(self): @ensure_model("stock.move.line") def move_line(self, record, with_picking=False, **kw): - display_vendor_packagings = kw.get("display_vendor_packagings") - record = record.with_context( - location=record.location_id.id, - display_vendor_packagings=display_vendor_packagings, - ) + record = record.with_context(location=record.location_id.id) parser = self._move_line_parser if with_picking: parser += [("picking_id:picking", self._picking_parser)] @@ -238,11 +234,7 @@ def _move_line_parser(self): @ensure_model("stock.move") def move(self, record, **kw): - display_vendor_packagings = kw.get("display_vendor_packagings") - record = record.with_context( - location=record.location_id.id, - display_vendor_packagings=display_vendor_packagings, - ) + record = record.with_context(location=record.location_id.id) parser = self._move_parser return self._jsonify(record, parser) @@ -264,10 +256,6 @@ 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): @@ -303,10 +291,6 @@ 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): @@ -326,16 +310,8 @@ 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( - packagings, + rec.packaging_ids.filtered(lambda x: x.qty), self._packaging_parser, multi=True, ) diff --git a/shopfloor/models/shopfloor_menu.py b/shopfloor/models/shopfloor_menu.py index 9fcd5497e7..7521a67db4 100644 --- a/shopfloor/models/shopfloor_menu.py +++ b/shopfloor/models/shopfloor_menu.py @@ -53,11 +53,6 @@ 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" @@ -231,14 +226,6 @@ 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): @@ -468,10 +455,3 @@ 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 ec5391f74a..868dc85c6c 100644 --- a/shopfloor/views/shopfloor_menu.xml +++ b/shopfloor/views/shopfloor_menu.xml @@ -168,13 +168,6 @@ /> - - - - diff --git a/shopfloor_reception/__manifest__.py b/shopfloor_reception/__manifest__.py index 0b50847024..dfb4c94691 100644 --- a/shopfloor_reception/__manifest__.py +++ b/shopfloor_reception/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Shopfloor Reception", "summary": "Reception scenario for shopfloor", - "version": "14.0.2.6.1", + "version": "14.0.2.7.0", "development_status": "Beta", "category": "Inventory", "website": "https://github.com/OCA/wms", @@ -9,7 +9,7 @@ "maintainers": ["mmequignon", "JuMiSanAr"], "license": "AGPL-3", "installable": True, - "depends": ["shopfloor"], + "depends": ["shopfloor", "shopfloor_vendor_packaging"], "data": [ "data/shopfloor_scenario_data.xml", ], diff --git a/shopfloor_vendor_packaging/__init__.py b/shopfloor_vendor_packaging/__init__.py new file mode 100644 index 0000000000..d826cddf76 --- /dev/null +++ b/shopfloor_vendor_packaging/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import actions diff --git a/shopfloor_vendor_packaging/__manifest__.py b/shopfloor_vendor_packaging/__manifest__.py new file mode 100644 index 0000000000..62a0d922ae --- /dev/null +++ b/shopfloor_vendor_packaging/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp SA (http://www.camptocamp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Shopfloor Vendor Packaging", + "summary": "Manage shopfloor behavior for vendor packaging", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Inventory", + "website": "https://github.com/OCA/wms", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "data": [ + "views/shopfloor_menu.xml", + ], + "depends": ["shopfloor", "product_packaging_type_vendor"], + "auto-install": True, +} diff --git a/shopfloor_vendor_packaging/actions/data.py b/shopfloor_vendor_packaging/actions/data.py new file mode 100644 index 0000000000..cd41e97bd1 --- /dev/null +++ b/shopfloor_vendor_packaging/actions/data.py @@ -0,0 +1,56 @@ +# Copyright 2024 Camptocamp SA (http://www.camptocamp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.addons.component.core import Component +from odoo.addons.shopfloor_base.utils import ensure_model + + +class DataAction(Component): + _inherit = "shopfloor.data.action" + + @ensure_model("stock.move.line") + def move_line(self, record, with_picking=False, **kw): + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + display_vendor_packagings=display_vendor_packagings, + ) + return super().move_line(record, with_picking, **kw) + + @ensure_model("stock.move") + def move(self, record, **kw): + display_vendor_packagings = kw.get("display_vendor_packagings") + record = record.with_context( + display_vendor_packagings=display_vendor_packagings, + ) + return super().move(record, **kw) + + @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 super().package_level(record, **kw) + + @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 super().product(record, **kw) + + def _product_packaging(self, rec, field): + display_vendor_packagings = rec.env.context.get("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( + packagings, + self._packaging_parser, + multi=True, + ) diff --git a/shopfloor_vendor_packaging/models/shopfloor_menu.py b/shopfloor_vendor_packaging/models/shopfloor_menu.py new file mode 100644 index 0000000000..2a2391aa55 --- /dev/null +++ b/shopfloor_vendor_packaging/models/shopfloor_menu.py @@ -0,0 +1,29 @@ +# Copyright 2024 Camptocamp SA (http://www.camptocamp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + +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" + + 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.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_vendor_packaging/readme/CONTRIBUTORS.rst b/shopfloor_vendor_packaging/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..2ee6b053bc --- /dev/null +++ b/shopfloor_vendor_packaging/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Juan Miguel Sánchez Arce \ No newline at end of file diff --git a/shopfloor_vendor_packaging/readme/DESCRIPTION.rst b/shopfloor_vendor_packaging/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..4105e17646 --- /dev/null +++ b/shopfloor_vendor_packaging/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +When installed, this module adds a new option in shopfloor +to prevent vendor packagings from being displayed in the frontend. \ No newline at end of file diff --git a/shopfloor_vendor_packaging/views/shopfloor_menu.xml b/shopfloor_vendor_packaging/views/shopfloor_menu.xml new file mode 100644 index 0000000000..b90fbdfd0a --- /dev/null +++ b/shopfloor_vendor_packaging/views/shopfloor_menu.xml @@ -0,0 +1,18 @@ + + + + shopfloor.menu + + + + + + + + + + +