diff --git a/setup/stock_picking_package_number_glue/odoo/addons/stock_picking_package_number_glue b/setup/stock_picking_package_number_glue/odoo/addons/stock_picking_package_number_glue new file mode 120000 index 0000000000..e602a3a6f1 --- /dev/null +++ b/setup/stock_picking_package_number_glue/odoo/addons/stock_picking_package_number_glue @@ -0,0 +1 @@ +../../../../stock_picking_package_number_glue \ No newline at end of file diff --git a/setup/stock_picking_package_number_glue/setup.py b/setup/stock_picking_package_number_glue/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/stock_picking_package_number_glue/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_package_number_glue/README.rst b/stock_picking_package_number_glue/README.rst new file mode 100644 index 0000000000..15eb65d686 --- /dev/null +++ b/stock_picking_package_number_glue/README.rst @@ -0,0 +1,76 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: https://opensource.org/licenses/LGPL-3.0 + :alt: License: LGPL-3 + +================================= +Stock Picking Package Number Glue +================================= + +Overview +======== + +The **Stock Picking Package Number Glue** module extends the **Stock Picking** functionality by automatically synchronizing the `number_of_packages` field with the `packages_qty` field. This ensures that the number of packages is correctly updated whenever the quantity of packages is modified. + +Features +======== + +- **Automatic Synchronization**: + + - Automatically updates the `number_of_packages` field based on the value of the `packages_qty` field in stock pickings. + +- **Onchange Trigger**: + + - Uses the `@api.onchange` decorator to track changes in the `packages_qty` field and update the `number_of_packages` field accordingly. + +Usage +===== + +1. **Install the Module**: + + - Install the **Stock Picking Package Number Glue** module from the Apps menu. + +2. **Modify Package Quantity**: + + - When editing a stock picking, update the `packages_qty` field. + +3. **Automatic Update**: + + - The `number_of_packages` field will be automatically updated to match the value of `packages_qty`. + +Configuration +============= + +No additional configuration is required for this module. It works automatically once installed. + +Testing +======= + +Perform the following tests to ensure the module is working correctly: + +- Create or edit a stock picking. + +- Change the value of the `packages_qty` field. + +- Verify that the `number_of_packages` field is automatically updated with the same value as `packages_qty`. + +Bug Tracker +=========== + +If you encounter any issues, please report them on the GitHub repository at `GitHub Issues `_. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi + +* Unai Beristain + +For specific questions or support, please contact the contributors. + +License +======= + +This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit . diff --git a/stock_picking_package_number_glue/__init__.py b/stock_picking_package_number_glue/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/stock_picking_package_number_glue/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_package_number_glue/__manifest__.py b/stock_picking_package_number_glue/__manifest__.py new file mode 100644 index 0000000000..80ddc6f8fa --- /dev/null +++ b/stock_picking_package_number_glue/__manifest__.py @@ -0,0 +1,16 @@ +{ + "name": "Stock Picking Package Number Glue", + "version": "16.0.1.0.0", + "category": "Stock", + "author": "Avanzosc", + "license": "LGPL-3", + "depends": [ + "stock", + "delivery_package_number", + "stock_picking_package_usability", + ], + "data": [], + "installable": True, + "application": False, + "website": "https://github.com/avanzosc/odoo-addons", +} diff --git a/stock_picking_package_number_glue/models/__init__.py b/stock_picking_package_number_glue/models/__init__.py new file mode 100644 index 0000000000..ae4c27227f --- /dev/null +++ b/stock_picking_package_number_glue/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/stock_picking_package_number_glue/models/stock_picking.py b/stock_picking_package_number_glue/models/stock_picking.py new file mode 100644 index 0000000000..fdcaab1960 --- /dev/null +++ b/stock_picking_package_number_glue/models/stock_picking.py @@ -0,0 +1,101 @@ +import logging + +from odoo import _, api, models + +# Configurar el logger +_logger = logging.getLogger(__name__) + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _update_number_of_packages(self): + """Actualizar el campo number_of_packages basado en packages_qty.""" + for picking in self: + previous_value = picking.number_of_packages + picking.number_of_packages = picking.packages_qty + _logger.info( + "[STOCK_PICKING_LOG] Updated number_of_packages for picking ID %s from %s to %s", + picking.id, + previous_value, + picking.number_of_packages, + ) + + @api.onchange("packages_qty") + def _onchange_picking_packages_qty(self): + _logger.info( + "[STOCK_PICKING_LOG] Onchange triggered for picking ID %s: packages_qty=%s", + self.id, + self.packages_qty, + ) + self._update_number_of_packages() + + def action_create_package(self): + _logger.info( + "[STOCK_PICKING_LOG] action_create_package triggered for picking ID %s", + self.id, + ) + super_result = super().action_create_package() + _logger.info( + "[STOCK_PICKING_LOG] Super action_create_package completed for picking ID %s", + self.id, + ) + self._update_number_of_packages() + _logger.info( + "[STOCK_PICKING_LOG] action_create_package: number_of_packages updated for picking ID %s", + self.id, + ) + return super_result + + def _action_generate_number_of_packages_wizard(self): + self.ensure_one() + _logger.info( + "[STOCK_PICKING_LOG] Generating number of packages wizard for picking ID %s with number_of_packages=%s", + self.id, + self.number_of_packages, + ) + view = self.env.ref("delivery_package_number.view_number_package_validate") + wizard_action = { + "name": _("Set number of packages"), + "type": "ir.actions.act_window", + "view_mode": "form", + "res_model": "stock.number.package.validate.wizard", + "views": [(view.id, "form")], + "view_id": view.id, + "target": "new", + "context": dict( + self.env.context, + default_pick_ids=[(4, p.id) for p in self], + default_number_of_packages=self.number_of_packages, + ), + } + _logger.info( + "[STOCK_PICKING_LOG] Wizard action generated for picking ID %s: %s", + self.id, + wizard_action, + ) + return wizard_action + + def _get_pickings_to_set_number_of_packages(self): + """Obtener los pickings que necesitan el wizard para llenar el nĂºmero de paquetes.""" + _logger.info( + "[STOCK_PICKING_LOG] Fetching pickings to set number of packages..." + ) + pickings_to_set_number_of_packages = ( + super()._get_pickings_to_set_number_of_packages() + ) + _logger.info( + "[STOCK_PICKING_LOG] Initial pickings from super: %s", + pickings_to_set_number_of_packages.ids, + ) + for picking in self: + _logger.info( + "[STOCK_PICKING_LOG] Adding picking ID %s to the result set.", + picking.id, + ) + pickings_to_set_number_of_packages |= picking + _logger.info( + "[STOCK_PICKING_LOG] Final pickings to set number of packages: %s", + pickings_to_set_number_of_packages.ids, + ) + return pickings_to_set_number_of_packages