コード例 #1
0
ファイル: transfer_control.py プロジェクト: ravidey/erpnext
 def ovr_mapper(self, doclist, ovr, ignore, onupdate):
   doclist = [Document(fielddata = d) for d in doclist]
   doc = doclist[0]
   orig_modified = doc.modified
   cur_doc = Document('DocType Mapper',doc.name)
   added = 0
   fld_lst = ''
       
   # Field Mapper Details fields
   # ------
   for d in getlist(doclist, 'field_mapper_details'):
     fld = ''
     # if exists
     if d.from_field and d.to_field:
       fld = sql("select name from `tabField Mapper Detail` where from_field=%s and to_field=%s and parent=%s", (d.from_field, d.to_field, d.parent))
           
     if (not fld) and d.from_field and d.to_field: # must have label
       # add field
       nd = Document(fielddata = d.fields)
       nd.oldfieldname, nd.oldfieldtype = '', ''
       nd.save(new = 1, ignore_fields = ignore, check_links = 0)
       fld_lst += "\n"+'From Field : '+cstr(d.from_field)+'   ---   To Field : '+cstr(d.to_field)
       added += 1
       
   # Table Mapper Details fields
   # ------
   for d in getlist(doclist, 'table_mapper_details'):
     fld = ''
     # if exists
     if d.from_table and d.to_table: 
       fld = sql("select name from `tabTable Mapper Detail` where from_table=%s and to_table = %s and parent=%s", (d.from_table, d.to_table, d.parent))
           
     if (not fld) and d.from_table and d.to_table: # must have label
       # add field
       nd = Document(fielddata = d.fields)
       nd.oldfieldname, nd.oldfieldtype = '', ''
       nd.save(new = 1, ignore_fields = ignore, check_links = 0)
       fld_lst += "\n"+'From Table : '+cstr(d.from_table)+'   ---   To Table : '+cstr(d.to_table)
       added += 1
            
   cur_doc.save(ignore_fields = ignore, check_links = 0)
   
   if onupdate:
     so = get_obj('DocType Mapper', doc.name, with_children = 1)
     if hasattr(so, 'on_update'):
       so.on_update()
   
   set(doc,'modified',orig_modified)
   
   if in_transaction: sql("COMMIT")
   
   if added == 0:
     added_fields = ''
   else:
     added_fields =  ' <div style="color : RED">Added Fields :- '+ cstr(fld_lst)+ '</div>' 
   return doc.name + (' Upgraded: %s fields added' % added)+added_fields
コード例 #2
0
ファイル: transfer.py プロジェクト: ranjithtenz/stable
def merge_module_def(doc_list, ovr, ignore, onupdate):
	import webnotes
	from webnotes.model.doc import Document
	from webnotes.model import doclist
	from webnotes.model.code import get_obj
	from webnotes.utils import cint
	from webnotes.utils import cstr
	import webnotes.db
	doc_list = [Document(fielddata = d) for d in doc_list]
	doc = doc_list[0]
	orig_modified = doc.modified
	cur_doc = Document('Module Def',doc.name)
	added, idx = 0, 0
	fld_lst, prev_dt, prev_dn, prev_dis_name = '', '', '', ''
		
	sql = webnotes.conn.sql
	
	# Module Def Item table fields
	for d in doclist.getlist(doc_list, 'items'):
		fld = ''
		# if exists
		if d.doc_type and d.doc_name:
			fld = sql("select name from `tabModule Def Item` where doc_type=%s and doc_name=%s and ifnull(display_name,'') = %s and parent=%s", (d.doc_type, d.doc_name, cstr(d.display_name), d.parent))
					
		if (not fld) and d.doc_type and d.doc_name:
			if prev_dt and prev_dn:
				idx = sql("select idx from `tabModule Def Item` where doc_type = %s and doc_name = %s and ifnull(display_name,'') = %s and parent = %s",(prev_dt, prev_dn, cstr(prev_dis_name), d.parent))[0][0]
			sql("update `tabModule Def Item` set idx = idx + 1 where parent=%s and idx > %s", (d.parent, cint(idx)))
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.idx = cint(idx)+1
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += '\n'+'Doc Type : '+cstr(d.doc_type)+'   ---	 Doc Name : '+cstr(d.doc_name)+'   ---	 Display Name : '+cstr(d.display_name)
			added += 1

		# clean up
		prev_dt = d.doc_type
		prev_dn = d.doc_name
		prev_dis_name = cstr(d.display_name)

	cur_doc.widget_code = cstr(doc.widget_code)
	cur_doc.save(ignore_fields = ignore, check_links = 0)
	
	if onupdate:
		so = get_obj('Module Def', doc.name, with_children = 1)
		if hasattr(so, 'on_update'):
			so.on_update()
	
	webnotes.conn.set(doc,'modified',orig_modified)
	
	if webnotes.conn.in_transaction: sql("COMMIT")
	
	if added == 0:
		added_fields = ''
	else:
		added_fields =	' Added Fields:'+ cstr(fld_lst)
	return doc.name + ('Upgraded: %s fields added' % added)+added_fields
