diff --git a/product_packaging_type_required/README.rst b/product_packaging_level_required/README.rst similarity index 78% rename from product_packaging_type_required/README.rst rename to product_packaging_level_required/README.rst index 186ae635064..bf6e393a7ca 100644 --- a/product_packaging_type_required/README.rst +++ b/product_packaging_level_required/README.rst @@ -1,6 +1,6 @@ -=============================== -Product Packaging Type Required -=============================== +================================ +Product Packaging Level Required +================================ .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -17,10 +17,10 @@ Product Packaging Type Required :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github - :target: https://github.com/OCA/product-attribute/tree/18.0/product_packaging_type_required + :target: https://github.com/OCA/product-attribute/tree/18.0/product_packaging_level_required :alt: OCA/product-attribute .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_type_required + :target: https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_packaging_level_required :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/product-attribute&target_branch=18.0 @@ -28,10 +28,10 @@ Product Packaging Type Required |badge1| |badge2| |badge3| |badge4| |badge5| -This module allows to mark a product packaging type as required. +This module allows to mark a product packaging level as required. A cron creates the missing product packages if the related packaging -type is required. +level is required. **Table of contents** @@ -41,10 +41,10 @@ type is required. Usage ===== -To set a packaging type as required: +To set a packaging level as required: -1. Go to *Sales > Configuration > Products > Product Packaging Type*. -2. You can make a type required +1. Go to *Inventory > Configuration > Product Packaging Level*. +2. You can make a level required Bug Tracker =========== @@ -52,7 +52,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -71,13 +71,14 @@ Contributors - Damien Crier - Simone Orsi - -- Phuc Tran Thanh + - Phuc Tran Thanh + - Tris Doan Other credits ------------- -The development of this module has been financially supported by: +The development and migration of this module has been financially +supported by: - Camptocamp @@ -105,6 +106,6 @@ Current `maintainers `__: |maintainer-simahawk| |maintainer-dcrier| -This module is part of the `OCA/product-attribute `_ project on GitHub. +This module is part of the `OCA/product-attribute `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_packaging_type_required/__init__.py b/product_packaging_level_required/__init__.py similarity index 100% rename from product_packaging_type_required/__init__.py rename to product_packaging_level_required/__init__.py diff --git a/product_packaging_type_required/__manifest__.py b/product_packaging_level_required/__manifest__.py similarity index 63% rename from product_packaging_type_required/__manifest__.py rename to product_packaging_level_required/__manifest__.py index acfb21eb74e..ff7580d8259 100644 --- a/product_packaging_type_required/__manifest__.py +++ b/product_packaging_level_required/__manifest__.py @@ -2,17 +2,17 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - "name": "Product Packaging Type Required", - "version": "14.0.1.1.0", + "name": "Product Packaging Level Required", + "version": "18.0.1.0.0", "development_status": "Beta", "category": "Product", - "summary": "Product Packaging Type Required", + "summary": "Product Packaging Level Required", "author": "Camptocamp, " "Odoo Community Association (OCA)", "maintainers": ["simahawk", "dcrier"], "website": "https://github.com/OCA/product-attribute", "license": "AGPL-3", - "depends": ["product", "product_packaging_type"], - "data": ["data/cron.xml", "views/product_packaging_type_view.xml"], + "depends": ["product_packaging_level"], + "data": ["data/cron.xml", "views/product_packaging_level_views.xml"], "installable": True, "auto_install": False, } diff --git a/product_packaging_type_required/data/cron.xml b/product_packaging_level_required/data/cron.xml similarity index 69% rename from product_packaging_type_required/data/cron.xml rename to product_packaging_level_required/data/cron.xml index 1f013de56d8..8908498f206 100644 --- a/product_packaging_type_required/data/cron.xml +++ b/product_packaging_level_required/data/cron.xml @@ -2,17 +2,12 @@ Packaging Required - + code - model.cron_check_create_required_packaging() + model.cron_check_create_required_packaging_level() 20 minutes - -1 - diff --git a/product_packaging_type_required/i18n/es.po b/product_packaging_level_required/i18n/es.po similarity index 100% rename from product_packaging_type_required/i18n/es.po rename to product_packaging_level_required/i18n/es.po diff --git a/product_packaging_type_required/i18n/it.po b/product_packaging_level_required/i18n/it.po similarity index 100% rename from product_packaging_type_required/i18n/it.po rename to product_packaging_level_required/i18n/it.po diff --git a/product_packaging_type_required/i18n/product_packaging_type_required.pot b/product_packaging_level_required/i18n/product_packaging_type_required.pot similarity index 100% rename from product_packaging_type_required/i18n/product_packaging_type_required.pot rename to product_packaging_level_required/i18n/product_packaging_type_required.pot diff --git a/product_packaging_level_required/models/__init__.py b/product_packaging_level_required/models/__init__.py new file mode 100644 index 00000000000..64a1316d44c --- /dev/null +++ b/product_packaging_level_required/models/__init__.py @@ -0,0 +1 @@ +from . import product_packaging_level diff --git a/product_packaging_type_required/models/product_packaging_type.py b/product_packaging_level_required/models/product_packaging_level.py similarity index 57% rename from product_packaging_type_required/models/product_packaging_type.py rename to product_packaging_level_required/models/product_packaging_level.py index 7c7d2a80406..5b7cedd9b9a 100644 --- a/product_packaging_type_required/models/product_packaging_type.py +++ b/product_packaging_level_required/models/product_packaging_level.py @@ -8,32 +8,30 @@ _logger = logging.getLogger(__name__) -class ProductPackagingType(models.Model): - _inherit = "product.packaging.type" +class ProductPackagingLevel(models.Model): + _inherit = "product.packaging.level" required = fields.Boolean() @api.model - def cron_check_create_required_packaging(self): - """Create required packaging for each consumable product if missing.""" - existing_products = self.env["product.product"].search( - [("type", "in", ("product", "consu"))] - ) - required_packaging_types = self.search([("required", "=", True)]) + def cron_check_create_required_packaging_level(self): + """Create required packaging level for each consumable product if missing.""" + existing_products = self.env["product.product"].search([("type", "=", "consu")]) + required_packaging_levels = self.search([("required", "=", True)]) packaging_model = self.env["product.packaging"] create_values = [] for product in existing_products: packagings = product.packaging_ids - existing_packaging_types = packagings.mapped("packaging_type_id") - missing_packaging_types = ( - required_packaging_types - existing_packaging_types + existing_packaging_levels = packagings.mapped("packaging_level_id") + missing_packaging_levels = ( + required_packaging_levels - existing_packaging_levels ) - if not missing_packaging_types: + if not missing_packaging_levels: continue create_values.extend( [ - ptype._prepare_required_packaging_vals(product) - for ptype in missing_packaging_types + plevel._prepare_required_packaging_vals(product) + for plevel in missing_packaging_levels ] ) if create_values: @@ -47,7 +45,7 @@ def cron_check_create_required_packaging(self): def _prepare_required_packaging_vals(self, product): res = { - "packaging_type_id": self.id, + "packaging_level_id": self.id, "name": self.name, "product_id": product.id, } diff --git a/product_packaging_type_required/pyproject.toml b/product_packaging_level_required/pyproject.toml similarity index 100% rename from product_packaging_type_required/pyproject.toml rename to product_packaging_level_required/pyproject.toml diff --git a/product_packaging_type_required/readme/CONTRIBUTORS.md b/product_packaging_level_required/readme/CONTRIBUTORS.md similarity index 65% rename from product_packaging_type_required/readme/CONTRIBUTORS.md rename to product_packaging_level_required/readme/CONTRIBUTORS.md index f37cb8ca66c..51785a62f70 100644 --- a/product_packaging_type_required/readme/CONTRIBUTORS.md +++ b/product_packaging_level_required/readme/CONTRIBUTORS.md @@ -1,4 +1,5 @@ - [Camptocamp](https://www.camptocamp.com) - Damien Crier \<\> - Simone Orsi \<\> -- Phuc Tran Thanh \<\> + - Phuc Tran Thanh \<\> + - Tris Doan \<\> diff --git a/product_packaging_level_required/readme/CREDITS.md b/product_packaging_level_required/readme/CREDITS.md new file mode 100644 index 00000000000..c2d2a1e6b83 --- /dev/null +++ b/product_packaging_level_required/readme/CREDITS.md @@ -0,0 +1,3 @@ +The development and migration of this module has been financially supported by: + +- Camptocamp diff --git a/product_packaging_level_required/readme/DESCRIPTION.md b/product_packaging_level_required/readme/DESCRIPTION.md new file mode 100644 index 00000000000..81cbeb82495 --- /dev/null +++ b/product_packaging_level_required/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module allows to mark a product packaging level as required. + +A cron creates the missing product packages if the related packaging +level is required. diff --git a/product_packaging_level_required/readme/USAGE.md b/product_packaging_level_required/readme/USAGE.md new file mode 100644 index 00000000000..abd1da7a4f1 --- /dev/null +++ b/product_packaging_level_required/readme/USAGE.md @@ -0,0 +1,4 @@ +To set a packaging level as required: +1. Go to *Inventory \> Configuration \> Product Packaging + Level*. +2. You can make a level required diff --git a/product_packaging_type_required/static/description/icon.png b/product_packaging_level_required/static/description/icon.png similarity index 100% rename from product_packaging_type_required/static/description/icon.png rename to product_packaging_level_required/static/description/icon.png diff --git a/product_packaging_type_required/static/description/index.html b/product_packaging_level_required/static/description/index.html similarity index 88% rename from product_packaging_type_required/static/description/index.html rename to product_packaging_level_required/static/description/index.html index e9bf73d73d5..2851f80ba18 100644 --- a/product_packaging_type_required/static/description/index.html +++ b/product_packaging_level_required/static/description/index.html @@ -3,7 +3,7 @@ -Product Packaging Type Required +Product Packaging Level Required -
-

