From 03463ef73bf373af5a2415b093018c1e978f6a9a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 10 Jan 2014 16:28:41 +0530 Subject: [PATCH] Move related property setters to custom field property --- patches/1401/__init__.py | 0 ...elated_property_setters_to_custom_field.py | 35 +++++++++++++++++++ patches/patch_list.py | 1 + 3 files changed, 36 insertions(+) create mode 100644 patches/1401/__init__.py create mode 100644 patches/1401/p01_move_related_property_setters_to_custom_field.py diff --git a/patches/1401/__init__.py b/patches/1401/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/patches/1401/p01_move_related_property_setters_to_custom_field.py b/patches/1401/p01_move_related_property_setters_to_custom_field.py new file mode 100644 index 0000000000..6b28553977 --- /dev/null +++ b/patches/1401/p01_move_related_property_setters_to_custom_field.py @@ -0,0 +1,35 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import webnotes +from webnotes.model.meta import get_field + +def execute(): + webnotes.reload_doc("core", "doctype", "custom_field") + + custom_fields = {} + for cf in webnotes.conn.sql("""select dt, fieldname from `tabCustom Field`""", as_dict=1): + custom_fields.setdefault(cf.dt, []).append(cf.fieldname) + + delete_list = [] + for ps in webnotes.conn.sql("""select * from `tabProperty Setter`""", as_dict=1): + if ps.field_name in custom_fields.get(ps.doc_type, []): + + if ps.property == "previous_field": + property_name = "insert_after" + + field_meta = get_field(ps.doc_type, ps.value) + property_value = field_meta.label if field_meta else "" + else: + property_name = ps.property + property_value =ps.value + + webnotes.conn.sql("""update `tabCustom Field` + set %s=%s where dt=%s and fieldname=%s""" % (property_name, '%s', '%s', '%s'), + (property_value, ps.doc_type, ps.field_name)) + + delete_list.append(ps.name) + + if delete_list: + webnotes.conn.sql("""delete from `tabProperty Setter` where name in (%s)""" % + ', '.join(['%s']*len(delete_list)), tuple(delete_list)) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 608ba77168..e4d2975ea3 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -263,4 +263,5 @@ patch_list = [ "patches.1311.p08_email_digest_recipients", "execute:webnotes.delete_doc('DocType', 'Warehouse Type')", "patches.1312.p02_update_item_details_in_item_price", + "patches.1401.p01_move_related_property_setters_to_custom_field", ] \ No newline at end of file