コード例 #3
0
ファイル: transfer_control.py プロジェクト: ravidey/erpnext
 def ovr_tds(self, doclist, ovr, ignore, onupdate):
   doclist = [Document(fielddata = d) for d in doclist]
   doc = doclist[0]
   orig_modified = doc.modified
   cur_doc = Document('TDS Rate Chart',doc.name)
   added = 0
   fld_lst = ''
       
   # TDS RATE CHART DETAIL fields
   # ------
   for d in getlist(doclist,'rate_chart_detail'):
     fld = ''
     # if exists
     if d.category and d.slab_from and d.slab_to:
       fld = sql("select name from `tabTDS Rate Detail` where category=%s and slab_from=%s and slab_to = %s and parent=%s", (d.category, d.slab_from, d.slab_to, d.parent))
             
     if (not fld) and d.category and d.slab_from and d.slab_to:
       # add field
       nd = Document(fielddata = d.fields)
       nd.oldfieldname, nd.oldfieldtype = '', ''
       nd.save(new = 1, ignore_fields = ignore, check_links = 0)
       fld_lst += "\n"+'Category : '+cstr(d.category)+'   ---   Slab From : '+cstr(d.slab_from)+ '   ---   Slab To : '+cstr(d.slab_to)
       added += 1
   
   cur_doc.save(ignore_fields = ignore)
   
   if onupdate:
     so = get_obj('TDS Rate Chart', doc.name, with_children = 1)
     if hasattr(so, 'on_update'):
       so.on_update()
   
   set(doc,'modified',orig_modified)
   
   if in_transaction: sql("COMMIT")
   if added == 0:
     added_fields = ''
   else:
     added_fields =  ' <div style="color : RED">Added Fields :- '+ cstr(fld_lst)+ '</div>' 
   
   return doc.name + (' Upgraded: %s fields added' % added)+added_fields
コード例 #4
0
ファイル: transfer_control.py プロジェクト: ravidey/erpnext
  def ovr_doctype(self, doclist, ovr, ignore, onupdate):
    doclist = [Document(fielddata = d) for d in doclist]
    doc = doclist[0]
    orig_modified = doc.modified
    cur_doc = Document('DocType',doc.name)
    added = 0
    prevfield = ''
    prevlabel = ''
    idx = 0
    fld_lst = ''
        
    # fields
    # ------
    for d in getlist(doclist, 'fields'):
      fld = ''
      # if exists
      if d.fieldname:
        fld = sql("select name from tabDocField where fieldname=%s and parent=%s", (d.fieldname, d.parent))
      elif d.label: # for buttons where there is no fieldname
        fld = sql("select name from tabDocField where label=%s and parent=%s", (d.label, d.parent))

      if (not fld) and d.label: # must have label
        if prevfield:
          idx = sql("select idx from tabDocField where fieldname = %s and parent = %s",(prevfield,d.parent))[0][0]
        elif prevlabel and not prevfield:
          idx = sql("select idx from tabDocField where label = %s and parent = %s",(prevlabel,d.parent))[0][0]
        sql("update tabDocField set idx = idx + 1 where parent=%s and idx > %s", (d.parent, cint(idx)))          

        # add field
        nd = Document(fielddata = d.fields)
        nd.oldfieldname, nd.oldfieldtype = '', ''
        nd.idx = cint(idx)+1
        nd.save(new = 1, ignore_fields = ignore, check_links = 0)
        fld_lst += "\n"+'Label : '+cstr(d.label)+'   ---   Fieldtype : '+cstr(d.fieldtype)+'   ---   Fieldname : '+cstr(d.fieldname)+'   ---   Options : '+cstr(d.options)
        added += 1
      if d.fieldname:
        prevfield = d.fieldname
        prevlabel = ''
      elif d.label:
        prevfield = ''
        prevlabel = d.label
        
    # Print Formats
    # ------
    for d in getlist(doclist, 'formats'):
      fld = ''
      # if exists
      if d.format:
        fld = sql("select name from `tabDocFormat` where format=%s and parent=%s", (d.format, d.parent))
            
      if (not fld) and d.format: # must have label
        # add field
        nd = Document(fielddata = d.fields)
        nd.oldfieldname, nd.oldfieldtype = '', ''
        nd.save(new = 1, ignore_fields = ignore, check_links = 0)
        fld_lst = fld_lst + "\n"+'Format : '+cstr(d.format)
        added += 1
          
    # code
    # ----
    
    cur_doc.server_code_core = cstr(doc.server_code_core)
    cur_doc.client_script_core = cstr(doc.client_script_core)
    
    cur_doc.save(ignore_fields = ignore, check_links = 0)

    if version=='v160':
      so = get_obj('DocType', doc.name, with_children = 1)
      if hasattr(so, 'on_update'):
        so.on_update()
    elif version=='v170':
      import webnotes.model.doctype
      try: 
        webnotes.model.doctype.update_doctype(so.doclist)
      except: 
        pass
    
    set(doc,'modified',orig_modified)
    
    if in_transaction: sql("COMMIT")
    
    if added == 0:
      added_fields = ''
    else:
      added_fields =  ' <div style="color : RED">Added Fields :- '+ cstr(fld_lst)+ '</div>'
      
    return doc.name + (' Upgraded: %s fields added' % added)+added_fields
