diff --git a/setup/stock_picking_volume/odoo/addons/stock_picking_volume b/setup/stock_picking_volume/odoo/addons/stock_picking_volume new file mode 120000 index 000000000..a95ab0794 --- /dev/null +++ b/setup/stock_picking_volume/odoo/addons/stock_picking_volume @@ -0,0 +1 @@ +../../../../stock_picking_volume \ No newline at end of file diff --git a/setup/stock_picking_volume/setup.py b/setup/stock_picking_volume/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_picking_volume/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_volume/README.rst b/stock_picking_volume/README.rst new file mode 100644 index 000000000..362c266d8 --- /dev/null +++ b/stock_picking_volume/README.rst @@ -0,0 +1,117 @@ +==================== +Stock Picking Volume +==================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/16/stock_picking_volume + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-16/stock-logistics-warehouse-16-stock_picking_volume + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/16 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +For some processes, you need to know the volume of your stock picking. This could +be useful for example to know the device to use to process it. An other use case +could be to know how many trucks you need to deliver your products. + +By default, the delivery module from Odoo will compute the picking weight. +Unfortunately, it will not compute the volume. This module will add the volume +computation to the picking and to the stock move. This information will be +stored in the database and will be available on the picking form view and +on the stock move form view. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +In order to have a pertinent value for the computed volume, the dimension fields +must be set on all the products. + +The computed volume depends on the move state. + +* If the move is done, the volume is the volume for the qty done. +* If the move is cancelled or draft waiting, the volume is the volume for the + qty to do. +* if the move is available or partially available, the volume is the volume + for the reserved quantity. + +When the module is installed on an existing database, the volume field is only +computed for the stock moves of pickings not yet processed. +The moves in a cancelled or done picking are not updated to avoid to freeze the +database for a long time during the upgrade process if it contains a lot of +stock moves and pickings. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laurent Mignon (https://www.acsone.eu/) + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* ACSONE SA/NV +* Alcyon Benelux + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px + :target: https://github.com/lmignon + :alt: lmignon + +Current `maintainer `__: + +|maintainer-lmignon| + +This module is part of the `OCA/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_volume/__init__.py b/stock_picking_volume/__init__.py new file mode 100644 index 000000000..f69c7729c --- /dev/null +++ b/stock_picking_volume/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook, pre_init_hook diff --git a/stock_picking_volume/__manifest__.py b/stock_picking_volume/__manifest__.py new file mode 100644 index 000000000..d95657170 --- /dev/null +++ b/stock_picking_volume/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Picking Volume", + "summary": """ + Compute volume information on stock moves and pickings""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "maintainers": ["lmignon"], + "depends": [ + "product_dimension", + "stock", + ], + "data": [ + "views/stock_picking.xml", + "views/stock_move.xml", + ], + "demo": [], + "post_init_hook": "post_init_hook", + "pre_init_hook": "pre_init_hook", + "development_status": "Beta", +} diff --git a/stock_picking_volume/hooks.py b/stock_picking_volume/hooks.py new file mode 100644 index 000000000..6ed58d7cd --- /dev/null +++ b/stock_picking_volume/hooks.py @@ -0,0 +1,32 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import logging + +from odoo import SUPERUSER_ID, api +from odoo.tools.sql import column_exists, create_column + +_logger = logging.getLogger(__name__) + + +def post_init_hook(cr, registry): + """Post init hook to set compute the volume on pending move and pickings.""" + env = api.Environment(cr, SUPERUSER_ID, {}) + pickings = env["stock.picking"].search([("state", "not in", ["done", "cancel"])]) + moves = env["stock.move"].search( + [ + "|", + ("state", "not in", ["done", "cancel"]), + ("picking_id", "in", pickings.ids), + ] + ) + _logger.info("Compute volumes for %d moves", len(moves)) + moves._compute_volume() + + +def pre_init_hook(cr): + """Pre init create volume column on stock.picking and stock.move""" + if not column_exists(cr, "stock_move", "volume"): + create_column(cr, "stock_move", "volume", "numeric") + if not column_exists(cr, "stock_picking", "volume"): + create_column(cr, "stock_picking", "volume", "numeric") diff --git a/stock_picking_volume/models/__init__.py b/stock_picking_volume/models/__init__.py new file mode 100644 index 000000000..a33bde1e8 --- /dev/null +++ b/stock_picking_volume/models/__init__.py @@ -0,0 +1,2 @@ +from . import stock_move +from . import stock_picking diff --git a/stock_picking_volume/models/stock_move.py b/stock_picking_volume/models/stock_move.py new file mode 100644 index 000000000..8bfce4aa7 --- /dev/null +++ b/stock_picking_volume/models/stock_move.py @@ -0,0 +1,49 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockMove(models.Model): + + _inherit = "stock.move" + + volume = fields.Float( + compute="_compute_volume", readonly=False, store=True, compute_sudo=True + ) + + volume_uom_name = fields.Char( + string="Volume unit of measure label", compute="_compute_volume_uom_name" + ) + + @api.depends("product_id", "product_uom_qty", "state", "move_line_ids.reserved_qty") + def _compute_volume(self): + for move in self: + qty = move.product_uom_qty + if move.state in ("partially_available", "assigned"): + qty = move.reserved_availability + new_volume = move._get_volume_for_qty(qty=qty) + if move.volume != new_volume: + move.volume = new_volume + + def _get_volume_for_qty(self, qty): + """Return the volume for the move. + + This method is meant to be inherited to change the volume + computation for a specific move. + + qty: float quantity to compute the volume for. + + An override of this method could take into account the packaging + of the product to compute the volume. (using the volume information + on the packaging provided by the module stock_quant_package_dimension + and the method product_qty_by_packaging on the product provided by the + module stock_packaging_calculator) + """ + self.ensure_one() + return qty * self.product_id.volume + + def _compute_volume_uom_name(self): + self.volume_uom_name = self.env[ + "product.template" + ]._get_volume_uom_name_from_ir_config_parameter() diff --git a/stock_picking_volume/models/stock_picking.py b/stock_picking_volume/models/stock_picking.py new file mode 100644 index 000000000..007df9cc7 --- /dev/null +++ b/stock_picking_volume/models/stock_picking.py @@ -0,0 +1,28 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockPicking(models.Model): + + _inherit = "stock.picking" + + volume = fields.Float( + compute="_compute_volume", readonly=False, store=True, compute_sudo=True + ) + volume_uom_name = fields.Char( + string="Volume unit of measure label", compute="_compute_volume_uom_name" + ) + + @api.depends("move_ids", "move_ids.volume") + def _compute_volume(self): + for picking in self: + new_volume = sum(picking.move_ids.mapped("volume")) + if picking.volume != new_volume: + picking.volume = new_volume + + def _compute_volume_uom_name(self): + self.volume_uom_name = self.env[ + "product.template" + ]._get_volume_uom_name_from_ir_config_parameter() diff --git a/stock_picking_volume/readme/CONTRIBUTORS.rst b/stock_picking_volume/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..ed1929f0d --- /dev/null +++ b/stock_picking_volume/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Laurent Mignon (https://www.acsone.eu/) diff --git a/stock_picking_volume/readme/CREDITS.rst b/stock_picking_volume/readme/CREDITS.rst new file mode 100644 index 000000000..c5a3e7318 --- /dev/null +++ b/stock_picking_volume/readme/CREDITS.rst @@ -0,0 +1,4 @@ +The development of this module has been financially supported by: + +* ACSONE SA/NV +* Alcyon Benelux diff --git a/stock_picking_volume/readme/DESCRIPTION.rst b/stock_picking_volume/readme/DESCRIPTION.rst new file mode 100644 index 000000000..3e0457aea --- /dev/null +++ b/stock_picking_volume/readme/DESCRIPTION.rst @@ -0,0 +1,9 @@ +For some processes, you need to know the volume of your stock picking. This could +be useful for example to know the device to use to process it. An other use case +could be to know how many trucks you need to deliver your products. + +By default, the delivery module from Odoo will compute the picking weight. +Unfortunately, it will not compute the volume. This module will add the volume +computation to the picking and to the stock move. This information will be +stored in the database and will be available on the picking form view and +on the stock move form view. diff --git a/stock_picking_volume/readme/USAGE.rst b/stock_picking_volume/readme/USAGE.rst new file mode 100644 index 000000000..f6ef8b7ec --- /dev/null +++ b/stock_picking_volume/readme/USAGE.rst @@ -0,0 +1,16 @@ +In order to have a pertinent value for the computed volume, the dimension fields +must be set on all the products. + +The computed volume depends on the move state. + +* If the move is done, the volume is the volume for the qty done. +* If the move is cancelled or draft waiting, the volume is the volume for the + qty to do. +* if the move is available or partially available, the volume is the volume + for the reserved quantity. + +When the module is installed on an existing database, the volume field is only +computed for the stock moves of pickings not yet processed. +The moves in a cancelled or done picking are not updated to avoid to freeze the +database for a long time during the upgrade process if it contains a lot of +stock moves and pickings. diff --git a/stock_picking_volume/static/description/icon.png b/stock_picking_volume/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_picking_volume/static/description/icon.png differ diff --git a/stock_picking_volume/static/description/index.html b/stock_picking_volume/static/description/index.html new file mode 100644 index 000000000..e09968829 --- /dev/null +++ b/stock_picking_volume/static/description/index.html @@ -0,0 +1,456 @@ + + + + + + +Stock Picking Volume + + + +
+

Stock Picking Volume

+ + +

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

For some processes, you need to know the volume of your stock picking. This could +be useful for example to know the device to use to process it. An other use case +could be to know how many trucks you need to deliver your products.

+

By default, the delivery module from Odoo will compute the picking weight. +Unfortunately, it will not compute the volume. This module will add the volume +computation to the picking and to the stock move. This information will be +stored in the database and will be available on the picking form view and +on the stock move form view.

+

Table of contents

+ +
+

Usage

+

In order to have a pertinent value for the computed volume, the dimension fields +must be set on all the products.

+

The computed volume depends on the move state.

+
    +
  • If the move is done, the volume is the volume for the qty done.
  • +
  • If the move is cancelled or draft waiting, the volume is the volume for the +qty to do.
  • +
  • if the move is available or partially available, the volume is the volume +for the reserved quantity.
  • +
+

When the module is installed on an existing database, the volume field is only +computed for the stock moves of pickings not yet processed. +The moves in a cancelled or done picking are not updated to avoid to freeze the +database for a long time during the upgrade process if it contains a lot of +stock moves and pickings.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • ACSONE SA/NV
  • +
  • Alcyon Benelux
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

lmignon

+

This module is part of the OCA/stock-logistics-warehouse project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_picking_volume/tests/__init__.py b/stock_picking_volume/tests/__init__.py new file mode 100644 index 000000000..69c6e6173 --- /dev/null +++ b/stock_picking_volume/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_picking_volume diff --git a/stock_picking_volume/tests/test_stock_picking_volume.py b/stock_picking_volume/tests/test_stock_picking_volume.py new file mode 100644 index 000000000..a7e1cb127 --- /dev/null +++ b/stock_picking_volume/tests/test_stock_picking_volume.py @@ -0,0 +1,141 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestStockPickingVolume(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.wh = cls.env["stock.warehouse"].create( + { + "name": "Base Warehouse", + "reception_steps": "one_step", + "delivery_steps": "ship_only", + "code": "BWH", + } + ) + cls.loc_stock = cls.wh.lot_stock_id + cls.loc_customer = cls.env.ref("stock.stock_location_customers") + cls.product_template = cls.env["product.template"].create( + { + "name": "Unittest P1", + "product_length": 10.0, + "product_width": 5.0, + "product_height": 3.0, + "uom_id": cls.env.ref("uom.product_uom_unit").id, + "type": "product", + } + ) + cls.product = cls.product_template.product_variant_ids + cls.picking_type_out = cls.env.ref("stock.picking_type_out") + cls.picking = cls.env["stock.picking"].create( + { + "picking_type_id": cls.picking_type_out.id, + "location_id": cls.loc_stock.id, + "location_dest_id": cls.loc_customer.id, + "partner_id": cls.env.ref("base.res_partner_1").id, + "move_ids": [ + ( + 0, + 0, + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_uom_qty": 5.0, + "location_id": cls.loc_stock.id, + "location_dest_id": cls.loc_customer.id, + }, + ) + ], + } + ) + + def _set_product_qty(self, product, qty): + self.env["stock.quant"]._update_available_quantity(product, self.loc_stock, qty) + + def test_picking_draft_volume(self): + """ + Data: + one picking with one move line with 5 units of product + Test Case: + get the volume of the picking + Expected result: + volume is 5 * 10 * 5 * 3 = 750 + The volume is computed from the expected quantity + """ + self.assertEqual(self.picking.volume, 750) + + def test_picking_partially_available_volume(self): + """ + Data: + one picking with one move line with 5 units of product + Test Case: + set 1 unit of product as available + get the volume of the picking + Expected result: + volume is 1 * 10 * 5 * 3 = 150 + The volume is computed from the available quantity + """ + self._set_product_qty(self.product, 1) + self.picking.action_confirm() + self.picking.action_assign() + self.assertEqual(self.picking.volume, 150) + + def test_picking_available_volume(self): + """ + Data: + one picking with one move line with 5 units of product + Test Case: + set 5 unit of product as available + get the volume of the picking + Expected result: + volume is 5 * 10 * 5 * 3 = 750 + The volume is computed from the expected quantity + """ + self._set_product_qty(self.product, 5) + self.picking.action_confirm() + self.picking.action_assign() + self.assertEqual(self.picking.volume, 750) + + def test_picking_done_volume(self): + """ + Data: + one picking with one move line with 5 units of product + Test Case: + set 1 unit of product as done + confirm the picking + get the volume of the picking + Expected result: + volume is 1 * 10 * 5 * 3 = 150 + The volume is computed from the done quantity + """ + self._set_product_qty(self.product, 1) + self.picking.action_confirm() + self.picking.action_assign() + self.picking.move_line_ids.qty_done = 1 + self.picking.button_validate() + self.assertEqual(self.picking.volume, 150) + + def test_picking_cancel_volume(self): + """ + Data: + one picking with one move line with 5 units of product + Test Case: + set 1 unit of product as done + confirm the picking + cancel the picking + get the volume of the picking + Expected result: + volume is 5 * 10 * 5 * 3 = 750 + The volume is computed from the expected quantity + """ + self._set_product_qty(self.product, 1) + self.picking.action_confirm() + self.picking.action_assign() + self.picking.move_line_ids.qty_done = 1 + self.picking.button_validate() + self.picking.action_cancel() + self.assertEqual(self.picking.volume, 750) diff --git a/stock_picking_volume/views/stock_move.xml b/stock_picking_volume/views/stock_move.xml new file mode 100644 index 000000000..4846eba86 --- /dev/null +++ b/stock_picking_volume/views/stock_move.xml @@ -0,0 +1,26 @@ + + + + + + stock.move.form (in stock_picking_volume) + stock.move + + + + + + + + diff --git a/stock_picking_volume/views/stock_picking.xml b/stock_picking_volume/views/stock_picking.xml new file mode 100644 index 000000000..6a55b0825 --- /dev/null +++ b/stock_picking_volume/views/stock_picking.xml @@ -0,0 +1,28 @@ + + + + + + stock.picking.form (in stock_picking_volume) + stock.picking + + + + + + + + + +