diff --git a/setup/stock_picking_volume_packaging/odoo/addons/stock_picking_volume_packaging b/setup/stock_picking_volume_packaging/odoo/addons/stock_picking_volume_packaging new file mode 120000 index 000000000000..3de6a14081c7 --- /dev/null +++ b/setup/stock_picking_volume_packaging/odoo/addons/stock_picking_volume_packaging @@ -0,0 +1 @@ +../../../../stock_picking_volume_packaging \ No newline at end of file diff --git a/setup/stock_picking_volume_packaging/setup.py b/setup/stock_picking_volume_packaging/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/stock_picking_volume_packaging/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_volume_packaging/README.rst b/stock_picking_volume_packaging/README.rst new file mode 100644 index 000000000000..5585d6104efe --- /dev/null +++ b/stock_picking_volume_packaging/README.rst @@ -0,0 +1,108 @@ +=================================== +Stock Picking Volume From Packaging +=================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_packaging + :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_packaging + :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| + +This modules improves the way the volume is computed on a stock.move by +taking into account the volume of the potential product packaging +that can be picked to fulfill the move. + +The potential packaging that can be picked for a move are computed by the +module *stock_packaging_calculator*. Thanks to this module we can compute the +best distribution of the packaging to uses to fulfill a specific quantity of a +product. (This information is important for the picking operators to minimize +the number of manipulations to do. Even if this information is not available +into the Odoo UI, The *Shopfloor* addon takes advantage of it to propose +the best picking strategy to the user). + +By default the volume information is not available on the product packaging. +Hopefully the module *product_packaging_dimension* provides this information. + +Since the volume information is not a mandatory field on the product packaging +when we ask for the best distribution of the packaging, packaging without volume +information are ignored. In this way we ensure that the volume of the packaging +is only taken into account when it's relevant otherwise we fallback on the +volume of the products. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +This modules makes sense only if you manage the volume information on +your product packaging definitions. If you don't, you can ignore this module. + +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 (http://acsone.eu) +* Guewen Baconnier `_ 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_packaging/__init__.py b/stock_picking_volume_packaging/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/stock_picking_volume_packaging/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_picking_volume_packaging/__manifest__.py b/stock_picking_volume_packaging/__manifest__.py new file mode 100644 index 000000000000..1ed251fac522 --- /dev/null +++ b/stock_picking_volume_packaging/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Picking Volume From Packaging", + "summary": """ + Use volume information on potential product packaging to compute the + volume of a stock.move""", + "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", + "depends": [ + "stock_picking_volume", + "stock_packaging_calculator", + "product_packaging_dimension", + ], + "data": [], + "demo": [], +} diff --git a/stock_picking_volume_packaging/models/__init__.py b/stock_picking_volume_packaging/models/__init__.py new file mode 100644 index 000000000000..6bda2d2428e0 --- /dev/null +++ b/stock_picking_volume_packaging/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/stock_picking_volume_packaging/models/stock_move.py b/stock_picking_volume_packaging/models/stock_move.py new file mode 100644 index 000000000000..0a5fdde4a749 --- /dev/null +++ b/stock_picking_volume_packaging/models/stock_move.py @@ -0,0 +1,29 @@ +# Copyright 2020-2022 Camptocamp SA +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class StockMove(models.Model): + + _inherit = "stock.move" + + def _get_volume_for_qty(self, qty): + self.ensure_one() + product = self.product_id + if not product.packaging_ids.filtered("volume"): + return super()._get_volume_for_qty(qty=qty) + packagings_with_volume = product.with_context( + _packaging_filter=lambda p: p.volume + ).product_qty_by_packaging(qty) + volume = 0 + for packaging_info in packagings_with_volume: + if packaging_info.get("is_unit"): + pack_volume = product.volume + else: + packaging = self.env["product.packaging"].browse(packaging_info["id"]) + pack_volume = packaging.volume + + volume += pack_volume * packaging_info["qty"] + return volume diff --git a/stock_picking_volume_packaging/readme/CONTRIBUTORS.rst b/stock_picking_volume_packaging/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..90b4c1cd2038 --- /dev/null +++ b/stock_picking_volume_packaging/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Laurent Mignon (http://acsone.eu) +* Guewen Baconnier + + + + + +Stock Picking Volume From Packaging + + + +
+

Stock Picking Volume From Packaging

+ + +

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

+

This modules improves the way the volume is computed on a stock.move by +taking into account the volume of the potential product packaging +that can be picked to fulfill the move.

+

The potential packaging that can be picked for a move are computed by the +module stock_packaging_calculator. Thanks to this module we can compute the +best distribution of the packaging to uses to fulfill a specific quantity of a +product. (This information is important for the picking operators to minimize +the number of manipulations to do. Even if this information is not available +into the Odoo UI, The Shopfloor addon takes advantage of it to propose +the best picking strategy to the user).

+

By default the volume information is not available on the product packaging. +Hopefully the module product_packaging_dimension provides this information.

+

Since the volume information is not a mandatory field on the product packaging +when we ask for the best distribution of the packaging, packaging without volume +information are ignored. In this way we ensure that the volume of the packaging +is only taken into account when it’s relevant otherwise we fallback on the +volume of the products.

+

Table of contents

+ +
+

Usage

+

This modules makes sense only if you manage the volume information on +your product packaging definitions. If you don’t, you can ignore this module.

+
+
+

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
  • +
  • Camptocamp
  • +
+
+
+

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.

+

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_packaging/tests/__init__.py b/stock_picking_volume_packaging/tests/__init__.py new file mode 100644 index 000000000000..27cec94648f3 --- /dev/null +++ b/stock_picking_volume_packaging/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_move_volume diff --git a/stock_picking_volume_packaging/tests/test_stock_move_volume.py b/stock_picking_volume_packaging/tests/test_stock_move_volume.py new file mode 100644 index 000000000000..4b4e0b4b2306 --- /dev/null +++ b/stock_picking_volume_packaging/tests/test_stock_move_volume.py @@ -0,0 +1,90 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestStockMoveVolume(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.product = cls.env["product.product"].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.pkg_box = cls.env["product.packaging"].create( + { + "name": "Box", + "product_id": cls.product.id, + "qty": 5, + "barcode": "BOX", + "length_uom_id": cls.env.ref("uom.product_uom_meter").id, + } + ) + cls.pkg_big_box = cls.env["product.packaging"].create( + { + "name": "Big Box", + "product_id": cls.product.id, + "qty": 10, + "barcode": "BIGBOX", + "length_uom_id": cls.env.ref("uom.product_uom_meter").id, + } + ) + + def test_move_volume_package_no_dimension(self): + """ + Data: + one product template with dimensions + no dimensions on packaging + Test Case: + get the move volume for a quantity of 16 + Expected result: + volume is 16 * 10 * 5 * 3 = 2400 + """ + move = self.env["stock.move"].new( + {"product_id": self.product, "product_uom_qty": 16} + ) + self.assertEqual(move._get_volume_for_qty(16), 2400) + + def test_move_volume_package_with_dimension(self): + """ + Data: + one product template with dimensions + Volumes on packaging are: + - box: 1 + - big box: 2 + Test Case: + get the move volume for a quantity of 16 + Expected result: + volume + - unit: 1 * 10 * 5 * 3 = 150 + - box: 1 * 1 * 1 * 1 = 1 + - big box: 2 * 1 * 1 * 1 = 2 + volume total = 150 + 1 + 2 = 153 + """ + self.pkg_box.write( + { + "packaging_length": 1, + "width": 1, + "height": 1, + } + ) + self.pkg_big_box.write( + { + "packaging_length": 1, + "width": 1, + "height": 2, + } + ) + move = self.env["stock.move"].new( + {"product_id": self.product, "product_uom_qty": 16} + ) + + self.assertEqual(move._get_volume_for_qty(16), 153)