From ce3296fc87298466c32b6de471d9b1f78aa31ccc Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 12:28:19 +0530 Subject: [PATCH 1/5] [rename tool] [fix] condition to validate that content exists in a row of the uploaded file --- utilities/doctype/rename_tool/rename_tool.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utilities/doctype/rename_tool/rename_tool.py b/utilities/doctype/rename_tool/rename_tool.py index 2e368ced70..5accf3c6b7 100644 --- a/utilities/doctype/rename_tool/rename_tool.py +++ b/utilities/doctype/rename_tool/rename_tool.py @@ -34,7 +34,8 @@ def upload(select_doctype=None, rows=None): rename_log = [] for row in rows: - if len(row) > 2: + # if row has some content + if len(row) > 1 and row[0] and row[1]: try: if rename_doc(select_doctype, row[0], row[1]): rename_log.append(_("Successful: ") + row[0] + " -> " + row[1]) @@ -45,5 +46,5 @@ def upload(select_doctype=None, rows=None): rename_log.append("" + \ _("Failed: ") + row[0] + " -> " + row[1] + "") rename_log.append("" + repr(e) + "") - + return rename_log \ No newline at end of file From 457cd7d1f446b7a823eef77c4df5c53c1e90d8c6 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 13:01:44 +0530 Subject: [PATCH 2/5] [gl entry] [validation] company match validation should be done only for is_cancelled = No --- accounts/doctype/gl_entry/gl_entry.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py index 64d84b0459..429cc104a7 100644 --- a/accounts/doctype/gl_entry/gl_entry.py +++ b/accounts/doctype/gl_entry/gl_entry.py @@ -108,8 +108,8 @@ class DocType: and not 'Accounts Manager' in webnotes.user.get_roles(): msgprint(_("Account") + ": " + self.doc.account + _(" has been freezed. \ Only Accounts Manager can do transaction against this account"), raise_exception=1) - - if ret and ret[0]["company"] != self.doc.company: + + if self.doc.is_cancelled in ("No", None) and ret and ret[0]["company"] != self.doc.company: msgprint(_("Account") + ": " + self.doc.account + _(" does not belong to the company") \ + ": " + self.doc.company, raise_exception=1) @@ -124,9 +124,10 @@ class DocType: return self.cost_center_company[self.doc.cost_center] - if self.doc.cost_center and _get_cost_center_company() != self.doc.company: - msgprint(_("Cost Center") + ": " + self.doc.cost_center \ - + _(" does not belong to the company") + ": " + self.doc.company, raise_exception=True) + if self.doc.is_cancelled in ("No", None) and \ + self.doc.cost_center and _get_cost_center_company() != self.doc.company: + msgprint(_("Cost Center") + ": " + self.doc.cost_center \ + + _(" does not belong to the company") + ": " + self.doc.company, raise_exception=True) def check_freezing_date(self, adv_adj): """ From e5a36a287f8069025d13b7b2547f580965d69525 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 14:12:27 +0530 Subject: [PATCH 3/5] [patch] [file data] patch for custom fields with name file_list --- patches/april_2013/p05_update_file_data.py | 40 +++++++++++++--------- patches/patch_list.py | 1 + 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py index 986e5b9b53..1ff48fa60e 100644 --- a/patches/april_2013/p05_update_file_data.py +++ b/patches/april_2013/p05_update_file_data.py @@ -5,28 +5,36 @@ def execute(): webnotes.reload_doc("core", "doctype", "file_data") webnotes.reset_perms("File Data") - singles = webnotes.conn.sql_list("""select name from tabDocType - where ifnull(issingle,0)=1""") + singles = get_single_doctypes() + for doctype in webnotes.conn.sql_list("""select parent from tabDocField where fieldname='file_list' and fieldtype='Text'"""): - if doctype in singles: - doc = webnotes.doc(doctype, doctype) - if doc.file_list: - update_for_doc(doctype, doc) - webnotes.conn.set_value(doctype, None, "file_list", None) - else: - try: - for doc in webnotes.conn.sql("""select name, file_list from `tab%s` where - ifnull(file_list, '')!=''""" % doctype, as_dict=True): - update_for_doc(doctype, doc) - webnotes.conn.commit() - webnotes.conn.sql("""alter table `tab%s` drop column file_list""" % doctype) - except Exception, e: - if e.args[0]!=1054: raise e + update_file_list(doctype, singles) webnotes.conn.sql("""delete from tabDocField where fieldname='file_list' and parent=%s""", doctype) + # export_to_files([["DocType", doctype]]) + +def get_single_doctypes(): + return webnotes.conn.sql_list("""select name from tabDocType + where ifnull(issingle,0)=1""") + +def update_file_list(doctype, singles): + if doctype in singles: + doc = webnotes.doc(doctype, doctype) + if doc.file_list: + update_for_doc(doctype, doc) + webnotes.conn.set_value(doctype, None, "file_list", None) + else: + try: + for doc in webnotes.conn.sql("""select name, file_list from `tab%s` where + ifnull(file_list, '')!=''""" % doctype, as_dict=True): + update_for_doc(doctype, doc) + webnotes.conn.commit() + webnotes.conn.sql("""alter table `tab%s` drop column file_list""" % doctype) + except Exception, e: + if e.args[0]!=1054: raise e def update_for_doc(doctype, doc): for filedata in doc.file_list.split("\n"): diff --git a/patches/patch_list.py b/patches/patch_list.py index a6dd0a217b..096fec80ab 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -247,4 +247,5 @@ patch_list = [ "execute:webnotes.reload_doc('Stock', 'DocType', 'Delivery Note Item')", "patches.april_2013.p06_default_cost_center", "execute:webnotes.reset_perms('File Data')", + "patches.april_2013.p07_update_file_data_custom_field", ] \ No newline at end of file From 123f59dc89cf3858678ba8a71bfd72e9a3b9438b Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 14:21:42 +0530 Subject: [PATCH 4/5] [patches] [file data] fixes in file data patch --- patches/april_2013/p05_update_file_data.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/patches/april_2013/p05_update_file_data.py b/patches/april_2013/p05_update_file_data.py index 1ff48fa60e..d3877417e2 100644 --- a/patches/april_2013/p05_update_file_data.py +++ b/patches/april_2013/p05_update_file_data.py @@ -53,10 +53,17 @@ def update_for_doc(doctype, doc): exists = False if exists: - webnotes.conn.sql("""update `tabFile Data` - set attached_to_doctype=%s, attached_to_name=%s - where name=%s""", (doctype, doc.name, fileid)) - + if webnotes.conn.exists("File Data", fileid): + fd = webnotes.bean("File Data", fileid) + if not (fd.doc.attached_to_doctype and fd.doc.attached_to_name): + fd.doc.attached_to_doctype = doctype + fd.doc.attached_to_name = doc.name + fd.save() + else: + fd = webnotes.bean("File Data", copy=fd.doclist) + fd.doc.attached_to_doctype = doctype + fd.doc.attached_to_name = doc.name + fd.insert() else: webnotes.conn.sql("""delete from `tabFile Data` where name=%s""", - fileid) \ No newline at end of file + fileid) \ No newline at end of file From 7bd7c8769ef6eb472b9b0dde5653859ccaa7150d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 29 Apr 2013 14:21:58 +0530 Subject: [PATCH 5/5] [patch] [file data] files in update file data patch --- .../april_2013/p07_update_file_data_custom_field.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 patches/april_2013/p07_update_file_data_custom_field.py diff --git a/patches/april_2013/p07_update_file_data_custom_field.py b/patches/april_2013/p07_update_file_data_custom_field.py new file mode 100644 index 0000000000..909df0554d --- /dev/null +++ b/patches/april_2013/p07_update_file_data_custom_field.py @@ -0,0 +1,11 @@ +import webnotes +def execute(): + from patches.april_2013.p05_update_file_data import update_file_list, get_single_doctypes + singles = get_single_doctypes() + for doctype in webnotes.conn.sql("""select parent from `tabCustom Field` where + fieldname='file_list' and fieldtype='Text'"""): + update_file_list(doctype, singles) + + webnotes.conn.sql("""delete from `tabCustom Field` where fieldname='file_list' + and parent=%s""", doctype) + \ No newline at end of file