From fb13d2f6a12801a6ac01147c8236cabc0db73594 Mon Sep 17 00:00:00 2001 From: shariquerik Date: Thu, 26 Aug 2021 01:14:39 +0530 Subject: [PATCH 1/3] fix: Reloading doc before Setting Property After Alert --- frappe/email/doctype/notification/notification.py | 1 + 1 file changed, 1 insertion(+) diff --git a/frappe/email/doctype/notification/notification.py b/frappe/email/doctype/notification/notification.py index 57418515f5..b93cdc16fc 100644 --- a/frappe/email/doctype/notification/notification.py +++ b/frappe/email/doctype/notification/notification.py @@ -146,6 +146,7 @@ def get_context(context): if doc.meta.get_field(fieldname).fieldtype in frappe.model.numeric_fieldtypes: value = frappe.utils.cint(value) + doc.reload() doc.set(fieldname, value) doc.flags.updater_reference = { 'doctype': self.doctype, From 0fc092a98e8c46e8b58cb1638ab8b7cc2cb494d9 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Tue, 31 Aug 2021 18:33:32 +0530 Subject: [PATCH 2/3] test: Added test to check change in property value after alert --- .../doctype/notification/test_notification.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frappe/email/doctype/notification/test_notification.py b/frappe/email/doctype/notification/test_notification.py index 2629050c1b..716daa0f7b 100644 --- a/frappe/email/doctype/notification/test_notification.py +++ b/frappe/email/doctype/notification/test_notification.py @@ -20,6 +20,8 @@ class TestNotification(unittest.TestCase): notification.event = 'Value Change' notification.value_changed = 'status' notification.send_to_all_assignees = 1 + notification.set_property_after_alert = 'description' + notification.property_value = 'Changed by Notification' notification.save() if not frappe.db.exists('Notification', {'name': 'Contact Status Update'}, 'name'): @@ -269,4 +271,19 @@ class TestNotification(unittest.TestCase): self.assertTrue('test2@example.com' in recipients) self.assertTrue('test1@example.com' in recipients) + def test_change_property_value_after_alert(self): + todo = frappe.new_doc('ToDo') + todo.description = 'Test Property Change after Alert' + todo.save() + + #change status of todo + todo.status = 'Closed' + todo.save() + + email_queue = frappe.get_doc('Email Queue', {'reference_doctype': 'ToDo', + 'reference_name': todo.name}) + + self.assertTrue(email_queue) + self.assertEquals(todo.description, 'Changed by Notification') + From a27db796f9fb15e3b8eda6d2dd1a0d591755d447 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 1 Sep 2021 15:33:23 +0530 Subject: [PATCH 3/3] test: minor fix --- .../doctype/notification/test_notification.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/frappe/email/doctype/notification/test_notification.py b/frappe/email/doctype/notification/test_notification.py index 716daa0f7b..803113e8ea 100644 --- a/frappe/email/doctype/notification/test_notification.py +++ b/frappe/email/doctype/notification/test_notification.py @@ -239,6 +239,9 @@ class TestNotification(unittest.TestCase): self.assertTrue(email_queue) + # check if description is changed after alert since set_property_after_alert is set + self.assertEquals(todo.description, 'Changed by Notification') + recipients = [d.recipient for d in email_queue.recipients] self.assertTrue('test2@example.com' in recipients) self.assertTrue('test1@example.com' in recipients) @@ -271,19 +274,4 @@ class TestNotification(unittest.TestCase): self.assertTrue('test2@example.com' in recipients) self.assertTrue('test1@example.com' in recipients) - def test_change_property_value_after_alert(self): - todo = frappe.new_doc('ToDo') - todo.description = 'Test Property Change after Alert' - todo.save() - - #change status of todo - todo.status = 'Closed' - todo.save() - - email_queue = frappe.get_doc('Email Queue', {'reference_doctype': 'ToDo', - 'reference_name': todo.name}) - - self.assertTrue(email_queue) - self.assertEquals(todo.description, 'Changed by Notification') -