fix: events not deleted on cancelling maintenance schedule (#22954)
* feat: add participant to event_participant child table * feat: add tests * chore: update function name Co-authored-by: Marica <maricadsouza221197@gmail.com> Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
parent
d1b88af5b6
commit
d70e711aea
@ -67,16 +67,16 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
for key in scheduled_date:
|
||||
description =frappe._("Reference: {0}, Item Code: {1} and Customer: {2}").format(self.name, d.item_code, self.customer)
|
||||
frappe.get_doc({
|
||||
event = frappe.get_doc({
|
||||
"doctype": "Event",
|
||||
"owner": email_map.get(d.sales_person, self.owner),
|
||||
"subject": description,
|
||||
"description": description,
|
||||
"starts_on": cstr(key["scheduled_date"]) + " 10:00:00",
|
||||
"event_type": "Private",
|
||||
"ref_type": self.doctype,
|
||||
"ref_name": self.name
|
||||
}).insert(ignore_permissions=1)
|
||||
})
|
||||
event.add_participant(self.doctype, self.name)
|
||||
event.insert(ignore_permissions=1)
|
||||
|
||||
frappe.db.set(self, 'status', 'Submitted')
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
from frappe.utils.data import get_datetime, add_days
|
||||
|
||||
import frappe
|
||||
import unittest
|
||||
@ -9,4 +10,39 @@ import unittest
|
||||
# test_records = frappe.get_test_records('Maintenance Schedule')
|
||||
|
||||
class TestMaintenanceSchedule(unittest.TestCase):
|
||||
pass
|
||||
def test_events_should_be_created_and_deleted(self):
|
||||
ms = make_maintenance_schedule()
|
||||
ms.generate_schedule()
|
||||
ms.submit()
|
||||
|
||||
all_events = get_events(ms)
|
||||
self.assertTrue(len(all_events) > 0)
|
||||
|
||||
ms.cancel()
|
||||
events_after_cancel = get_events(ms)
|
||||
self.assertTrue(len(events_after_cancel) == 0)
|
||||
|
||||
def get_events(ms):
|
||||
return frappe.get_all("Event Participants", filters={
|
||||
"reference_doctype": ms.doctype,
|
||||
"reference_docname": ms.name,
|
||||
"parenttype": "Event"
|
||||
})
|
||||
|
||||
def make_maintenance_schedule():
|
||||
ms = frappe.new_doc("Maintenance Schedule")
|
||||
ms.company = "_Test Company"
|
||||
ms.customer = "_Test Customer"
|
||||
ms.transaction_date = get_datetime()
|
||||
|
||||
ms.append("items", {
|
||||
"item_code": "_Test Item",
|
||||
"start_date": get_datetime(),
|
||||
"end_date": add_days(get_datetime(), 32),
|
||||
"periodicity": "Weekly",
|
||||
"no_of_visits": 4,
|
||||
"sales_person": "Sales Team",
|
||||
})
|
||||
ms.insert(ignore_permissions=True)
|
||||
|
||||
return ms
|
||||
|
Loading…
Reference in New Issue
Block a user