patch to fix existing holiday lists

This commit is contained in:
Anand Doshi 2013-01-08 19:27:41 +05:30
parent 89230cbc4b
commit 6f88c6680e
2 changed files with 45 additions and 0 deletions

View 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

View File

@ -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',
},
] ]