summaryrefslogtreecommitdiff
path: root/addons/product_email_template/tests
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/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/product_email_template/tests')
-rw-r--r--addons/product_email_template/tests/__init__.py3
-rw-r--r--addons/product_email_template/tests/test_account_move.py70
2 files changed, 73 insertions, 0 deletions
diff --git a/addons/product_email_template/tests/__init__.py b/addons/product_email_template/tests/__init__.py
new file mode 100644
index 00000000..e2899d2c
--- /dev/null
+++ b/addons/product_email_template/tests/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import test_account_move
diff --git a/addons/product_email_template/tests/test_account_move.py b/addons/product_email_template/tests/test_account_move.py
new file mode 100644
index 00000000..4ed7833f
--- /dev/null
+++ b/addons/product_email_template/tests/test_account_move.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
+from odoo.tests import tagged
+
+@tagged('post_install', '-at_install')
+class TestAccountMove(AccountTestInvoicingCommon):
+ def setUp(self):
+ super().setUp()
+ Template = self.env['mail.template']
+ self.template = Template.create({
+ 'name': 'Product Template',
+ 'subject': 'YOUR PRODUCT',
+ 'model_id': self.env['ir.model']._get_id('product.template')
+ })
+ self.customer = self.env['res.partner'].create({
+ 'name': 'James Bond',
+ 'email': 'james.bond@yopmail.com'
+ })
+ self.product_a.email_template_id = self.template.id
+
+ def test_send_product_template_email_on_invoice_post(self):
+ id_max = self.env['mail.message'].search([], order='id desc', limit=1)
+ if id_max:
+ id_max = id_max[0].id
+ else:
+ id_max = 0
+ invoice = self.env['account.move'].create({
+ 'move_type': 'out_invoice',
+ 'partner_id': self.customer.id,
+ 'invoice_line_ids': [(0, 0, {
+ 'name': 'Walter PPK',
+ 'quantity': 1,
+ 'price_unit': 123,
+ 'product_id': self.product_a.id
+ })]
+ })
+ invoice.action_post()
+ message_sent = self.env['mail.message'].search([('id', '>', id_max), ('subject', '=', 'YOUR PRODUCT')])
+ self.assertEqual(len(message_sent), 1, 'Should send 1 message for product')
+ self.assertTrue(message_sent[0].email_from, 'Should have from email address')
+
+ def test_send_as_system_when_sudo(self):
+ """
+ Test scenario of a product ordered through the portal.
+ """
+ id_max = self.env['mail.message'].search([], order='id desc', limit=1)
+ if id_max:
+ id_max = id_max[0].id
+ else:
+ id_max = 0
+ invoice = self.env['account.move'].create({
+ 'move_type': 'out_invoice',
+ 'partner_id': self.customer.id,
+ 'invoice_line_ids': [(0, 0, {
+ 'name': 'Walter PPK',
+ 'quantity': 1,
+ 'price_unit': 123,
+ 'product_id': self.product_a.id
+ })]
+ })
+ pub_user = self.env['res.users'].create({
+ 'login': 'test_public_user',
+ 'name': 'test_public_user',
+ 'email': False,
+ 'groups_id': [(6, 0, [self.env.ref('base.group_public').id])]
+ })
+ invoice.with_user(pub_user).sudo().action_post()
+ message_sent = self.env['mail.message'].search([('id', '>', id_max), ('subject', '=', 'YOUR PRODUCT')])
+ self.assertEqual(len(message_sent), 1, 'Should send 1 message for product')
+ self.assertTrue(message_sent[0].email_from, 'Should have from email address')