[IMP] purchase: add reminder mail tests

Test the reminder mail can be correctly send.

Task 2265912
PR #52693
This commit is contained in:
yhu-odoo
2020-06-09 13:59:27 +00:00
parent ccfc54113d
commit f48aad5944
+66 -1
View File
@@ -3,6 +3,7 @@
from datetime import timedelta
from odoo import fields
from odoo.tests.common import SavepointCase
from odoo.tests import Form
@@ -19,7 +20,7 @@ class TestPurchase(SavepointCase):
'name': 'Product B',
'type': 'consu',
})
cls.vendor = cls.env['res.partner'].create({'name': 'vendor1'})
cls.vendor = cls.env['res.partner'].create({'name': 'vendor1', 'email': 'vendor1@test.com'})
cls.uom_unit = cls.env.ref('uom.product_uom_unit')
def test_date_planned(self):
@@ -79,3 +80,67 @@ class TestPurchase(SavepointCase):
vals['date_order'] = '2019-12-31 23:30:00'
purchase_order = PurchaseOrder.with_context(tz='Europe/Brussels').create(vals.copy())
self.assertTrue(purchase_order.name.startswith('PO/2020/'))
def test_reminder_1(self):
"""Set to send reminder today, check if a reminder can be send to the
partner.
"""
po = Form(self.env['purchase.order'])
po.partner_id = self.vendor
with po.order_line.new() as po_line:
po_line.product_id = self.product_consu
po_line.product_qty = 1
po_line.price_unit = 100
with po.order_line.new() as po_line:
po_line.product_id = self.product_consu2
po_line.product_qty = 10
po_line.price_unit = 200
# set to send reminder today
po.date_planned = fields.Datetime.now() + timedelta(days=1)
po.receipt_reminder_email = True
po.reminder_date_before_receipt = 1
po = po.save()
po.button_confirm()
# check vendor is a message recipient
self.assertTrue(po.partner_id in po.message_partner_ids)
old_messages = po.message_ids
po._send_reminder_mail()
messages_send = po.message_ids - old_messages
# check reminder send
self.assertTrue(messages_send)
self.assertTrue(po.partner_id in messages_send.mapped('partner_ids'))
# check confirm button
po.confirm_reminder_mail()
self.assertTrue(po.mail_reminder_confirmed)
def test_reminder_2(self):
"""Set to send reminder tomorrow, check if no reminder can be send.
"""
po = Form(self.env['purchase.order'])
po.partner_id = self.vendor
with po.order_line.new() as po_line:
po_line.product_id = self.product_consu
po_line.product_qty = 1
po_line.price_unit = 100
with po.order_line.new() as po_line:
po_line.product_id = self.product_consu2
po_line.product_qty = 10
po_line.price_unit = 200
# set to send reminder tomorrow
po.date_planned = fields.Datetime.now() + timedelta(days=2)
po.receipt_reminder_email = True
po.reminder_date_before_receipt = 1
po = po.save()
po.button_confirm()
# check vendor is a message recipient
self.assertTrue(po.partner_id in po.message_partner_ids)
old_messages = po.message_ids
po._send_reminder_mail()
messages_send = po.message_ids - old_messages
# check no reminder send
self.assertFalse(messages_send)