Add event in transaction base correction (#15631)

This commit is contained in:
Charles-Henri Decultot 2018-10-11 13:24:26 +02:00 committed by Nabin Hait
parent 6c743bebf2
commit 64b6421fce

View File

@ -37,11 +37,18 @@ class TransactionBase(StatusUpdater):
self._add_calendar_event(opts) self._add_calendar_event(opts)
def delete_events(self): def delete_events(self):
events = frappe.db.sql_list("""select name from `tabEvent` participations = frappe.get_all("Event Participants", filters={"reference_doctype": self.doctype, "reference_docname": self.name,
where ref_type=%s and ref_name=%s""", (self.doctype, self.name)) "parenttype": "Event"}, fields=["name", "parent"])
if events:
frappe.db.sql("delete from `tabEvent` where name in ({0})" if participations:
.format(", ".join(['%s']*len(events))), tuple(events)) for participation in participations:
total_participants = frappe.get_all("Event Participants", filters={"parenttype": "Event", "parent": participation.parent})
if len(total_participants) <= 1:
frappe.db.sql("delete from `tabEvent` where name='%s'" % participation.parent)
frappe.db.sql("delete from `tabEvent Participants` where name='%s'" % participation.name)
def _add_calendar_event(self, opts): def _add_calendar_event(self, opts):
opts = frappe._dict(opts) opts = frappe._dict(opts)
@ -54,11 +61,15 @@ class TransactionBase(StatusUpdater):
"description": opts.description, "description": opts.description,
"starts_on": self.contact_date, "starts_on": self.contact_date,
"ends_on": opts.ends_on, "ends_on": opts.ends_on,
"event_type": "Private", "event_type": "Private"
"ref_type": self.doctype,
"ref_name": self.name
}) })
event.append('event_participants', {
"reference_doctype": self.doctype,
"reference_docname": self.name
}
)
event.insert(ignore_permissions=True) event.insert(ignore_permissions=True)
if frappe.db.exists("User", self.contact_by): if frappe.db.exists("User", self.contact_by):