Product Packaging Type Required

+
+

Product Packaging Level Required

-

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

-

This module allows to mark a product packaging type as required.

+

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

+

This module allows to mark a product packaging level as required.

A cron creates the missing product packages if the related packaging -type is required.

+level is required.

Table of contents

    @@ -389,10 +389,10 @@

    Product Packaging Type Required

Usage

-

To set a packaging type as required:

+

To set a packaging level as required:

    -
  1. Go to Sales > Configuration > Products > Product Packaging Type.
  2. -
  3. You can make a type required
  4. +
  5. Go to Inventory > Configuration > Product Packaging Level.
  6. +
  7. You can make a level required
@@ -400,7 +400,7 @@

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.

+feedback.

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

@@ -417,14 +417,16 @@

Contributors

  • Camptocamp
  • -
  • Phuc Tran Thanh <phuc@trobz.com>
  • Other credits

    -

    The development of this module has been financially supported by:

    +

    The development and migration of this module has been financially +supported by:

    • Camptocamp
    @@ -440,7 +442,7 @@

    Maintainers

    promote its widespread use.

    Current maintainers:

    simahawk dcrier

    -

    This module is part of the OCA/product-attribute project on GitHub.

    +

    This module is part of the OCA/product-attribute project on GitHub.

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

    diff --git a/product_packaging_type_required/tests/__init__.py b/product_packaging_level_required/tests/__init__.py similarity index 100% rename from product_packaging_type_required/tests/__init__.py rename to product_packaging_level_required/tests/__init__.py diff --git a/product_packaging_level_required/tests/test_packaging_required.py b/product_packaging_level_required/tests/test_packaging_required.py new file mode 100644 index 00000000000..bc41e560de5 --- /dev/null +++ b/product_packaging_level_required/tests/test_packaging_required.py @@ -0,0 +1,74 @@ +# Copyright 2021 Camptocamp SA +# @author Simone Orsi +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) +from odoo.tests import common +from odoo.tools.misc import mute_logger + + +class TestPackagingLevelRequired(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.template"].create( + {"name": "Product Test", "type": "consu"} + ) + cls.default_level = cls.env.ref( + "product_packaging_level.product_packaging_level_default" + ) + cls.default_level.write({"required": True}) + cls.test_level = cls.env["product.packaging.level"].create( + { + "name": "Packaging Level Test", + "code": "TEST2", + "sequence": 2, + "required": True, + } + ) + # Create packaging only for one of them + cls.pkg_box = cls.env["product.packaging"].create( + { + "name": "Box", + "product_id": cls.product.product_variant_ids.id, + "qty": 50, + "packaging_level_id": cls.default_level.id, + "barcode": "BOX", + } + ) + + @mute_logger( + "odoo.addons.product_packing_level_required.models.product_packaging_level" + ) + def test_cron_create(self): + products_count = self.env["product.product"].search_count( + [("type", "=", "consu")] + ) + count_packaging = self.env["product.packaging"].search_count + domain1 = [("packaging_level_id", "=", self.test_level.id)] + self.assertEqual(count_packaging(domain1), 0) + + domain2 = [("packaging_level_id", "=", self.default_level.id)] + self.assertEqual(count_packaging(domain2), 1) + + res = self.env[ + "product.packaging.level" + ].cron_check_create_required_packaging_level() + # We get one required packaging per level per product + self.assertEqual(count_packaging(domain1), products_count) + self.assertEqual(count_packaging(domain2), products_count) + # 1 was already created at the setup + created_count = (products_count * 2) - 1 + self.assertEqual(res, f"CREATED {created_count} required packaging") + + # Let's add another one + self.env["product.packaging.level"].create( + { + "name": "Packaging Level Test 3", + "code": "TEST3", + "sequence": 3, + "required": True, + } + ) + res = self.env[ + "product.packaging.level" + ].cron_check_create_required_packaging_level() + self.assertEqual(res, f"CREATED {products_count} required packaging") diff --git a/product_packaging_level_required/views/product_packaging_level_views.xml b/product_packaging_level_required/views/product_packaging_level_views.xml new file mode 100644 index 00000000000..dfde64f78d7 --- /dev/null +++ b/product_packaging_level_required/views/product_packaging_level_views.xml @@ -0,0 +1,31 @@ + + + + product.packaging.level.list.inherit + product.packaging.level + + + + + + + + + + product.packaging.level.form.inherit + product.packaging.level + + + + + + + + + diff --git a/product_packaging_type_required/migrations/14.0.1.1.0/post-migrate.py b/product_packaging_type_required/migrations/14.0.1.1.0/post-migrate.py deleted file mode 100644 index 4745cac5dd5..00000000000 --- a/product_packaging_type_required/migrations/14.0.1.1.0/post-migrate.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2021 Camptocamp (http://www.camptocamp.com). -# @author Simone Orsi -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import logging - -from odoo import SUPERUSER_ID, api - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - env = api.Environment(cr, SUPERUSER_ID, {}) - _logger.info("product_packaging_type_required: fix 'Packaging Required' cron") - # This cron has `noupdate` on, we must fix it here - cron = env.ref("product_packaging_type_required.ir_cron_packaging_required", False) - if cron: - cron.code = "model.cron_check_create_required_packaging()" diff --git a/product_packaging_type_required/models/__init__.py b/product_packaging_type_required/models/__init__.py deleted file mode 100644 index 643870a78df..00000000000 --- a/product_packaging_type_required/models/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from . import product_packaging_type diff --git a/product_packaging_type_required/readme/CREDITS.md b/product_packaging_type_required/readme/CREDITS.md deleted file mode 100644 index 705d3b30cad..00000000000 --- a/product_packaging_type_required/readme/CREDITS.md +++ /dev/null @@ -1,3 +0,0 @@ -The development of this module has been financially supported by: - -- Camptocamp diff --git a/product_packaging_type_required/readme/DESCRIPTION.md b/product_packaging_type_required/readme/DESCRIPTION.md deleted file mode 100644 index 4582468025e..00000000000 --- a/product_packaging_type_required/readme/DESCRIPTION.md +++ /dev/null @@ -1,4 +0,0 @@ -This module allows to mark a product packaging type as required. - -A cron creates the missing product packages if the related packaging -type is required. diff --git a/product_packaging_type_required/readme/USAGE.md b/product_packaging_type_required/readme/USAGE.md deleted file mode 100644 index a7b23827b61..00000000000 --- a/product_packaging_type_required/readme/USAGE.md +++ /dev/null @@ -1,5 +0,0 @@ -To set a packaging type as required: - -1. Go to *Sales \> Configuration \> Products \> Product Packaging - Type*. -2. You can make a type required diff --git a/product_packaging_type_required/tests/test_packaging_required.py b/product_packaging_type_required/tests/test_packaging_required.py deleted file mode 100644 index acc64cb050f..00000000000 --- a/product_packaging_type_required/tests/test_packaging_required.py +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright 2021 Camptocamp SA -# @author Simone Orsi -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) -from odoo.tests.common import SavepointCase -from odoo.tools.misc import mute_logger - - -class TestPackagingTypeRequired(SavepointCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.product = product = cls.env.ref("product.product_product_6") - cls.pkg_type_model = cls.env["product.packaging.type"] - # create some required types - cls.type_retail_box = cls.pkg_type_model.create( - {"name": "Retail Box", "code": "PACK", "sequence": 3, "required": True} - ) - cls.type_transport_box = cls.pkg_type_model.create( - {"name": "Transport Box", "code": "CASE", "sequence": 4, "required": True} - ) - cls.type_pallet = cls.pkg_type_model.create( - {"name": "Pallet", "code": "PALLET", "sequence": 5, "required": True} - ) - # Create packaging only for one of them - cls.pkg_box = cls.env["product.packaging"].create( - { - "name": "Box", - "product_id": product.id, - "qty": 50, - "packaging_type_id": cls.type_retail_box.id, - "barcode": "BOX", - } - ) - - @mute_logger( - "odoo.addons.product_packaging_type_required.models.product_packaging_type" - ) - def test_cron_create(self): - products_count = self.env["product.product"].search_count( - [("type", "in", ("product", "consu"))] - ) - count_packaging = self.env["product.packaging"].search_count - domain1 = [("packaging_type_id", "=", self.type_transport_box.id)] - self.assertEqual(count_packaging(domain1), 0) - domain2 = [("packaging_type_id", "=", self.type_pallet.id)] - self.assertEqual(count_packaging(domain2), 0) - domain3 = [("packaging_type_id", "=", self.type_retail_box.id)] - self.assertEqual(count_packaging(domain3), 1) - res = self.pkg_type_model.cron_check_create_required_packaging() - # We get one required packaging per type per product - self.assertEqual(count_packaging(domain1), products_count) - self.assertEqual(count_packaging(domain2), products_count) - self.assertEqual(count_packaging(domain3), products_count) - # 1 was already created at the setup - created_count = (products_count * 3) - 1 - self.assertEqual(res, f"CREATED {created_count} required packaging") - # Let's add another one - self.pkg_type_model.create( - {"name": "Small box", "code": "S BOX", "sequence": 6, "required": True} - ) - res = self.pkg_type_model.cron_check_create_required_packaging() - self.assertEqual(res, f"CREATED {products_count} required packaging") diff --git a/product_packaging_type_required/views/product_packaging_type_view.xml b/product_packaging_type_required/views/product_packaging_type_view.xml deleted file mode 100644 index 405d16ada3e..00000000000 --- a/product_packaging_type_required/views/product_packaging_type_view.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - product.packaging.type.tree - product.packaging.type - - - - - - - - - - product.packaging.type.form - product.packaging.type - - - - - - - - -