From f48aad5944e0a8516efc838eb31ce1d79079687f Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Tue, 2 Jun 2020 21:22:28 +0000 Subject: [PATCH] [IMP] purchase: add reminder mail tests Test the reminder mail can be correctly send. Task 2265912 PR #52693 --- addons/purchase/tests/test_purchase.py | 67 +++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/addons/purchase/tests/test_purchase.py b/addons/purchase/tests/test_purchase.py index dae88ecf0d9..19734a815fa 100644 --- a/addons/purchase/tests/test_purchase.py +++ b/addons/purchase/tests/test_purchase.py @@ -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)