summaryrefslogtreecommitdiff
path: root/addons/product_email_template/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/product_email_template/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/product_email_template/models')
-rw-r--r--addons/product_email_template/models/__init__.py4
-rw-r--r--addons/product_email_template/models/account_move.py31
-rw-r--r--addons/product_email_template/models/product.py16
3 files changed, 51 insertions, 0 deletions
diff --git a/addons/product_email_template/models/__init__.py b/addons/product_email_template/models/__init__.py
new file mode 100644
index 00000000..6e7344e1
--- /dev/null
+++ b/addons/product_email_template/models/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+
+from . import product
+from . import account_move \ No newline at end of file
diff --git a/addons/product_email_template/models/account_move.py b/addons/product_email_template/models/account_move.py
new file mode 100644
index 00000000..07039372
--- /dev/null
+++ b/addons/product_email_template/models/account_move.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from odoo import api, models, SUPERUSER_ID
+
+
+class AccountMove(models.Model):
+ _inherit = 'account.move'
+
+ def invoice_validate_send_email(self):
+ if self.env.su:
+ # sending mail in sudo was meant for it being sent from superuser
+ self = self.with_user(SUPERUSER_ID)
+ for invoice in self.filtered(lambda x: x.move_type == 'out_invoice'):
+ # send template only on customer invoice
+ # subscribe the partner to the invoice
+ if invoice.partner_id not in invoice.message_partner_ids:
+ invoice.message_subscribe([invoice.partner_id.id])
+ for line in invoice.invoice_line_ids:
+ if line.product_id.email_template_id:
+ invoice.message_post_with_template(
+ line.product_id.email_template_id.id,
+ composition_mode="comment",
+ email_layout_xmlid="mail.mail_notification_light"
+ )
+ return True
+
+ def _post(self, soft=True):
+ # OVERRIDE
+ posted = super()._post(soft)
+ posted.invoice_validate_send_email()
+ return posted
diff --git a/addons/product_email_template/models/product.py b/addons/product_email_template/models/product.py
new file mode 100644
index 00000000..e043717e
--- /dev/null
+++ b/addons/product_email_template/models/product.py
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+
+from odoo import fields, models
+
+
+class ProductTemplate(models.Model):
+ """ Product Template inheritance to add an optional email.template to a
+ product.template. When validating an invoice, an email will be send to the
+ customer based on this template. The customer will receive an email for each
+ product linked to an email template. """
+ _inherit = "product.template"
+
+ email_template_id = fields.Many2one('mail.template', string='Product Email Template',
+ help='When validating an invoice, an email will be sent to the customer '
+ 'based on this template. The customer will receive an email for each '
+ 'product linked to an email template.')