コード例 #5
0
ファイル: transfer.py プロジェクト: ranjithtenz/stable
def merge_mapper(doc_list, ovr, ignore, onupdate):
	import webnotes
	from webnotes.model.doc import Document
	from webnotes.model import doclist
	from webnotes.model.code import get_obj
	from webnotes.utils import cint
	from webnotes.utils import cstr
	import webnotes.db
	doc_list = [Document(fielddata = d) for d in doc_list]
	doc = doc_list[0]
	orig_modified = doc.modified
	cur_doc = Document('DocType Mapper',doc.name)
	added = 0
	fld_lst = ''
		
	sql = webnotes.conn.sql
	
	# Field Mapper Details fields
	# ------
	for d in doclist.getlist(doc_list, 'field_mapper_details'):
		fld = ''
		# if exists
		if d.from_field and d.to_field:
			fld = sql("select name from `tabField Mapper Detail` where from_field=%s and to_field=%s and parent=%s", (d.from_field, d.to_field, d.parent))
					
		if (not fld) and d.from_field and d.to_field: # must have label
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += '\n'+'From Field : '+cstr(d.from_field)+'	 ---	 To Field : '+cstr(d.to_field)
			added += 1
			
	# Table Mapper Details fields
	# ------
	for d in doclist.getlist(doc_list, 'table_mapper_details'):
		fld = ''
		# if exists
		if d.from_table and d.to_table: 
			fld = sql("select name from `tabTable Mapper Detail` where from_table=%s and to_table = %s and parent=%s", (d.from_table, d.to_table, d.parent))
					
		if (not fld) and d.from_table and d.to_table: # must have label
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += '\n'+'From Table : '+cstr(d.from_table)+'	 ---	 To Table : '+cstr(d.to_table)
			added += 1
					 
	cur_doc.save(ignore_fields = ignore, check_links = 0)
	
	if onupdate:
		so = get_obj('DocType Mapper', doc.name, with_children = 1)
		if hasattr(so, 'on_update'):
			so.on_update()
	
	webnotes.conn.set(doc,'modified',orig_modified)
	
	if webnotes.conn.in_transaction: sql("COMMIT")
	
	if added == 0:
		added_fields = ''
	else:
		added_fields =	' Added Fields:'+ cstr(fld_lst)
	return doc.name + ('Upgraded: %s fields added' % added)+added_fields

	added = 0
	fld_lst = ''
		
	sql = webnotes.conn.sql
	
	# Field Mapper Details fields
	# ------
	for d in doclist.getlist(doc_list, 'field_mapper_details'):
		fld = ''
		# if exists
		if d.from_field and d.to_field:
			fld = sql("select name from `tabField Mapper Detail` where from_field=%s and to_field=%s and parent=%s", (d.from_field, d.to_field, d.parent))
					
		if (not fld) and d.from_field and d.to_field: # must have label
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += '\n'+'From Field : '+cstr(d.from_field)+'	 ---	 To Field : '+cstr(d.to_field)
			added += 1
			
	# Table Mapper Details fields
	# ------
	for d in doclist.getlist(doc_list, 'table_mapper_details'):
		fld = ''
		# if exists
		if d.from_table and d.to_table: 
			fld = sql("select name from `tabTable Mapper Detail` where from_table=%s and to_table = %s and parent=%s", (d.from_table, d.to_table, d.parent))
					
		if (not fld) and d.from_table and d.to_table: # must have label
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += '\n'+'From Table : '+cstr(d.from_table)+'	 ---	 To Table : '+cstr(d.to_table)
			added += 1
					 
	cur_doc.save(ignore_fields = ignore, check_links = 0)
	
	if onupdate:
		so = get_obj('DocType Mapper', doc.name, with_children = 1)
		if hasattr(so, 'on_update'):
			so.on_update()
	
	webnotes.conn.set(doc,'modified',orig_modified)
	
	if webnotes.conn.in_transaction: sql("COMMIT")
	
	if added == 0:
		added_fields = ''
	else:
		added_fields =	' Added Fields:'+ cstr(fld_lst)
	return doc.name + ('Upgraded: %s fields added' % added)+added_fields
