diff --git a/sale_exception_holidays_public/README.rst b/sale_exception_holidays_public/README.rst new file mode 100644 index 00000000000..4f20f69c48c --- /dev/null +++ b/sale_exception_holidays_public/README.rst @@ -0,0 +1,107 @@ +============================== +Sale Exception Public Holidays +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:445676e17493ecef7eb2113db9b37cf038599660e7caad248ac266e86e0b9f8a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/18.0/sale_exception_holidays_public + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_exception_holidays_public + :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/sale-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module raises a sale exception if there is a commitment_date on the +SO and this date is a public holidays for the shipping partner address. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +1. Go to *Settings > Technical > Exception Rules*. +2. Activate the rule *Delivery Date is a public holiday*. + +Usage +===== + +1. Go to *Sales > Orders > Quotations* +2. Create a new quotation. +3. Set Delivery Date on a public holiday. +4. Confirm the order. +5. An exception will be displayed. + +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 +* BCIM + +Contributors +------------ + +- Nguyen Minh Chien + +Other credits +------------- + +The creation of this module to 16.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. + +.. |maintainer-jbaudoux| image:: https://github.com/jbaudoux.png?size=40px + :target: https://github.com/jbaudoux + :alt: jbaudoux + +Current `maintainer `__: + +|maintainer-jbaudoux| + +This module is part of the `OCA/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_exception_holidays_public/__init__.py b/sale_exception_holidays_public/__init__.py new file mode 100644 index 00000000000..7b3b84b7183 --- /dev/null +++ b/sale_exception_holidays_public/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from . import models diff --git a/sale_exception_holidays_public/__manifest__.py b/sale_exception_holidays_public/__manifest__.py new file mode 100644 index 00000000000..a8035c30a43 --- /dev/null +++ b/sale_exception_holidays_public/__manifest__.py @@ -0,0 +1,16 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Sale Exception Public Holidays", + "summary": """Raise a sale exception if there is a commitment_date on + the SO and this date is a public holidays for the shipping partner address""", + "version": "18.0.1.0.0", + "category": "Generic Modules/Sale", + "author": "Camptocamp, BCIM, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/sale-workflow", + "maintainers": ["jbaudoux"], + "depends": ["sale_exception", "hr_holidays_public"], + "license": "AGPL-3", + "data": [ + "data/sale_exception_data.xml", + ], +} diff --git a/sale_exception_holidays_public/data/sale_exception_data.xml b/sale_exception_holidays_public/data/sale_exception_data.xml new file mode 100644 index 00000000000..81a74c9eec5 --- /dev/null +++ b/sale_exception_holidays_public/data/sale_exception_data.xml @@ -0,0 +1,12 @@ + + + + + Delivery Date is a public holiday + Delivery Date is a public holiday + 100 + sale.order + failed=not self.check_commitment_date() + + + diff --git a/sale_exception_holidays_public/i18n/es.po b/sale_exception_holidays_public/i18n/es.po new file mode 100644 index 00000000000..a695a6bcb49 --- /dev/null +++ b/sale_exception_holidays_public/i18n/es.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_holidays_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-18 20:10+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: sale_exception_holidays_public +#: model:exception.rule,description:sale_exception_holidays_public.excep_commit_on_public_holiday +#: model:exception.rule,name:sale_exception_holidays_public.excep_commit_on_public_holiday +msgid "Delivery Date is a public holiday" +msgstr "La fecha de entrega es un día festivo" + +#. module: sale_exception_holidays_public +#: model:ir.model,name:sale_exception_holidays_public.model_sale_order +msgid "Sales Order" +msgstr "Orden de Venta" diff --git a/sale_exception_holidays_public/i18n/fr.po b/sale_exception_holidays_public/i18n/fr.po new file mode 100644 index 00000000000..4b25271d9a9 --- /dev/null +++ b/sale_exception_holidays_public/i18n/fr.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_holidays_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-12-31 15:06+0000\n" +"Last-Translator: samibc2c \n" +"Language-Team: none\n" +"Language: fr\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: sale_exception_holidays_public +#: model:exception.rule,description:sale_exception_holidays_public.excep_commit_on_public_holiday +#: model:exception.rule,name:sale_exception_holidays_public.excep_commit_on_public_holiday +msgid "Delivery Date is a public holiday" +msgstr "La date de livraison est un jour férié" + +#. module: sale_exception_holidays_public +#: model:ir.model,name:sale_exception_holidays_public.model_sale_order +msgid "Sales Order" +msgstr "Commandes de vente" diff --git a/sale_exception_holidays_public/i18n/it.po b/sale_exception_holidays_public/i18n/it.po new file mode 100644 index 00000000000..4efbe9eb944 --- /dev/null +++ b/sale_exception_holidays_public/i18n/it.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_holidays_public +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-07 18:33+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 4.17\n" + +#. module: sale_exception_holidays_public +#: model:exception.rule,description:sale_exception_holidays_public.excep_commit_on_public_holiday +#: model:exception.rule,name:sale_exception_holidays_public.excep_commit_on_public_holiday +msgid "Delivery Date is a public holiday" +msgstr "La data di consegna è una festività" + +#. module: sale_exception_holidays_public +#: model:ir.model,name:sale_exception_holidays_public.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" diff --git a/sale_exception_holidays_public/i18n/sale_exception_holidays_public.pot b/sale_exception_holidays_public/i18n/sale_exception_holidays_public.pot new file mode 100644 index 00000000000..6c175d97686 --- /dev/null +++ b/sale_exception_holidays_public/i18n/sale_exception_holidays_public.pot @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_exception_holidays_public +# +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: sale_exception_holidays_public +#: model:exception.rule,description:sale_exception_holidays_public.excep_commit_on_public_holiday +#: model:exception.rule,name:sale_exception_holidays_public.excep_commit_on_public_holiday +msgid "Delivery Date is a public holiday" +msgstr "" + +#. module: sale_exception_holidays_public +#: model:ir.model,name:sale_exception_holidays_public.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/sale_exception_holidays_public/models/__init__.py b/sale_exception_holidays_public/models/__init__.py new file mode 100644 index 00000000000..06868d6f45a --- /dev/null +++ b/sale_exception_holidays_public/models/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from . import sale_order diff --git a/sale_exception_holidays_public/models/sale_order.py b/sale_exception_holidays_public/models/sale_order.py new file mode 100644 index 00000000000..cb85204b167 --- /dev/null +++ b/sale_exception_holidays_public/models/sale_order.py @@ -0,0 +1,42 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _is_commitment_date_a_public_holiday(self): + """ + Returns True if commitment_date is a public holiday + :return: bool + """ + self.ensure_one() + if not self.commitment_date: + return False + commitment_date = fields.Datetime.context_timestamp( + self, self.commitment_date + ).date() + partner = self.partner_shipping_id or self.partner_id + domain = [ + ("public_holiday_id.country_id", "in", (False, partner.country_id.id)), + "|", + ("state_ids", "=", False), + ("state_ids", "=", partner.state_id.id), + ("date", "=", commitment_date), + ] + hhplo = self.env["calendar.public.holiday.line"] + holidays_line = hhplo.search(domain, limit=1, order="id") + return bool(holidays_line) + + def check_commitment_date(self): + """ + Returns True if the check is ok + :return: bool + """ + return not self._is_commitment_date_a_public_holiday() + + def _fields_trigger_check_exception(self): + res = super()._fields_trigger_check_exception() + res.append("commitment_date") + return res diff --git a/sale_exception_holidays_public/pyproject.toml b/sale_exception_holidays_public/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/sale_exception_holidays_public/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_exception_holidays_public/readme/CONFIGURE.md b/sale_exception_holidays_public/readme/CONFIGURE.md new file mode 100644 index 00000000000..82d7d549b22 --- /dev/null +++ b/sale_exception_holidays_public/readme/CONFIGURE.md @@ -0,0 +1,2 @@ +1. Go to *Settings \> Technical \> Exception Rules*. +2. Activate the rule *Delivery Date is a public holiday*. diff --git a/sale_exception_holidays_public/readme/CONTRIBUTORS.md b/sale_exception_holidays_public/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..69ab8fce516 --- /dev/null +++ b/sale_exception_holidays_public/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Nguyen Minh Chien \ diff --git a/sale_exception_holidays_public/readme/CREDITS.md b/sale_exception_holidays_public/readme/CREDITS.md new file mode 100644 index 00000000000..f56144c70ae --- /dev/null +++ b/sale_exception_holidays_public/readme/CREDITS.md @@ -0,0 +1,2 @@ +The creation of this module to 16.0 was financially supported by +Camptocamp. diff --git a/sale_exception_holidays_public/readme/DESCRIPTION.md b/sale_exception_holidays_public/readme/DESCRIPTION.md new file mode 100644 index 00000000000..c13fa627201 --- /dev/null +++ b/sale_exception_holidays_public/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module raises a sale exception if there is a commitment_date on the +SO and this date is a public holidays for the shipping partner address. diff --git a/sale_exception_holidays_public/readme/USAGE.md b/sale_exception_holidays_public/readme/USAGE.md new file mode 100644 index 00000000000..1392d2bc634 --- /dev/null +++ b/sale_exception_holidays_public/readme/USAGE.md @@ -0,0 +1,5 @@ +1. Go to *Sales \> Orders \> Quotations* +2. Create a new quotation. +3. Set Delivery Date on a public holiday. +4. Confirm the order. +5. An exception will be displayed. diff --git a/sale_exception_holidays_public/static/description/icon.png b/sale_exception_holidays_public/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/sale_exception_holidays_public/static/description/icon.png differ diff --git a/sale_exception_holidays_public/static/description/index.html b/sale_exception_holidays_public/static/description/index.html new file mode 100644 index 00000000000..4d8cdaf4356 --- /dev/null +++ b/sale_exception_holidays_public/static/description/index.html @@ -0,0 +1,452 @@ + + + + + +Sale Exception Public Holidays + + + +
+

