Skip to content

Commit

Permalink
[ADD] stock_picking_package_number_glue
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis committed Jan 22, 2025
1 parent 1e75fb9 commit fb966b4
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_picking_package_number_glue/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
76 changes: 76 additions & 0 deletions stock_picking_package_number_glue/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/avanzosc/odoo-addons/issues>`_.

Credits
=======

Contributors
------------

* Ana Juaristi <[email protected]>

* Unai Beristain <[email protected]>

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 <https://opensource.org/licenses/LGPL-3.0>.
1 change: 1 addition & 0 deletions stock_picking_package_number_glue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions stock_picking_package_number_glue/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
1 change: 1 addition & 0 deletions stock_picking_package_number_glue/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking
44 changes: 44 additions & 0 deletions stock_picking_package_number_glue/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
from odoo import api, models

# Configurar el logger
_logger = logging.getLogger(__name__)

class StockPicking(models.Model):
_inherit = "stock.picking"

@api.onchange("packages_qty")
def _onchange_picking_packages_qty(self):
for picking in self:
_logger.info(
"[STOCK_PICKING_LOG] Onchange triggered for picking ID %s: packages_qty=%s",
picking.id, picking.packages_qty
)
picking.number_of_packages = picking.packages_qty
_logger.info(
"[STOCK_PICKING_LOG] Updated number_of_packages for picking ID %s to %s",
picking.id, picking.number_of_packages
)

def _get_pickings_to_set_number_of_packages(self):
"""Get pickings that needed raise wizard to
fill number of packages for any number of packages"""
_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

0 comments on commit fb966b4

Please sign in to comment.