diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index ae9f1115..2a6da6a4 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -49,6 +49,7 @@ "sale_order_margin_percent", "sale_order_partner_restrict_affiliates", "sale_order_portal_hide_invoices", + "sale_order_type_email_template", "sale_order_url_tracking", "sale_order_weight", "sale_partner_authorized_company", diff --git a/Dockerfile b/Dockerfile index cf6c2b37..a4b243b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,6 +54,7 @@ COPY sale_order_line_readonly_conditions /mnt/extra-addons/sale_order_line_reado COPY sale_order_margin_percent /mnt/extra-addons/sale_order_margin_percent COPY sale_order_partner_restrict_affiliates /mnt/extra-addons/sale_order_partner_restrict_affiliates COPY sale_order_portal_hide_invoices /mnt/extra-addons/sale_order_portal_hide_invoices +COPY sale_order_type_email_template /mnt/extra-addons/sale_order_type_email_template COPY sale_order_url_tracking /mnt/extra-addons/sale_order_url_tracking COPY sale_order_weight /mnt/extra-addons/sale_order_weight COPY sale_partner_authorized_company /mnt/extra-addons/sale_partner_authorized_company diff --git a/gitoo.yml b/gitoo.yml index dfb77ba0..2ada24ff 100644 --- a/gitoo.yml +++ b/gitoo.yml @@ -99,6 +99,7 @@ branch: "14.0" includes: - sale_order_tag + - sale_order_type - sale_order_partner_restrict - sale_product_multi_add diff --git a/sale_order_type_email_template/README.rst b/sale_order_type_email_template/README.rst new file mode 100644 index 00000000..8c4c0735 --- /dev/null +++ b/sale_order_type_email_template/README.rst @@ -0,0 +1,35 @@ +Sale Order Type Email Template +============================== +This module allows to sent different email template based on the sale order type. + +Usage +----- +*Configuration* +As a user with access to email templates, I create an email template per order type. + +.. image:: static/description/email_templates_list.png + +I configure a Qweb report to use (or using Aeroo report). + +.. image:: static/description/template_with_qweb_report.png + +As a sales administrator, I access order types from the `Sales > Configuration > Sale Order Types` menu. +From the form view, I see that a new `Email Template` field is available. + +.. image:: static/description/sale_order_type.png + +For each type of order, I define the email template to use. + +*Use Case* +As a sales user, I create a quotation. +Then, I select the type of quotation, then I send it by email by clicking on the `Send by Email` button. + +.. image:: static/description/sale_order_form_view.png + +I see that the appropriate email template is chosen as well as the PDF report: + +.. image:: static/description/template_for_email.png + +Contributors +------------ +* Numigi (tm) and all its contributors (https://bit.ly/numigiens) diff --git a/sale_order_type_email_template/__init__.py b/sale_order_type_email_template/__init__.py new file mode 100644 index 00000000..01e87973 --- /dev/null +++ b/sale_order_type_email_template/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_order_type_email_template/__manifest__.py b/sale_order_type_email_template/__manifest__.py new file mode 100644 index 00000000..cc40302c --- /dev/null +++ b/sale_order_type_email_template/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Sale Order Type Email Template", + "version": "1.0.0", + "author": "Numigi", + "maintainer": "Numigi", + "website": "https://bit.ly/numigi-com", + "license": "AGPL-3", + "category": "Sale", + "depends": [ + "sale_order_type", + ], + "summary": "Sends different email template based on the sale order type.", + "data": [ + "views/sale_order_type_views.xml", + ], + "installable": True, +} diff --git a/sale_order_type_email_template/i18n/fr.po b/sale_order_type_email_template/i18n/fr.po new file mode 100644 index 00000000..22869ed9 --- /dev/null +++ b/sale_order_type_email_template/i18n/fr.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_type_email_template +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-04-11 15:22+0000\n" +"PO-Revision-Date: 2024-04-11 15:22+0000\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_order_type_email_template +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order__display_name +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order_type__display_name +msgid "Display Name" +msgstr "Afficher le nom" + +#. module: sale_order_type_email_template +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order_type__mail_template +msgid "Email Template" +msgstr "Modèle de courriel" + +#. module: sale_order_type_email_template +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order__id +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order_type__id +msgid "ID" +msgstr "" + +#. module: sale_order_type_email_template +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order____last_update +#: model:ir.model.fields,field_description:sale_order_type_email_template.field_sale_order_type____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: sale_order_type_email_template +#: model:ir.model,name:sale_order_type_email_template.model_sale_order +msgid "Sales Order" +msgstr "Bon de commande" + +#. module: sale_order_type_email_template +#: model:ir.model,name:sale_order_type_email_template.model_sale_order_type +msgid "Type of sale order" +msgstr "Type de bon de commande" \ No newline at end of file diff --git a/sale_order_type_email_template/models/__init__.py b/sale_order_type_email_template/models/__init__.py new file mode 100644 index 00000000..76988056 --- /dev/null +++ b/sale_order_type_email_template/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import sale_order_type +from . import sale diff --git a/sale_order_type_email_template/models/sale.py b/sale_order_type_email_template/models/sale.py new file mode 100644 index 00000000..79bc72cb --- /dev/null +++ b/sale_order_type_email_template/models/sale.py @@ -0,0 +1,17 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _find_mail_template(self, force_confirmation_template=False): + self.ensure_one() + if (self.type_id and self.type_id.mail_template + and not force_confirmation_template): + return self.type_id.mail_template.id + return super(SaleOrder, self)._find_mail_template( + force_confirmation_template=force_confirmation_template + ) diff --git a/sale_order_type_email_template/models/sale_order_type.py b/sale_order_type_email_template/models/sale_order_type.py new file mode 100644 index 00000000..b58a09eb --- /dev/null +++ b/sale_order_type_email_template/models/sale_order_type.py @@ -0,0 +1,10 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class SaleOrderTypology(models.Model): + _inherit = "sale.order.type" + + mail_template = fields.Many2one("mail.template", "Email Template") diff --git a/sale_order_type_email_template/static/description/email_templates_list.png b/sale_order_type_email_template/static/description/email_templates_list.png new file mode 100644 index 00000000..c1a4a5da Binary files /dev/null and b/sale_order_type_email_template/static/description/email_templates_list.png differ diff --git a/sale_order_type_email_template/static/description/icon.png b/sale_order_type_email_template/static/description/icon.png new file mode 100644 index 00000000..92a86b10 Binary files /dev/null and b/sale_order_type_email_template/static/description/icon.png differ diff --git a/sale_order_type_email_template/static/description/sale_order_form_view.png b/sale_order_type_email_template/static/description/sale_order_form_view.png new file mode 100644 index 00000000..66e7b9c0 Binary files /dev/null and b/sale_order_type_email_template/static/description/sale_order_form_view.png differ diff --git a/sale_order_type_email_template/static/description/sale_order_type.png b/sale_order_type_email_template/static/description/sale_order_type.png new file mode 100644 index 00000000..1ec135e1 Binary files /dev/null and b/sale_order_type_email_template/static/description/sale_order_type.png differ diff --git a/sale_order_type_email_template/static/description/template_for_email.png b/sale_order_type_email_template/static/description/template_for_email.png new file mode 100644 index 00000000..adbc0a6b Binary files /dev/null and b/sale_order_type_email_template/static/description/template_for_email.png differ diff --git a/sale_order_type_email_template/static/description/template_with_qweb_report.png b/sale_order_type_email_template/static/description/template_with_qweb_report.png new file mode 100644 index 00000000..2c359739 Binary files /dev/null and b/sale_order_type_email_template/static/description/template_with_qweb_report.png differ diff --git a/sale_order_type_email_template/tests/__init__.py b/sale_order_type_email_template/tests/__init__.py new file mode 100644 index 00000000..68a168e2 --- /dev/null +++ b/sale_order_type_email_template/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_sale_order_type_template diff --git a/sale_order_type_email_template/tests/test_sale_order_type_template.py b/sale_order_type_email_template/tests/test_sale_order_type_template.py new file mode 100644 index 00000000..2adc368a --- /dev/null +++ b/sale_order_type_email_template/tests/test_sale_order_type_template.py @@ -0,0 +1,37 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.sale_order_type.tests.test_sale_order_type import TestSaleOrderType +from odoo.tests import tagged + + +@tagged("post_install") +class TestSaleOrderTypeTemplate(TestSaleOrderType): + def setUp(self): + super(TestSaleOrderTypeTemplate, self).setUp() + values = { + "name": "My Template", + "subject": "My Subject", + "body_html": "Template Body", + "model_id": self.env.ref("sale.model_sale_order").id, + "use_default_to": True, + } + self.template = self.env["mail.template"].create(values) + + def test_action_quotation_send_right_email_template(self): + """ + Test that the right email template is used when sending a quotation. + """ + order = self.create_sale_order() + self.sale_type_route.mail_template = self.template.id + order.type_id = self.sale_type_route.id + order.onchange_type_id() + action = order.action_quotation_send() + self.assertEqual( + action["context"]["default_use_template"], + bool(order.type_id.mail_template.id), + ) + self.assertEqual( + action["context"]["default_template_id"], + order.type_id.mail_template.id, + ) diff --git a/sale_order_type_email_template/views/sale_order_type_views.xml b/sale_order_type_email_template/views/sale_order_type_views.xml new file mode 100644 index 00000000..b4691e91 --- /dev/null +++ b/sale_order_type_email_template/views/sale_order_type_views.xml @@ -0,0 +1,15 @@ + + + + + Sale Order Type Form: add mail template + sale.order.type + + + + + + + + + \ No newline at end of file