Sale Exception Public Holidays

+ + +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

This module raises a sale exception if there is a commitment_date on the +SO and this date is a public holidays for the shipping partner address.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Go to Settings > Technical > Exception Rules.
  2. +
  3. Activate the rule Delivery Date is a public holiday.
  4. +
+
+
+

Usage

+
    +
  1. Go to Sales > Orders > Quotations
  2. +
  3. Create a new quotation.
  4. +
  5. Set Delivery Date on a public holiday.
  6. +
  7. Confirm the order.
  8. +
  9. An exception will be displayed.
  10. +
+
+
+

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

Contributors

+ +
+
+

Other credits

+

The creation of this module to 16.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.

+

Current maintainer:

+

jbaudoux

+

This module is part of the OCA/sale-workflow project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_exception_holidays_public/tests/__init__.py b/sale_exception_holidays_public/tests/__init__.py new file mode 100644 index 00000000000..b375cf0128b --- /dev/null +++ b/sale_exception_holidays_public/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from . import test_sale_exception diff --git a/sale_exception_holidays_public/tests/test_sale_exception.py b/sale_exception_holidays_public/tests/test_sale_exception.py new file mode 100644 index 00000000000..5bb051e65ef --- /dev/null +++ b/sale_exception_holidays_public/tests/test_sale_exception.py @@ -0,0 +1,78 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from datetime import timedelta + +from odoo import Command, fields +from odoo.exceptions import ValidationError +from odoo.tests import TransactionCase + + +class TestSaleException(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.holiday_model = cls.env["calendar.public.holiday"] + cls.holiday_model_line = cls.env["calendar.public.holiday.line"] + + # Remove possibly existing public holidays that would interfer. + cls.holiday_model_line.search([]).unlink() + cls.holiday_model.search([]).unlink() + + # Create holidays + holiday_date = fields.Date.today() + timedelta(days=10) + holiday_1 = cls.holiday_model.create( + {"year": holiday_date.year, "country_id": cls.env.ref("base.sl").id} + ) + cls.holiday_model_line.create( + { + "name": "holiday 5", + "date": holiday_date, + "public_holiday_id": holiday_1.id, + } + ) + + cls.holiday_date = holiday_date + cls.holiday_1 = holiday_1 + + def test_sale_order_exception(self): + self.sale_exception_confirm = self.env["sale.exception.confirm"] + + exception = self.env.ref( + "sale_exception_holidays_public.excep_commit_on_public_holiday" + ) + exception.active = True + + partner = self.env.ref("base.res_partner_1") + p = self.env.ref("product.product_product_6") + so1 = self.env["sale.order"].create( + { + "partner_id": partner.id, + "partner_invoice_id": partner.id, + "partner_shipping_id": partner.id, + "order_line": [ + Command.create( + { + "name": p.name, + "product_id": p.id, + "product_uom_qty": 2, + "product_uom": p.uom_id.id, + "price_unit": p.list_price, + }, + ) + ], + } + ) + # Update freely without error + so1.commitment_date = self.holiday_date + so1.commitment_date = None + + # Update Delivery Date + self.holiday_1.country_id = None + so1.state = "sale" + with self.assertRaises(ValidationError): + so1.commitment_date = self.holiday_date + so1.state = "draft" + so1.commitment_date = self.holiday_date + so1.action_confirm() + self.assertTrue(so1.exceptions_summary)