diff --git a/sale_product_email/README.rst b/sale_product_email/README.rst new file mode 100644 index 00000000000..cb5c44f9353 --- /dev/null +++ b/sale_product_email/README.rst @@ -0,0 +1,101 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================== +Sale product email +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:543561d513d5b13661ca3257405c8cc5a94ae0e9259c84c1b9c4141df5a02618 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/16.0/sale_product_email + :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-16-0/sale-workflow-16-0-sale_product_email + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds an optional email template to products. +When a sale is confirmed, a single mail will be sent for each product with the mail template set in the 'Sale confirmation email' (`sale_confirmation_mail_template_id`) field. + +This module differs from `product_email_template`, as it sends a mail when an invoice is posted, whereas this module sends a mail when a sale order is confirmed. +As such, depending on your workflow, you may pick either module for the email timing you require. +For instance, if a sale order leads to a contract which generates invoices recurrently, you may prefer to only send a mail when the sale order is confirmed. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +How to use this module : + +1. Create an Email template for the Sale Order (`sale.order`) model. +2. Edit a product, then go into the 'Sales' notebook tab. +3. In the 'Sale confirmation email' field, select your newly created email template. + +Afterwards, when this product is present in a confirmed sale, a mail based on the configured template will be sent. + +.. image:: https://raw.githubusercontent.com/sale_product_email/static/description/mail_template_select.png + :alt: Mail template selection on a Product + +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 +~~~~~~~ + +* Commown SCIC +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Florent Cayré +* Chafique Delli + +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/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_product_email/__init__.py b/sale_product_email/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/sale_product_email/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_product_email/__manifest__.py b/sale_product_email/__manifest__.py new file mode 100644 index 00000000000..eb5a3b6206e --- /dev/null +++ b/sale_product_email/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2022-today Commown SCIC (https://commown.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Sale product email", + "category": "Sales", + "summary": "Send a product-specific email to its buyers", + "version": "16.0.1.0.0", + "author": "Commown SCIC, Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/sale-workflow", + "data": [ + "views/product_template.xml", + ], + "depends": [ + "sale", + ], + "installable": True, +} diff --git a/sale_product_email/models/__init__.py b/sale_product_email/models/__init__.py new file mode 100644 index 00000000000..b48bb2dda30 --- /dev/null +++ b/sale_product_email/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_template +from . import sale_order diff --git a/sale_product_email/models/product_template.py b/sale_product_email/models/product_template.py new file mode 100644 index 00000000000..9f8c3bf65ff --- /dev/null +++ b/sale_product_email/models/product_template.py @@ -0,0 +1,17 @@ +# Copyright 2022-today Commown SCIC (https://commown.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + sale_confirmation_mail_template_id = fields.Many2one( + "mail.template", + string="Sale confirmation email", + domain=lambda self: [ + ("model_id", "=", self.env.ref("sale.model_sale_order").id), + ], + help=("If set, this email will be sent to the buyer on sale" " confirmation"), + ) diff --git a/sale_product_email/models/sale_order.py b/sale_product_email/models/sale_order.py new file mode 100644 index 00000000000..0a94c8b5d0c --- /dev/null +++ b/sale_product_email/models/sale_order.py @@ -0,0 +1,26 @@ +# Copyright 2022-today Commown SCIC (https://commown.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def action_confirm(self): + res = super().action_confirm() + self.send_sold_products_mail() + return res + + def send_sold_products_mail(self): + for order in self: + for line in order.order_line: + product_tmpl = line.product_id.product_tmpl_id + mail_template = product_tmpl.sale_confirmation_mail_template_id + if mail_template: + order.with_context( + product_tmpl=product_tmpl, + default_composition_mode="comment", + default_partner_ids=order.partner_id.ids, + custom_layout="sale.email_template_edi_sale", + ).message_post_with_template(mail_template.id) diff --git a/sale_product_email/readme/CONTRIBUTORS.rst b/sale_product_email/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..600cd70105f --- /dev/null +++ b/sale_product_email/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Florent Cayré +* Chafique Delli diff --git a/sale_product_email/readme/DESCRIPTION.rst b/sale_product_email/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..43601623d5d --- /dev/null +++ b/sale_product_email/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +This module adds an optional email template to products. +When a sale is confirmed, a single mail will be sent for each product with the mail template set in the 'Sale confirmation email' (`sale_confirmation_mail_template_id`) field. + +This module differs from `product_email_template`, as it sends a mail when an invoice is posted, whereas this module sends a mail when a sale order is confirmed. +As such, depending on your workflow, you may pick either module for the email timing you require. +For instance, if a sale order leads to a contract which generates invoices recurrently, you may prefer to only send a mail when the sale order is confirmed. diff --git a/sale_product_email/readme/USAGE.rst b/sale_product_email/readme/USAGE.rst new file mode 100644 index 00000000000..6766a678882 --- /dev/null +++ b/sale_product_email/readme/USAGE.rst @@ -0,0 +1,10 @@ +How to use this module : + +1. Create an Email template for the Sale Order (`sale.order`) model. +2. Edit a product, then go into the 'Sales' notebook tab. +3. In the 'Sale confirmation email' field, select your newly created email template. + +Afterwards, when this product is present in a confirmed sale, a mail based on the configured template will be sent. + +.. image:: /sale_product_email/static/description/mail_template_select.png + :alt: Mail template selection on a Product diff --git a/sale_product_email/static/description/index.html b/sale_product_email/static/description/index.html new file mode 100644 index 00000000000..e7a5bb29613 --- /dev/null +++ b/sale_product_email/static/description/index.html @@ -0,0 +1,447 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale product email