コード例 #6
0
ファイル: transfer.py プロジェクト: ranjithtenz/stable
def merge_doctype(doc_list, ovr, ignore, onupdate):
	import webnotes
	from webnotes.model.doc import Document
	from webnotes.model import doclist
	from webnotes.utils import cint
	from webnotes.utils import cstr
	
	doc_list = [Document(fielddata = d) for d in doc_list]
	
	doc = doc_list[0]
	orig_modified = doc.modified
	cur_doc = Document('DocType',doc.name)
	added = 0
	prevfield = ''
	prevlabel = ''
	idx = 0
	fld_lst = ''
	
	sql = webnotes.conn.sql

	# fields
	# ------
	for d in doclist.getlist(doc_list, 'fields'):
		fld = ''
		# if exists
		if d.fieldname:
			fld = sql("select name from tabDocField where fieldname=%s and parent=%s", (d.fieldname, d.parent))
		elif d.label: # for buttons where there is no fieldname
			fld = sql("select name from tabDocField where label=%s and parent=%s", (d.label, d.parent))

		if (not fld) and d.label: # must have label
			if prevfield:
				idx = sql("select idx from tabDocField where fieldname = %s and parent = %s",(prevfield,d.parent))[0][0]
			elif prevlabel and not prevfield:
				idx = sql("select idx from tabDocField where label = %s and parent = %s",(prevlabel,d.parent))[0][0]
			sql("update tabDocField set idx = idx + 1 where parent=%s and idx > %s", (d.parent, cint(idx)))					

			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.idx = cint(idx)+1
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst += 'Label : '+cstr(d.label)+'	 ---	 Fieldtype : '+cstr(d.fieldtype)+'	 ---	 Fieldname : '+cstr(d.fieldname)+'	 ---	 Options : '+cstr(d.options)
			added += 1
			
		# clean up
		if d.fieldname:
			prevfield = d.fieldname
			prevlabel = ''
		elif d.label:
			prevfield = ''
			prevlabel = d.label
			
	# Print Formats
	# -------------
	for d in doclist.getlist(doc_list, 'formats'):
		fld = ''
		# if exists
		if d.format:
			fld = sql("select name from `tabDocFormat` where format=%s and parent=%s", (d.format, d.parent))
					
		if (not fld) and d.format: # must have label
			# add field
			nd = Document(fielddata = d.fields)
			nd.oldfieldname, nd.oldfieldtype = '', ''
			nd.save(new = 1, ignore_fields = ignore, check_links = 0)
			fld_lst = fld_lst + '\n'+'Format : '+cstr(d.format)
			added += 1
				
	# code
	# ----
	
	cur_doc.server_code_core = cstr(doc.server_code_core)
	cur_doc.client_script_core = cstr(doc.client_script_core)
	cur_doc.module = doc.module
	cur_doc.save(ignore_fields = ignore, check_links = 0)	
	

	# update schema
	# -------------
	import webnotes.model
	try:
		dl = webnotes.model.doc.get('DocType', doc.name)
		webnotes.model.doctype.update_doctype(dl)
	except:
		pass
	
	webnotes.conn.set(doc,'modified',orig_modified)
	
	if webnotes.conn.in_transaction: sql("COMMIT")
	
	if added == 0:
		added_fields = ''
	else:
		added_fields =	' Added Fields :'+ cstr(fld_lst)
		
	return doc.name + (' Upgraded: %s fields added' % added)+added_fields