diff --git a/setup/stock_packaging_calculator_packaging_level/odoo/addons/stock_packaging_calculator_packaging_level b/setup/stock_packaging_calculator_packaging_level/odoo/addons/stock_packaging_calculator_packaging_level new file mode 120000 index 000000000..a0a855467 --- /dev/null +++ b/setup/stock_packaging_calculator_packaging_level/odoo/addons/stock_packaging_calculator_packaging_level @@ -0,0 +1 @@ +../../../../stock_packaging_calculator_packaging_level \ No newline at end of file diff --git a/setup/stock_packaging_calculator_packaging_level/setup.py b/setup/stock_packaging_calculator_packaging_level/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_packaging_calculator_packaging_level/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_packaging_calculator_packaging_level/README.rst b/stock_packaging_calculator_packaging_level/README.rst new file mode 100644 index 000000000..ad385a7b1 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/README.rst @@ -0,0 +1,90 @@ +========================================= +Stock packaging calculator packaging type +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:61fe6c94961cafcf1382441c5d6cd7752a90da24cc6f12beb077a3da0e89a1d9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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/14.0/stock_packaging_calculator_packaging_type + :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-14-0/stock-logistics-warehouse-14-0-stock_packaging_calculator_packaging_type + :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=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Glue module for `stock_packaging_calculator` and `product_packaging_type`. + +Mainly to use packaging type's code instead of packaging's name. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**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 +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Simone Orsi +* `Trobz `_: + * Nguyen Hoang Hiep + +Other credits +~~~~~~~~~~~~~ + +The migration of this module from 13.0 to 14.0 was financially supported by Camptocamp + +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_packaging_calculator_packaging_level/__init__.py b/stock_packaging_calculator_packaging_level/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_packaging_calculator_packaging_level/__manifest__.py b/stock_packaging_calculator_packaging_level/__manifest__.py new file mode 100644 index 000000000..23ed6967d --- /dev/null +++ b/stock_packaging_calculator_packaging_level/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2021 Camptocamp SA +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) +{ + "name": "Stock packaging calculator packaging level", + "summary": "Glue module for packaging level", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Warehouse Management", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "LGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": ["stock_packaging_calculator", "product_packaging_level"], +} diff --git a/stock_packaging_calculator_packaging_level/i18n/stock_packaging_calculator_packaging_type.pot b/stock_packaging_calculator_packaging_level/i18n/stock_packaging_calculator_packaging_type.pot new file mode 100644 index 000000000..7ef0cdc1a --- /dev/null +++ b/stock_packaging_calculator_packaging_level/i18n/stock_packaging_calculator_packaging_type.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_packaging_calculator_packaging_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_packaging_calculator_packaging_type +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_product__display_name +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_qty_by_packaging_mixin__display_name +msgid "Display Name" +msgstr "" + +#. module: stock_packaging_calculator_packaging_type +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_product__id +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_qty_by_packaging_mixin__id +msgid "ID" +msgstr "" + +#. module: stock_packaging_calculator_packaging_type +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_product____last_update +#: model:ir.model.fields,field_description:stock_packaging_calculator_packaging_type.field_product_qty_by_packaging_mixin____last_update +msgid "Last Modified on" +msgstr "" + +#. module: stock_packaging_calculator_packaging_type +#: model:ir.model,name:stock_packaging_calculator_packaging_type.model_product_product +msgid "Product" +msgstr "" + +#. module: stock_packaging_calculator_packaging_type +#: model:ir.model,name:stock_packaging_calculator_packaging_type.model_product_qty_by_packaging_mixin +msgid "Product Qty By Packaging (Mixin)" +msgstr "" diff --git a/stock_packaging_calculator_packaging_level/models/__init__.py b/stock_packaging_calculator_packaging_level/models/__init__.py new file mode 100644 index 000000000..fb73bb4d1 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/models/__init__.py @@ -0,0 +1,2 @@ +from . import product +from . import product_qty_by_packaging_mixin diff --git a/stock_packaging_calculator_packaging_level/models/product.py b/stock_packaging_calculator_packaging_level/models/product.py new file mode 100644 index 000000000..e5cb0639d --- /dev/null +++ b/stock_packaging_calculator_packaging_level/models/product.py @@ -0,0 +1,25 @@ +# Copyright 2021 Camptocamp SA +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) + +from odoo import models + + +class Product(models.Model): + _inherit = "product.product" + + def _packaging_name_getter(self, packaging): + return packaging.packaging_level_id.name + + def _qty_by_packaging_as_str(self, packaging, qty): + # By default use packaging type code + qty_by_packaging_type_fname = self.env.context.get( + "qty_by_packaging_type_fname", "code" + ) + compact_mode = self.env.context.get("qty_by_packaging_type_compact", True) + sep = "" if compact_mode else " " + # Override to use packaging level code + if packaging and packaging.packaging_level_id: + name = packaging.packaging_level_id[qty_by_packaging_type_fname] + return f"{qty}{sep}{name}" + else: + return super()._qty_by_packaging_as_str(packaging, qty) diff --git a/stock_packaging_calculator_packaging_level/models/product_qty_by_packaging_mixin.py b/stock_packaging_calculator_packaging_level/models/product_qty_by_packaging_mixin.py new file mode 100644 index 000000000..2197968a8 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/models/product_qty_by_packaging_mixin.py @@ -0,0 +1,22 @@ +# Copyright 2021 Camptocamp SA +# @author: Simone Orsi +# @author: Sébastien Alix +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) +from odoo import api, models + + +class ProductQtyByPackagingMixin(models.AbstractModel): + """Allow displaying product qty by packaging.""" + + _inherit = "product.qty_by_packaging.mixin" + + # Amazing.. unlike `api.depends`, `depends_context` cannot use a lambda + # to delegate lookup. Hence we are forced to override and call super. + @api.depends_context( + "lang", + "qty_by_pkg_total_units", + "qty_by_packaging_type_fname", + "qty_by_packaging_type_compact", + ) + def _compute_product_qty_by_packaging_display(self): + return super()._compute_product_qty_by_packaging_display() diff --git a/stock_packaging_calculator_packaging_level/readme/CONTRIBUTORS.rst b/stock_packaging_calculator_packaging_level/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..85e36b884 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Simone Orsi +* `Trobz `_: + * Nguyen Hoang Hiep diff --git a/stock_packaging_calculator_packaging_level/readme/CREDITS.rst b/stock_packaging_calculator_packaging_level/readme/CREDITS.rst new file mode 100644 index 000000000..f37ebe757 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/readme/CREDITS.rst @@ -0,0 +1 @@ +The migration of this module from 13.0 to 14.0 was financially supported by Camptocamp diff --git a/stock_packaging_calculator_packaging_level/readme/DESCRIPTION.rst b/stock_packaging_calculator_packaging_level/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c4e69a515 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Glue module for `stock_packaging_calculator` and `product_packaging_type`. + +Mainly to use packaging type's code instead of packaging's name. diff --git a/stock_packaging_calculator_packaging_level/static/description/icon.png b/stock_packaging_calculator_packaging_level/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_packaging_calculator_packaging_level/static/description/icon.png differ diff --git a/stock_packaging_calculator_packaging_level/static/description/index.html b/stock_packaging_calculator_packaging_level/static/description/index.html new file mode 100644 index 000000000..c76095427 --- /dev/null +++ b/stock_packaging_calculator_packaging_level/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Stock packaging calculator packaging type + + + +
+

Stock packaging calculator packaging type

+ + +

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

+

Glue module for stock_packaging_calculator and product_packaging_type.

+

Mainly to use packaging type’s code instead of packaging’s name.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 13.0 to 14.0 was financially supported by 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_packaging_calculator_packaging_level/tests/__init__.py b/stock_packaging_calculator_packaging_level/tests/__init__.py new file mode 100644 index 000000000..c6b11a17e --- /dev/null +++ b/stock_packaging_calculator_packaging_level/tests/__init__.py @@ -0,0 +1 @@ +from . import test_packaging_by_qty diff --git a/stock_packaging_calculator_packaging_level/tests/test_packaging_by_qty.py b/stock_packaging_calculator_packaging_level/tests/test_packaging_by_qty.py new file mode 100644 index 000000000..775fa4e5b --- /dev/null +++ b/stock_packaging_calculator_packaging_level/tests/test_packaging_by_qty.py @@ -0,0 +1,56 @@ +# Copyright 2021 Camptocamp SA +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) +from odoo.addons.stock_packaging_calculator.tests.common import TestCommon +from odoo.addons.stock_packaging_calculator.tests.utils import make_pkg_values + + +class TestCalc(TestCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.level_retail_box = cls.env["product.packaging.level"].create( + {"name": "Retail Box", "code": "PACK", "sequence": 3} + ) + cls.level_transport_box = cls.env["product.packaging.level"].create( + {"name": "Transport Box", "code": "CASE", "sequence": 4} + ) + cls.level_pallet = cls.env["product.packaging.level"].create( + {"name": "Pallet", "code": "PALLET", "sequence": 5} + ) + cls.pkg_box.packaging_level_id = cls.level_retail_box + cls.pkg_big_box.packaging_level_id = cls.level_transport_box + cls.pkg_pallet.packaging_level_id = cls.level_pallet + + def test_calc_1(self): + expected = [ + make_pkg_values(self.pkg_pallet, qty=1, name=self.level_pallet.name), + make_pkg_values( + self.pkg_big_box, qty=3, name=self.level_transport_box.name + ), + make_pkg_values(self.pkg_box, qty=1, name=self.level_retail_box.name), + make_pkg_values(self.uom_unit, qty=5), + ] + self.assertEqual(self.product_a.product_qty_by_packaging(2655), expected) + + def test_calc_2(self): + expected = [ + make_pkg_values( + self.pkg_big_box, qty=1, name=self.level_transport_box.name + ), + make_pkg_values(self.pkg_box, qty=3, name=self.level_retail_box.name), + ] + self.assertEqual(self.product_a.product_qty_by_packaging(350), expected) + + def test_as_str(self): + self.assertEqual(self.product_a.product_qty_by_packaging_as_str(10), "10 Units") + self.assertEqual(self.product_a.product_qty_by_packaging_as_str(100), "2PACK") + self.assertEqual( + self.product_a.product_qty_by_packaging_as_str(250), "1CASE,\xa01PACK" + ) + self.assertEqual( + self.product_a.with_context( + qty_by_packaging_type_fname="name", + qty_by_packaging_type_compact=False, + ).product_qty_by_packaging_as_str(250), + "1 Transport Box,\xa01 Retail Box", + )