+ +

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

+

This module adds an optional email template to products. +When a sale is confirmed, a single mail will be sent for each product with the mail template set in the ‘Sale confirmation email’ (sale_confirmation_mail_template_id) field.

+

This module differs from product_email_template, as it sends a mail when an invoice is posted, whereas this module sends a mail when a sale order is confirmed. +As such, depending on your workflow, you may pick either module for the email timing you require. +For instance, if a sale order leads to a contract which generates invoices recurrently, you may prefer to only send a mail when the sale order is confirmed.

+

Table of contents

+ +
+

Usage

+

How to use this module :

+
    +
  1. Create an Email template for the Sale Order (sale.order) model.
  2. +
  3. Edit a product, then go into the ‘Sales’ notebook tab.
  4. +
  5. In the ‘Sale confirmation email’ field, select your newly created email template.
  6. +
+

Afterwards, when this product is present in a confirmed sale, a mail based on the configured template will be sent.

+Mail template selection on a Product +
+
+

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

+
    +
  • Commown SCIC
  • +
  • Akretion
  • +
+
+
+

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/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_product_email/static/description/mail_template_select.png b/sale_product_email/static/description/mail_template_select.png new file mode 100644 index 00000000000..4121644e8b5 Binary files /dev/null and b/sale_product_email/static/description/mail_template_select.png differ diff --git a/sale_product_email/tests/__init__.py b/sale_product_email/tests/__init__.py new file mode 100644 index 00000000000..58aeff6de6c --- /dev/null +++ b/sale_product_email/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_product_email diff --git a/sale_product_email/tests/test_sale_product_email.py b/sale_product_email/tests/test_sale_product_email.py new file mode 100644 index 00000000000..df1afce3b0e --- /dev/null +++ b/sale_product_email/tests/test_sale_product_email.py @@ -0,0 +1,35 @@ +# Copyright 2022-today Commown SCIC (https://commown.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestSaleProductEmail(TransactionCase): + + test_email_subject = "Test product email template" + + @classmethod + def setUpClass(cls): + super(TestSaleProductEmail, cls).setUpClass() + cls.product_25 = cls.env.ref("product.product_product_25") + mail_template = cls.env.ref("sale.email_template_edi_sale").copy( + { + "subject": cls.test_email_subject, + } + ) + cls.product_25.product_tmpl_id.write( + {"sale_confirmation_mail_template_id": mail_template.id} + ) + cls.sale_order_1 = cls.env.ref("sale.sale_order_1") + + def _product_messages(self): + return self.sale_order_1.message_ids.filtered( + lambda m: m.subject == self.test_email_subject + ) + + def test_send_sold_products_mail(self): + self.assertFalse(self._product_messages()) + self.sale_order_1.action_confirm() + messages = self._product_messages() + self.assertEqual(len(messages), 1) + self.assertIn(self.sale_order_1.partner_id, messages.partner_ids) diff --git a/sale_product_email/views/product_template.xml b/sale_product_email/views/product_template.xml new file mode 100644 index 00000000000..795d270cd77 --- /dev/null +++ b/sale_product_email/views/product_template.xml @@ -0,0 +1,14 @@ + + + + product.template + + + + + + + + + + diff --git a/setup/sale_product_email/odoo/addons/sale_product_email b/setup/sale_product_email/odoo/addons/sale_product_email new file mode 120000 index 00000000000..b5df777671c --- /dev/null +++ b/setup/sale_product_email/odoo/addons/sale_product_email @@ -0,0 +1 @@ +../../../../sale_product_email \ No newline at end of file diff --git a/setup/sale_product_email/setup.py b/setup/sale_product_email/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/sale_product_email/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)