Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#62876 [ADD] sale_order_type_email_template #369

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gitoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
branch: "14.0"
includes:
- sale_order_tag
- sale_order_type
- sale_order_partner_restrict
- sale_product_multi_add

Expand Down
35 changes: 35 additions & 0 deletions sale_order_type_email_template/README.rst
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions sale_order_type_email_template/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Check notice on line 4 in sale_order_type_email_template/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sale_order_type_email_template/__init__.py#L4

'.models' imported but unused (F401)
20 changes: 20 additions & 0 deletions sale_order_type_email_template/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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).

{

Check warning on line 4 in sale_order_type_email_template/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sale_order_type_email_template/__manifest__.py#L4

Statement seems to have no effect
"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,
}
49 changes: 49 additions & 0 deletions sale_order_type_email_template/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions sale_order_type_email_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Check notice on line 4 in sale_order_type_email_template/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sale_order_type_email_template/models/__init__.py#L4

'.sale_order_type' imported but unused (F401)
from . import sale

Check notice on line 5 in sale_order_type_email_template/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

sale_order_type_email_template/models/__init__.py#L5

'.sale' imported but unused (F401)
17 changes: 17 additions & 0 deletions sale_order_type_email_template/models/sale.py
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 10 additions & 0 deletions sale_order_type_email_template/models/sale_order_type.py
Original file line number Diff line number Diff line change
@@ -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")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions sale_order_type_email_template/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
)
15 changes: 15 additions & 0 deletions sale_order_type_email_template/views/sale_order_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="sot_sale_order_type_form_view_inherit" model="ir.ui.view">
<field name="name">Sale Order Type Form: add mail template</field>
<field name="model">sale.order.type</field>
<field name="inherit_id" ref="sale_order_type.sot_sale_order_type_form_view"/>
<field name="arch" type="xml">
<field name="sequence_id" position="after">
<field name="mail_template"/>
</field>
</field>
</record>

</odoo>
Loading