patch to fix existing holiday lists
This commit is contained in:
parent
89230cbc4b
commit
6f88c6680e
41
patches/january_2013/holiday_list_patch.py
Normal file
41
patches/january_2013/holiday_list_patch.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import webnotes
|
||||||
|
def execute():
|
||||||
|
for name in webnotes.conn.sql("""select name from `tabHoliday List`"""):
|
||||||
|
holiday_list_wrapper = webnotes.model_wrapper("Holiday List", name[0])
|
||||||
|
|
||||||
|
desc_count = _count([d.description for d in
|
||||||
|
holiday_list_wrapper.doclist.get({"doctype": "Holiday"})])
|
||||||
|
|
||||||
|
holiday_list_obj = webnotes.get_obj(doc=holiday_list_wrapper.doc,
|
||||||
|
doclist=holiday_list_wrapper.doclist)
|
||||||
|
|
||||||
|
save = False
|
||||||
|
|
||||||
|
for desc in desc_count.keys():
|
||||||
|
if desc in ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
|
||||||
|
"Friday", "Saturday"] and desc_count[desc] > 50:
|
||||||
|
holiday_list_obj.doclist = holiday_list_obj.doclist.get(
|
||||||
|
{"description": ["!=", desc]})
|
||||||
|
|
||||||
|
webnotes.conn.sql("""delete from `tabHoliday`
|
||||||
|
where parent=%s and parenttype='Holiday List'
|
||||||
|
and `description`=%s""", (holiday_list_obj.doc.name, desc))
|
||||||
|
holiday_list_obj.doc.weekly_off = desc
|
||||||
|
holiday_list_obj.get_weekly_off_dates()
|
||||||
|
save = True
|
||||||
|
|
||||||
|
if save:
|
||||||
|
holiday_list_wrapper.set_doclist(holiday_list_obj.doclist)
|
||||||
|
holiday_list_wrapper.save()
|
||||||
|
|
||||||
|
def _count(lst):
|
||||||
|
out = {}
|
||||||
|
for l in lst:
|
||||||
|
out[l] = out.setdefault(l, 0) + 1
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -578,4 +578,8 @@ patch_list = [
|
|||||||
'patch_module': 'patches.january_2013',
|
'patch_module': 'patches.january_2013',
|
||||||
'patch_file': 'remove_support_search_criteria',
|
'patch_file': 'remove_support_search_criteria',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'patch_module': 'patches.january_2013',
|
||||||
|
'patch_file': 'holiday_list_patch',
|
||||||
|
},
|
||||||
]
|
]
|
Loading…
Reference in New Issue
Block a user