From a2945e8e4b37bbedde1376cc8a94a9509fdcda7a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 8 Jan 2013 19:27:41 +0530 Subject: [PATCH] patch to fix existing holiday lists --- patches/january_2013/holiday_list_patch.py | 38 ++++++++++++++++++++++ patches/patch_list.py | 4 +++ 2 files changed, 42 insertions(+) create mode 100644 patches/january_2013/holiday_list_patch.py diff --git a/patches/january_2013/holiday_list_patch.py b/patches/january_2013/holiday_list_patch.py new file mode 100644 index 0000000000..ec78b16790 --- /dev/null +++ b/patches/january_2013/holiday_list_patch.py @@ -0,0 +1,38 @@ +import webnotes +from collections import Counter +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 = Counter([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() + + + + + + + + \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 2dd37ecad8..f9bb97cf8a 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -578,4 +578,8 @@ patch_list = [ 'patch_module': 'patches.january_2013', 'patch_file': 'remove_support_search_criteria', }, + { + 'patch_module': 'patches.january_2013', + 'patch_file': 'holiday_list_patch', + }, ] \ No newline at end of file