diff --git a/setup/stock_package_type_volume/odoo/addons/stock_package_type_volume b/setup/stock_package_type_volume/odoo/addons/stock_package_type_volume new file mode 120000 index 000000000..edd25a412 --- /dev/null +++ b/setup/stock_package_type_volume/odoo/addons/stock_package_type_volume @@ -0,0 +1 @@ +../../../../stock_package_type_volume \ No newline at end of file diff --git a/setup/stock_package_type_volume/setup.py b/setup/stock_package_type_volume/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_package_type_volume/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_package_type_volume/README.rst b/stock_package_type_volume/README.rst new file mode 100644 index 000000000..a5bab38e6 --- /dev/null +++ b/stock_package_type_volume/README.rst @@ -0,0 +1,78 @@ +========================= +Stock Package Type Volume +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bf20d34fd706590a701c72a8fed441b094edec4d6e1972ed48902f7464b6c1f1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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.0/stock_package_type_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-0/stock-logistics-warehouse-16-0-stock_package_type_volume + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +This module adds the volume to the package type. + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* ForgeFlow + * Jordi Ballester Alomar + +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. + +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_package_type_volume/__init__.py b/stock_package_type_volume/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_package_type_volume/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_package_type_volume/__manifest__.py b/stock_package_type_volume/__manifest__.py new file mode 100644 index 000000000..6ea86c33f --- /dev/null +++ b/stock_package_type_volume/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 ForgeFlow +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "Stock Package Type Volume", + "version": "16.0.1.0.0", + "summary": "Compute volume of a package type", + "category": "Warehouse", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "license": "LGPL-3", + "depends": [ + "stock", + ], + "data": [ + "views/stock_package_type_views.xml", + ], + "installable": True, +} diff --git a/stock_package_type_volume/models/__init__.py b/stock_package_type_volume/models/__init__.py new file mode 100644 index 000000000..a6844dd4b --- /dev/null +++ b/stock_package_type_volume/models/__init__.py @@ -0,0 +1 @@ +from . import stock_package_type diff --git a/stock_package_type_volume/models/stock_package_type.py b/stock_package_type_volume/models/stock_package_type.py new file mode 100644 index 000000000..58cddd8ba --- /dev/null +++ b/stock_package_type_volume/models/stock_package_type.py @@ -0,0 +1,72 @@ +# Copyright 2024 ForgeFlow +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class StockPackageType(models.Model): + _inherit = "stock.package.type" + + volume = fields.Float( + digits=(8, 4), + compute="_compute_volume", + readonly=True, + store=False, + help="The Packaging volume", + ) + + volume_uom_id = fields.Many2one( + "uom.uom", string="Volume Units of Measure", compute="_compute_volume_uom" + ) + volume_uom_name = fields.Char(compute="_compute_volume_uom") + + def _compute_volume_uom(self): + for rec in self: + rec.volume_uom_id = self.env[ + "product.template" + ]._get_volume_uom_id_from_ir_config_parameter() + rec.volume_uom_name = rec.volume_uom_id.name + + def convert_to_meters(self, measure, dimensional_uom): + uom_meters = self.env.ref("uom.product_uom_meter") + return dimensional_uom._compute_quantity( + qty=measure, + to_unit=uom_meters, + round=False, + ) + + def convert_to_volume_uom(self, measure, volume_uom_id): + uom_m3 = self.env.ref("uom.product_uom_cubic_meter") + return uom_m3._compute_quantity( + qty=measure, + to_unit=volume_uom_id, + round=False, + ) + + @api.model + def _calc_volume( + self, packaging_length, height, width, length_uom_id, volume_uom_id + ): + volume_m3 = 0 + if packaging_length and height and width and length_uom_id: + length_m = self.convert_to_meters(packaging_length, length_uom_id) + height_m = self.convert_to_meters(height, length_uom_id) + width_m = self.convert_to_meters(width, length_uom_id) + volume_m3 = length_m * height_m * width_m + volume_in_volume_uom = self.convert_to_volume_uom(volume_m3, volume_uom_id) + return volume_in_volume_uom + + @api.depends("packaging_length", "width", "height", "volume_uom_id") + def _compute_volume(self): + for rec in self: + length_uom_id = self.env[ + "product.template" + ]._get_length_uom_id_from_ir_config_parameter() + volume_in_volume_uom = rec._calc_volume( + rec.packaging_length, + rec.height, + rec.width, + length_uom_id, + rec.volume_uom_id, + ) + rec.volume = volume_in_volume_uom diff --git a/stock_package_type_volume/readme/CONTRIBUTORS.rst b/stock_package_type_volume/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..7381675b8 --- /dev/null +++ b/stock_package_type_volume/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* ForgeFlow + * Jordi Ballester Alomar diff --git a/stock_package_type_volume/readme/DESCRIPTION.rst b/stock_package_type_volume/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c48432abf --- /dev/null +++ b/stock_package_type_volume/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ + +This module adds the volume to the package type. diff --git a/stock_package_type_volume/static/description/index.html b/stock_package_type_volume/static/description/index.html new file mode 100644 index 000000000..2c0df50f3 --- /dev/null +++ b/stock_package_type_volume/static/description/index.html @@ -0,0 +1,427 @@ + + + + + +Stock Package Type Volume + + + +
+

Stock Package Type Volume

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

+

This module adds the volume to the package type.

+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

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_package_type_volume/tests/__init__.py b/stock_package_type_volume/tests/__init__.py new file mode 100644 index 000000000..010247961 --- /dev/null +++ b/stock_package_type_volume/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_package_type_volume diff --git a/stock_package_type_volume/tests/test_stock_package_type_volume.py b/stock_package_type_volume/tests/test_stock_package_type_volume.py new file mode 100644 index 000000000..230563290 --- /dev/null +++ b/stock_package_type_volume/tests/test_stock_package_type_volume.py @@ -0,0 +1,17 @@ +# Copyright 2024 ForgeFlow +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo.tests.common import TransactionCase + + +class TestStockPackageTypeVolume(TransactionCase): + def setUp(self): + super(TestStockPackageTypeVolume, self).setUp() + self.package_type = self.env["stock.package.type"].new() + + def test_01(self): + # By default length is in mm and volume in cubic meter + self.package_type.packaging_length = 1000.0 + self.package_type.height = 1000.0 + self.package_type.width = 1000.0 + self.assertEqual(1.0, self.package_type.volume) diff --git a/stock_package_type_volume/views/stock_package_type_views.xml b/stock_package_type_volume/views/stock_package_type_views.xml new file mode 100644 index 000000000..6c5d9642e --- /dev/null +++ b/stock_package_type_volume/views/stock_package_type_views.xml @@ -0,0 +1,19 @@ + + + + + stock.package.type.form + stock.package.type + + +
+
+
+
+ +