From 6f7cdeae6446676dcb248d655188576b37cf7504 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 16 Mar 2012 16:25:23 +0530 Subject: [PATCH 1/3] rename function modified --- docs/old/_sources/report_cookbook.txt | 4 ++-- py/webnotes/model/__init__.py | 33 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/old/_sources/report_cookbook.txt b/docs/old/_sources/report_cookbook.txt index 3653db779c..6ef4318574 100644 --- a/docs/old/_sources/report_cookbook.txt +++ b/docs/old/_sources/report_cookbook.txt @@ -17,7 +17,7 @@ Filters can be modified declaring the customize_filters method:: this.filter_fields_dict['GL Entry'+FILTER_SEP +'Account'].df.filter_hide = 0; // add new filters - this.add_filter({fieldname:'aging_based_on', label:'Aging Based On', fieldtype:'Select', options:NEWLINE+'Transaction Date'+NEWLINE+'Aging Date'+NEWLINE+'Due Date',ignore : 1, parent:'Receivable Voucher', report_default:'Aging Date'}); + this.add_filter({fieldname:'aging_based_on', label:'Aging Based On', fieldtype:'Select', options:NEWLINE+'Transaction Date'+NEWLINE+'Aging Date'+NEWLINE+'Due Date',ignore : 1, parent:'Sales Invoice', report_default:'Aging Date'}); this.add_filter({fieldname:'range_1', label:'Range 1', fieldtype:'Data', ignore : 1, parent:'GL Entry'}); // set default filters @@ -83,7 +83,7 @@ Values of columns can be found by label using the dictionary col_idx:: r.append(terr and terr[0][0] or '') # get due date - due_date = sql("""select due_date from `tabReceivable Voucher` + due_date = sql("""select due_date from `tabSales Invoice` where name = '%s'""" % r[col_idx['Against Voucher']]) r.append(due_date and cstr(due_date[0][0]) or '') diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index 025fb875a4..da0611530a 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -141,8 +141,9 @@ def rename(dt, old, new, is_doctype = 0): """ Renames a doc(dt, old) to doc(dt, new) and updates all linked fields of type "Link" or "Select" with "link:" """ - sql = webnotes.conn.sql + import webnotes.utils + sql = webnotes.conn.sql # rename doc sql("update `tab%s` set name='%s' where name='%s'" % (dt, new, old)) @@ -150,16 +151,20 @@ def rename(dt, old, new, is_doctype = 0): ct = sql("select options from tabDocField where parent = '%s' and fieldtype='Table'" % dt) for c in ct: sql("update `tab%s` set parent='%s' where parent='%s'" % (c[0], new, old)) + + # if dt is a child table of another dt + sql("update `tabDocField` set options = '%s' where options = '%s' and fieldtype = 'Table'" % (new, old)) # get links (link / select) ll = get_link_fields(dt) - for l in ll: - is_single = sql("select issingle from tabDocType where name = '%s'" % l[0]) - is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0 - if is_single: - sql("update `tabSingles` set value='%s' where field='%s' and value = '%s' and doctype = '%s' " % (new, l[1], old, l[0])) - else: - sql("update `tab%s` set `%s`='%s' where `%s`='%s'" % (l[0], l[1], new, l[1], old)) + update_link_fld_values(ll, old, new) + + # update options and values where select options contains old dt + select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select'" % old) + update_link_fld_values(select_flds, old, new) + + sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old)) + # doctype if is_doctype: @@ -170,6 +175,18 @@ def rename(dt, old, new, is_doctype = 0): for c in ct: sql("update `tab%s` set parenttype='%s' where parenttype='%s'" % (c[0], new, old)) + + +def update_link_fld_values(flds, old, new): + for l in flds: + is_single = sql("select issingle from tabDocType where name = '%s'" % l[0]) + is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0 + if is_single: + sql("update `tabSingles` set value='%s' where field='%s' and value = '%s' and doctype = '%s' " % (new, l[1], old, l[0])) + else: + sql("update `tab%s` set `%s`='%s' where `%s`='%s'" % (l[0], l[1], new, l[1], old)) + + #================================================================================= def clear_recycle_bin(): From 76a0fd29c85c531f6566a1e6b66d16ed84db2a90 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 28 Mar 2012 12:01:05 +0530 Subject: [PATCH 2/3] error fixed in mapper --- py/core/doctype/doctype_mapper/doctype_mapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/core/doctype/doctype_mapper/doctype_mapper.py b/py/core/doctype/doctype_mapper/doctype_mapper.py index b28a984ded..48c830129e 100644 --- a/py/core/doctype/doctype_mapper/doctype_mapper.py +++ b/py/core/doctype/doctype_mapper/doctype_mapper.py @@ -239,7 +239,7 @@ class DocType: ft = sql("select fieldtype from tabDocField where fieldname = '%s' and parent = '%s'" % (fld,tbl)) ft = ft and ft[0][0] or '' if ft == 'Currency' or ft == 'Float': - cur_val = '%.2f' % cur_val + cur_val = '%.2f' % flt(cur_val) return cur_val, ft # Check consistency From 2c03250c85679b98943fae587fba9d855a0c066d Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 28 Mar 2012 12:09:01 +0530 Subject: [PATCH 3/3] changes in rename_dt --- py/webnotes/model/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/py/webnotes/model/__init__.py b/py/webnotes/model/__init__.py index da0611530a..df0b48dee6 100644 --- a/py/webnotes/model/__init__.py +++ b/py/webnotes/model/__init__.py @@ -160,7 +160,7 @@ def rename(dt, old, new, is_doctype = 0): update_link_fld_values(ll, old, new) # update options and values where select options contains old dt - select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select'" % old) + select_flds = sql("select parent, fieldname from `tabDocField` where parent not like 'old%%' and options like '%%%s%%' and options not like 'link:%%' and fieldtype = 'Select' and parent != '%s'" % (old, new)) update_link_fld_values(select_flds, old, new) sql("update `tabDocField` set options = replace(options, '%s', '%s') where options like '%%%s%%'" % (old, new, old)) @@ -168,7 +168,10 @@ def rename(dt, old, new, is_doctype = 0): # doctype if is_doctype: - sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new)) + if not is_single_dt(old): + sql("RENAME TABLE `tab%s` TO `tab%s`" % (old, new)) + else: + sql("update tabSingles set doctype = %s where doctype = %s", (new, old)) # get child docs (update parenttype) ct = sql("select options from tabDocField where parent = '%s' and fieldtype='Table'" % new) @@ -179,13 +182,15 @@ def rename(dt, old, new, is_doctype = 0): def update_link_fld_values(flds, old, new): for l in flds: - is_single = sql("select issingle from tabDocType where name = '%s'" % l[0]) - is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0 - if is_single: - sql("update `tabSingles` set value='%s' where field='%s' and value = '%s' and doctype = '%s' " % (new, l[1], old, l[0])) + if is_single_dt(l[0]): + webnotes.conn.sql("update `tabSingles` set value='%s' where field='%s' and value = '%s' and doctype = '%s' " % (new, l[1], old, l[0])) else: - sql("update `tab%s` set `%s`='%s' where `%s`='%s'" % (l[0], l[1], new, l[1], old)) + webnotes.conn.sql("update `tab%s` set `%s`='%s' where `%s`='%s'" % (l[0], l[1], new, l[1], old)) +def is_single_dt(dt): + is_single = webnotes.conn.sql("select issingle from tabDocType where name = '%s'" % dt) + is_single = is_single and webnotes.utils.cint(is_single[0][0]) or 0 + return is_single #=================================================================================