[fix] [minor] create birthday event only for active employees, else delete it
This commit is contained in:
parent
dd2ec17962
commit
0b6fa018d6
@ -156,20 +156,23 @@ class DocType:
|
|||||||
raise_exception=InvalidLeaveApproverError)
|
raise_exception=InvalidLeaveApproverError)
|
||||||
|
|
||||||
def update_dob_event(self):
|
def update_dob_event(self):
|
||||||
if self.doc.date_of_birth:
|
if self.doc.status == "Active" and self.doc.date_of_birth:
|
||||||
get_events = webnotes.conn.sql("""select name from `tabEvent` where repeat_on='Every Year'
|
birthday_event = webnotes.conn.sql("""select name from `tabEvent` where repeat_on='Every Year'
|
||||||
and ref_type='Employee' and ref_name=%s""", self.doc.name)
|
and ref_type='Employee' and ref_name=%s""", self.doc.name)
|
||||||
|
|
||||||
starts_on = self.doc.date_of_birth + " 00:00:00"
|
starts_on = self.doc.date_of_birth + " 00:00:00"
|
||||||
ends_on = self.doc.date_of_birth + " 00:15:00"
|
ends_on = self.doc.date_of_birth + " 00:15:00"
|
||||||
|
|
||||||
if get_events:
|
if birthday_event:
|
||||||
webnotes.conn.sql("""update `tabEvent` set starts_on=%s, ends_on=%s
|
event = webnotes.bean("Event", birthday_event[0][0])
|
||||||
where name=%s""", (starts_on, ends_on, get_events[0][0]))
|
event.doc.starts_on = starts_on
|
||||||
|
event.doc.ends_on = ends_on
|
||||||
|
event.save()
|
||||||
else:
|
else:
|
||||||
webnotes.bean({
|
webnotes.bean({
|
||||||
"doctype": "Event",
|
"doctype": "Event",
|
||||||
"subject": _("Birthday") + ": " + self.doc.employee_name,
|
"subject": _("Birthday") + ": " + self.doc.employee_name,
|
||||||
|
"description": _("Happy Birthday!") + " " + self.doc.employee_name,
|
||||||
"starts_on": starts_on,
|
"starts_on": starts_on,
|
||||||
"ends_on": ends_on,
|
"ends_on": ends_on,
|
||||||
"event_type": "Public",
|
"event_type": "Public",
|
||||||
|
|||||||
@ -5,7 +5,9 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
for employee in webnotes.conn.sql_list("""select name from `tabEmployee` where ifnull(date_of_birth, '')!=''"""):
|
webnotes.conn.sql("""delete from `tabEvent` where repeat_on='Every Year' and ref_type='Employee'""")
|
||||||
|
for employee in webnotes.conn.sql_list("""select name from `tabEmployee` where status='Active' and
|
||||||
|
ifnull(date_of_birth, '')!=''"""):
|
||||||
obj = webnotes.get_obj("Employee", employee)
|
obj = webnotes.get_obj("Employee", employee)
|
||||||
obj.update_dob_event()
|
obj.update_dob_event()
|
||||||
|
|
||||||
@ -254,5 +254,5 @@ patch_list = [
|
|||||||
"patches.august_2013.p01_hr_settings",
|
"patches.august_2013.p01_hr_settings",
|
||||||
"patches.august_2013.p02_rename_price_list",
|
"patches.august_2013.p02_rename_price_list",
|
||||||
"patches.august_2013.p03_pos_setting_replace_customer_account",
|
"patches.august_2013.p03_pos_setting_replace_customer_account",
|
||||||
"patches.august_2013.p04_employee_birthdays",
|
"patches.august_2013.p05_employee_birthdays",
|
||||||
]
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user