-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] stock_picking_package_number_glue
- Loading branch information
Showing
7 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/stock_picking_package_number_glue/odoo/addons/stock_picking_package_number_glue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../stock_picking_package_number_glue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_picking |
101 changes: 101 additions & 0 deletions
101
stock_picking_package_number_glue/models/stock_picking.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |