diff --git a/delivery_carrier_max_weight_constraint/README.rst b/delivery_carrier_max_weight_constraint/README.rst new file mode 100644 index 0000000000..a193e12d44 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/README.rst @@ -0,0 +1,94 @@ +================================ +Constrain package maximum weight +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6ba5257fa2a9b192424dfe7143ca22893a08d55d46cf69b0897cfcbf231a26bf + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fdelivery--carrier-lightgray.png?logo=github + :target: https://github.com/OCA/delivery-carrier/tree/17.0/delivery_carrier_max_weight_constraint + :alt: OCA/delivery-carrier +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/delivery-carrier-17-0/delivery-carrier-17-0-delivery_carrier_max_weight_constraint + :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/delivery-carrier&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module ensures the wizard of package type selection cannot create a +package with a weight greater than the maximum configured on its +packaging type if the constraint is enabled and maximum weight set. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The constraint can be enabled at multiple levels: + +- Company: *Settings* - *Inventory* - *Shipping* +- Carrier with company level as default +- Package type with carrier level as default + +If the constraint is disabled at the package type level Odoo behaves the +usual way. + +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 +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Nans Lefebvre +- Hughes Damry +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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/delivery-carrier `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/delivery_carrier_max_weight_constraint/__init__.py b/delivery_carrier_max_weight_constraint/__init__.py new file mode 100644 index 0000000000..5bb80146af --- /dev/null +++ b/delivery_carrier_max_weight_constraint/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models +from . import wizards diff --git a/delivery_carrier_max_weight_constraint/__manifest__.py b/delivery_carrier_max_weight_constraint/__manifest__.py new file mode 100644 index 0000000000..23dbbea3d8 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2021 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Constrain package maximum weight", + "version": "17.0.1.0.0", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "category": "Delivery", + "depends": ["stock_delivery"], + "website": "https://github.com/OCA/delivery-carrier", + "data": [ + "views/res_config_settings_views.xml", + "views/delivery_carrier_views.xml", + "views/stock_package_type_views.xml", + ], + "license": "AGPL-3", + "installable": True, +} diff --git a/delivery_carrier_max_weight_constraint/i18n/delivery_carrier_max_weight_constraint.pot b/delivery_carrier_max_weight_constraint/i18n/delivery_carrier_max_weight_constraint.pot new file mode 100644 index 0000000000..b57ac5f31d --- /dev/null +++ b/delivery_carrier_max_weight_constraint/i18n/delivery_carrier_max_weight_constraint.pot @@ -0,0 +1,79 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * delivery_carrier_max_weight_constraint +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_company +msgid "Companies" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model_terms:ir.ui.view,arch_db:delivery_carrier_max_weight_constraint.res_config_settings_view_form +msgid "Constrain the maximum weight of packages to be respected" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_choose_delivery_package +msgid "Delivery Package Selection Wizard" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "Overweight forbidden" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "Overweight package forbidden" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_company__delivery_carrier_strict_weight_package +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_config_settings__delivery_carrier_strict_weight_package +msgid "Overweight packages forbidden" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_delivery_carrier +msgid "Shipping Methods" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_stock_package_type +msgid "Stock package type" +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "The maximum weight of packages can't be exceeded." +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "The maximum weight of the package can't be exceeded." +msgstr "" + +#. module: delivery_carrier_max_weight_constraint +#. odoo-python +#: code:addons/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py:0 +#, python-format +msgid "" +"The weight of your package is higher than the maximum weight authorized for " +"this package type. Please choose another package type." +msgstr "" diff --git a/delivery_carrier_max_weight_constraint/i18n/es.po b/delivery_carrier_max_weight_constraint/i18n/es.po new file mode 100644 index 0000000000..4e6d5705ca --- /dev/null +++ b/delivery_carrier_max_weight_constraint/i18n/es.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * delivery_carrier_max_weight_constraint +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-08-03 15:09+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_company +msgid "Companies" +msgstr "Compañías" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_config_settings +msgid "Config Settings" +msgstr "Ajustes de Configuración" + +#. module: delivery_carrier_max_weight_constraint +#: model_terms:ir.ui.view,arch_db:delivery_carrier_max_weight_constraint.res_config_settings_view_form +msgid "Constrain the maximum weight of packages to be respected" +msgstr "Limitar el peso máximo a respetar de los paquetes" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_choose_delivery_package +msgid "Delivery Package Selection Wizard" +msgstr "Asistente de selección de paquetes de entrega" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "Overweight forbidden" +msgstr "Prohibido el sobrepeso" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "Overweight package forbidden" +msgstr "Paquete con sobrepeso prohibido" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_company__delivery_carrier_strict_weight_package +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_config_settings__delivery_carrier_strict_weight_package +msgid "Overweight packages forbidden" +msgstr "Paquetes con sobrepeso prohibido" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_delivery_carrier +msgid "Shipping Methods" +msgstr "Métodos de envío" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_stock_package_type +msgid "Stock package type" +msgstr "Tipo de empaquetado de existencias" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "The maximum weight of packages can't be exceeded." +msgstr "No se puede exceder el peso máximo de los paquetes." + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "The maximum weight of the package can't be exceeded." +msgstr "No se puede exceder el peso máximo del paquete." + +#. module: delivery_carrier_max_weight_constraint +#. odoo-python +#: code:addons/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py:0 +#, python-format +msgid "" +"The weight of your package is higher than the maximum weight authorized for " +"this package type. Please choose another package type." +msgstr "" +"El peso de su paquete es superior al peso máximo autorizado para este tipo " +"de paquete. Por favor, elija otro tipo de paquete." diff --git a/delivery_carrier_max_weight_constraint/i18n/it.po b/delivery_carrier_max_weight_constraint/i18n/it.po new file mode 100644 index 0000000000..d3f35a3213 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/i18n/it.po @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * delivery_carrier_max_weight_constraint +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-21 16:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_res_config_settings +msgid "Config Settings" +msgstr "Impostazioni configurazione" + +#. module: delivery_carrier_max_weight_constraint +#: model_terms:ir.ui.view,arch_db:delivery_carrier_max_weight_constraint.res_config_settings_view_form +msgid "Constrain the maximum weight of packages to be respected" +msgstr "Limitare il peso massimo dei pacchi da rispettare" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_choose_delivery_package +msgid "Delivery Package Selection Wizard" +msgstr "Procedura guidata selezione collo consegna" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "Overweight forbidden" +msgstr "Vietato il sovrappeso" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "Overweight package forbidden" +msgstr "Vietato il sovrappeso del collo" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_company__delivery_carrier_strict_weight_package +#: model:ir.model.fields,field_description:delivery_carrier_max_weight_constraint.field_res_config_settings__delivery_carrier_strict_weight_package +msgid "Overweight packages forbidden" +msgstr "Vietato il sovrappeso dei colli" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_delivery_carrier +msgid "Shipping Methods" +msgstr "Metodi di spedizione" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model,name:delivery_carrier_max_weight_constraint.model_stock_package_type +msgid "Stock package type" +msgstr "Tipo collo magazzino" + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_delivery_carrier__is_strict_weight_package +msgid "The maximum weight of packages can't be exceeded." +msgstr "Il peso massimo dei colli non può essere superato." + +#. module: delivery_carrier_max_weight_constraint +#: model:ir.model.fields,help:delivery_carrier_max_weight_constraint.field_stock_package_type__is_strict_weight +msgid "The maximum weight of the package can't be exceeded." +msgstr "Il peso massimo del collo non può essere superato." + +#. module: delivery_carrier_max_weight_constraint +#. odoo-python +#: code:addons/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py:0 +#, python-format +msgid "" +"The weight of your package is higher than the maximum weight authorized for " +"this package type. Please choose another package type." +msgstr "" +"Il peso del collo è superiore al massimo peso autorizzato per questo tipo di " +"collo. Scegliere un altro tipo di collo." diff --git a/delivery_carrier_max_weight_constraint/models/__init__.py b/delivery_carrier_max_weight_constraint/models/__init__.py new file mode 100644 index 0000000000..70e577f7fc --- /dev/null +++ b/delivery_carrier_max_weight_constraint/models/__init__.py @@ -0,0 +1,7 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import delivery_carrier +from . import res_company +from . import res_config_settings +from . import stock_package_type diff --git a/delivery_carrier_max_weight_constraint/models/delivery_carrier.py b/delivery_carrier_max_weight_constraint/models/delivery_carrier.py new file mode 100644 index 0000000000..dc9d80bced --- /dev/null +++ b/delivery_carrier_max_weight_constraint/models/delivery_carrier.py @@ -0,0 +1,25 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + is_strict_weight_package = fields.Boolean( + string="Overweight package forbidden", + help="The maximum weight of packages can't be exceeded.", + compute="_compute_is_strict_weight_package", + store=True, + readonly=False, + ) + + @api.depends("company_id.delivery_carrier_strict_weight_package") + def _compute_is_strict_weight_package(self): + for rec in self: + rec.is_strict_weight_package = ( + rec.company_id.delivery_carrier_strict_weight_package + if rec.company_id + else False + ) diff --git a/delivery_carrier_max_weight_constraint/models/res_company.py b/delivery_carrier_max_weight_constraint/models/res_company.py new file mode 100644 index 0000000000..beb12c37fe --- /dev/null +++ b/delivery_carrier_max_weight_constraint/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + delivery_carrier_strict_weight_package = fields.Boolean( + string="Overweight packages forbidden", + default=False, + ) diff --git a/delivery_carrier_max_weight_constraint/models/res_config_settings.py b/delivery_carrier_max_weight_constraint/models/res_config_settings.py new file mode 100644 index 0000000000..b067b5a533 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + delivery_carrier_strict_weight_package = fields.Boolean( + related="company_id.delivery_carrier_strict_weight_package", + readonly=False, + ) diff --git a/delivery_carrier_max_weight_constraint/models/stock_package_type.py b/delivery_carrier_max_weight_constraint/models/stock_package_type.py new file mode 100644 index 0000000000..682b1a1b2c --- /dev/null +++ b/delivery_carrier_max_weight_constraint/models/stock_package_type.py @@ -0,0 +1,25 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class PackageType(models.Model): + _inherit = "stock.package.type" + + is_strict_weight = fields.Boolean( + string="Overweight forbidden", + help="The maximum weight of the package can't be exceeded.", + compute="_compute_is_strict_weight", + store=True, + readonly=False, + ) + + @api.depends("company_id.delivery_carrier_strict_weight_package") + def _compute_is_strict_weight(self): + for rec in self: + rec.is_strict_weight = ( + rec.company_id.delivery_carrier_strict_weight_package + if rec.company_id + else False + ) diff --git a/delivery_carrier_max_weight_constraint/pyproject.toml b/delivery_carrier_max_weight_constraint/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/delivery_carrier_max_weight_constraint/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/delivery_carrier_max_weight_constraint/readme/CONTRIBUTORS.md b/delivery_carrier_max_weight_constraint/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..7ddfa6afd9 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Nans Lefebvre \<\> +- Hughes Damry \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/delivery_carrier_max_weight_constraint/readme/DESCRIPTION.md b/delivery_carrier_max_weight_constraint/readme/DESCRIPTION.md new file mode 100644 index 0000000000..864ffc33b8 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module ensures the wizard of package type selection cannot create a +package with a weight greater than the maximum configured on its +packaging type if the constraint is enabled and maximum weight set. diff --git a/delivery_carrier_max_weight_constraint/readme/USAGE.md b/delivery_carrier_max_weight_constraint/readme/USAGE.md new file mode 100644 index 0000000000..b734b06c7f --- /dev/null +++ b/delivery_carrier_max_weight_constraint/readme/USAGE.md @@ -0,0 +1,8 @@ +The constraint can be enabled at multiple levels: + +- Company: *Settings* - *Inventory* - *Shipping* +- Carrier with company level as default +- Package type with carrier level as default + +If the constraint is disabled at the package type level Odoo behaves the +usual way. diff --git a/delivery_carrier_max_weight_constraint/static/description/icon.png b/delivery_carrier_max_weight_constraint/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/delivery_carrier_max_weight_constraint/static/description/icon.png differ diff --git a/delivery_carrier_max_weight_constraint/static/description/index.html b/delivery_carrier_max_weight_constraint/static/description/index.html new file mode 100644 index 0000000000..572bea3bc3 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Constrain package maximum weight + + + +
+

Constrain package maximum weight

+ + +

Beta License: AGPL-3 OCA/delivery-carrier Translate me on Weblate Try me on Runboat

+

This module ensures the wizard of package type selection cannot create a +package with a weight greater than the maximum configured on its +packaging type if the constraint is enabled and maximum weight set.

+

Table of contents

+ +
+

Usage

+

The constraint can be enabled at multiple levels:

+
    +
  • Company: Settings - Inventory - Shipping
  • +
  • Carrier with company level as default
  • +
  • Package type with carrier level as default
  • +
+

If the constraint is disabled at the package type level Odoo behaves the +usual way.

+
+
+

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

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

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/delivery-carrier project on GitHub.

+

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

+
+
+
+ + diff --git a/delivery_carrier_max_weight_constraint/tests/__init__.py b/delivery_carrier_max_weight_constraint/tests/__init__.py new file mode 100644 index 0000000000..eb2978b49d --- /dev/null +++ b/delivery_carrier_max_weight_constraint/tests/__init__.py @@ -0,0 +1 @@ +from . import test_max_weight_constraint diff --git a/delivery_carrier_max_weight_constraint/tests/test_max_weight_constraint.py b/delivery_carrier_max_weight_constraint/tests/test_max_weight_constraint.py new file mode 100644 index 0000000000..fcf65a53ff --- /dev/null +++ b/delivery_carrier_max_weight_constraint/tests/test_max_weight_constraint.py @@ -0,0 +1,230 @@ +# Copyright 2021 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import ValidationError + +from odoo.addons.stock.tests.test_packing import TestPackingCommon + + +class TestMaxWeightConstraint(TestPackingCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.uom_kg = cls.env.ref("uom.product_uom_kgm") + cls.product_test = cls.env["product.product"].create( + { + "name": "Product TEST", + "type": "product", + "weight": 2, + "uom_id": cls.uom_kg.id, + "uom_po_id": cls.uom_kg.id, + } + ) + carrier_product = cls.env["product.product"].create( + { + "name": "Test carrier product", + "type": "service", + } + ) + cls.carrier = cls.env["delivery.carrier"].create( + { + "name": "Test carrier", + "delivery_type": "fixed", + "product_id": carrier_product.id, + } + ) + cls.package_type = cls.env["stock.package.type"].create( + { + "name": "Pack Type 1", + "max_weight": 10, + } + ) + # make some stock available + cls.env["stock.quant"]._update_available_quantity( + cls.product_test, cls.stock_location, 30.0 + ) + + def test_strict_weight_not_set(self): + """ + Check that the 'choose.delivery.package' wizard is working the normal way + The validation is ok even if the package is over the max_weight of the + package type + """ + # check package type hasn't weight constraint enabled + self.assertFalse(self.package_type.is_strict_weight) + + picking_ship = self.env["stock.picking"].create( + { + "partner_id": self.env["res.partner"].create({"name": "A partner"}).id, + "picking_type_id": self.warehouse.out_type_id.id, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "carrier_id": self.carrier.id, + } + ) + self.env["stock.move.line"].create( + { + "product_id": self.product_test.id, + "product_uom_id": self.uom_kg.id, + "picking_id": picking_ship.id, + "quantity": 6, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + } + ) + picking_ship.action_confirm() + pack_action = picking_ship.action_put_in_pack() + pack_action_ctx = pack_action["context"] + + # We instanciate the wizard with the context of the action + # Then set the delivery package type + pack_wiz = ( + self.env["choose.delivery.package"] + .with_context(**pack_action_ctx) + .create({}) + ) + # check the package is over the max_weight of package type + self.assertGreater(pack_wiz.shipping_weight, self.package_type.max_weight) + pack_wiz.delivery_package_type_id = self.package_type.id + # validate the wizard + pack_wiz.action_put_in_pack() + + def test_strict_weight_set_ok(self): + """ + Check that the 'choose.delivery.package' wizard is working the normal way + The validation is ok even if the package is under the max_weight of the + package type + """ + self.package_type.is_strict_weight = True + # check package type hasn't weight constraint enabled + self.assertTrue(self.package_type.is_strict_weight) + + picking_ship = self.env["stock.picking"].create( + { + "partner_id": self.env["res.partner"].create({"name": "A partner"}).id, + "picking_type_id": self.warehouse.out_type_id.id, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "carrier_id": self.carrier.id, + } + ) + self.env["stock.move.line"].create( + { + "product_id": self.product_test.id, + "product_uom_id": self.uom_kg.id, + "picking_id": picking_ship.id, + "quantity": 4, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + } + ) + picking_ship.action_confirm() + pack_action = picking_ship.action_put_in_pack() + pack_action_ctx = pack_action["context"] + + # We instanciate the wizard with the context of the action + # Then set the delivery package type + pack_wiz = ( + self.env["choose.delivery.package"] + .with_context(**pack_action_ctx) + .create({}) + ) + # check the package is under the max_weight of package type + self.assertGreater(self.package_type.max_weight, pack_wiz.shipping_weight) + pack_wiz.delivery_package_type_id = self.package_type.id + # validate the wizard + pack_wiz.action_put_in_pack() + + def test_strict_weight_set_error(self): + """ + Check that the 'choose.delivery.package' wizard is raising an error when + the package is over the max_weight of the package type + """ + self.package_type.is_strict_weight = True + # check package type hasn't weight constraint enabled + self.assertTrue(self.package_type.is_strict_weight) + + picking_ship = self.env["stock.picking"].create( + { + "partner_id": self.env["res.partner"].create({"name": "A partner"}).id, + "picking_type_id": self.warehouse.out_type_id.id, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "carrier_id": self.carrier.id, + } + ) + self.env["stock.move.line"].create( + { + "product_id": self.product_test.id, + "product_uom_id": self.uom_kg.id, + "picking_id": picking_ship.id, + "quantity": 6, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + } + ) + picking_ship.action_confirm() + pack_action = picking_ship.action_put_in_pack() + pack_action_ctx = pack_action["context"] + + # We instanciate the wizard with the context of the action + # Then set the delivery package type + pack_wiz = ( + self.env["choose.delivery.package"] + .with_context(**pack_action_ctx) + .create({}) + ) + # check the package is over the max_weight of package type + self.assertGreater(pack_wiz.shipping_weight, self.package_type.max_weight) + error_msg = ( + "The weight of your package is higher than the maximum " + "weight authorized for this package type. Please choose " + "another package type." + ) + with self.assertRaises(ValidationError, msg=error_msg): + pack_wiz.delivery_package_type_id = self.package_type.id + + def test_strict_weight_set_max_weightb_not_set(self): + """ + Check that the 'choose.delivery.package' wizard is working the normal way + when the constraint is set but package type max_weight not. + """ + self.package_type.is_strict_weight = True + # check package type hasn't weight constraint enabled + self.assertTrue(self.package_type.is_strict_weight) + + picking_ship = self.env["stock.picking"].create( + { + "partner_id": self.env["res.partner"].create({"name": "A partner"}).id, + "picking_type_id": self.warehouse.out_type_id.id, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + "carrier_id": self.carrier.id, + } + ) + self.env["stock.move.line"].create( + { + "product_id": self.product_test.id, + "product_uom_id": self.uom_kg.id, + "picking_id": picking_ship.id, + "quantity": 6, + "location_id": self.stock_location.id, + "location_dest_id": self.customer_location.id, + } + ) + picking_ship.action_confirm() + pack_action = picking_ship.action_put_in_pack() + pack_action_ctx = pack_action["context"] + + # We instanciate the wizard with the context of the action + # Then set the delivery package type + pack_wiz = ( + self.env["choose.delivery.package"] + .with_context(**pack_action_ctx) + .create({}) + ) + # set max_weight of package type to 0 + self.package_type.max_weight = 0 + pack_wiz.delivery_package_type_id = self.package_type.id + # validate the wizard + pack_wiz.action_put_in_pack() diff --git a/delivery_carrier_max_weight_constraint/views/delivery_carrier_views.xml b/delivery_carrier_max_weight_constraint/views/delivery_carrier_views.xml new file mode 100644 index 0000000000..0cbb5a54a6 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/views/delivery_carrier_views.xml @@ -0,0 +1,15 @@ + + + + delivery.carrier.form (in delivery_carrier_max_weight_constraint) + delivery.carrier + + + + + + + + diff --git a/delivery_carrier_max_weight_constraint/views/res_config_settings_views.xml b/delivery_carrier_max_weight_constraint/views/res_config_settings_views.xml new file mode 100644 index 0000000000..873726d5fc --- /dev/null +++ b/delivery_carrier_max_weight_constraint/views/res_config_settings_views.xml @@ -0,0 +1,22 @@ + + + + res.config.settings.view.form (in delivery_carrier_max_weight_constraint) + + res.config.settings + + + + + + + + + + diff --git a/delivery_carrier_max_weight_constraint/views/stock_package_type_views.xml b/delivery_carrier_max_weight_constraint/views/stock_package_type_views.xml new file mode 100644 index 0000000000..1e567bad57 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/views/stock_package_type_views.xml @@ -0,0 +1,20 @@ + + + + + stock.package.type.form.delivery (in delivery_carrier_max_weight_constraint) + stock.package.type + + + + + + + + + diff --git a/delivery_carrier_max_weight_constraint/wizards/__init__.py b/delivery_carrier_max_weight_constraint/wizards/__init__.py new file mode 100644 index 0000000000..2a7c69f0da --- /dev/null +++ b/delivery_carrier_max_weight_constraint/wizards/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import choose_delivery_package diff --git a/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py b/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py new file mode 100644 index 0000000000..7055cef186 --- /dev/null +++ b/delivery_carrier_max_weight_constraint/wizards/choose_delivery_package.py @@ -0,0 +1,25 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class ChooseDeliveryPackage(models.TransientModel): + _inherit = "choose.delivery.package" + + @api.constrains("delivery_package_type_id", "shipping_weight") + def _check_strict_weight_package(self): + for package in self: + if ( + package.delivery_package_type_id.is_strict_weight + and package.delivery_package_type_id.max_weight + and package.shipping_weight + > package.delivery_package_type_id.max_weight + ): + error_msg = _( + "The weight of your package is higher than the maximum " + "weight authorized for this package type. Please choose " + "another package type." + ) + raise ValidationError(error_msg)