Ejemplo n.º 1
0
    def addchild(self, fieldname, childtype="", local=0, doclist=None):
        """
	      Returns a child record of the give `childtype`.
	      
	      * if local is set, it does not save the record
	      * if doclist is passed, it append the record to the doclist
		"""
        if not childtype:
            childtype = db_getchildtype(self.doctype, fieldname)

        d = Document()
        d.parent = self.name
        d.parenttype = self.doctype
        d.parentfield = fieldname
        d.doctype = childtype
        d.docstatus = 0
        d.name = ""
        d.owner = webnotes.session["user"]

        if local:
            d.fields["__islocal"] = "1"  # for Client to identify unsaved doc
        else:
            d.save(new=1)

        if doclist != None:
            doclist.append(d)

        return d
Ejemplo n.º 2
0
def runserverobj():
	import webnotes.model.code
	import webnotes.model.doclist
	from webnotes.utils import cint

	form = webnotes.form


	method = form.getvalue('method')
	doclist, clientlist = [], []
	arg = form.getvalue('arg')
	dt = form.getvalue('doctype')
	dn = form.getvalue('docname')
		
	if dt: # not called from a doctype (from a page)
		if not dn: dn = dt # single
		so = webnotes.model.code.get_obj(dt, dn)

	else:
		clientlist = webnotes.model.doclist.expand(form.getvalue('docs'))

		# find main doc
		for d in clientlist:
			if cint(d.get('docstatus')) != 2 and not d.get('parent'):
				main_doc = webnotes.model.doc.Document(fielddata = d)
	
		# find child docs
		for d in clientlist:
			doc = webnotes.model.doc.Document(fielddata = d)
			if doc.fields.get('parent'):
				doclist.append(doc)	
	
		so = webnotes.model.code.get_server_obj(main_doc, doclist)

	# check integrity
	if not check_integrity(so.doc):
		return
		
	check_guest_access(so.doc)
				
	if so:
		r = webnotes.model.code.run_server_obj(so, method, arg)
		doclist = so.doclist # reference back [in case of null]
		if r:
			try:
				if r['doclist']:
					clientlist += r['doclist']
			except:
				pass
			
			#build output as csv
			if cint(webnotes.form.getvalue('as_csv')):
				make_csv_output(r, so.doc.doctype)
			else:
				webnotes.response['message'] = r
		
		if clientlist:
			doclist.append(main_doc)
			webnotes.response['docs'] = doclist
Ejemplo n.º 3
0
def add_print_formats(doclist):
    print_formats = webnotes.conn.sql("""select * FROM `tabPrint Format`
		WHERE doc_type=%s AND docstatus<2""",
                                      doclist[0].name,
                                      as_dict=1)
    for pf in print_formats:
        doclist.append(
            webnotes.model.doc.Document('Print Format', fielddata=pf))
Ejemplo n.º 4
0
def add_print_formats(doclist):
    print_formats = webnotes.conn.sql(
        """select * FROM `tabPrint Format`
		WHERE doc_type=%s AND docstatus<2""",
        doclist[0].name,
        as_dict=1,
    )
    for pf in print_formats:
        doclist.append(webnotes.model.doc.Document("Print Format", fielddata=pf))
Ejemplo n.º 5
0
	def addchild(self, fieldname, childtype = '', local=0, doclist=None):
		if not childtype:
			childtype = db_getchildtype(self.doctype, fieldname)
	
		d = Document()
		d.parent = self.name
		d.parenttype = self.doctype
		d.parentfield = fieldname
		d.doctype = childtype
		d.docstatus = 0;
		d.name = ''
		d.owner = webnotes.session['user']
		
		if local:
			d.fields['__islocal'] = '1' # for Client to identify unsaved doc
		else: 
			d.save(new=1)
	
		if doclist != None:
			doclist.append(d)
	
		return d
Ejemplo n.º 6
0
        if e.args[0] == 1146:
            return doclist
        else:
            raise e

    for r in res:
        custom_field = webnotes.model.doc.Document(fielddata=r)

        # convert to DocField
        custom_field.fields.update({
            'doctype': 'DocField',
            'parent': doctype,
            'parentfield': 'fields',
            'parenttype': 'DocType',
        })
        doclist.append(custom_field)

    return doclist


def add_linked_with(doclist):
    """add list of doctypes this doctype is 'linked' with"""
    doctype = doclist[0].name
    links = webnotes.conn.sql(
        """select parent, fieldname from tabDocField
		where (fieldtype="Link" and options=%s)
		or (fieldtype="Select" and options=%s)""", (doctype, "link:" + doctype))
    links += webnotes.conn.sql(
        """select dt, fieldname from `tabCustom Field`
		where (fieldtype="Link" and options=%s)
		or (fieldtype="Select" and options=%s)""", (doctype, "link:" + doctype))
Ejemplo n.º 7
0
			return doclist
		else:
			raise

	for r in res:
		custom_field = webnotes.model.doc.Document(fielddata=r)
		
		# convert to DocField
		custom_field.fields.update({
			'doctype': 'DocField',
			'parent': doctype,
			'parentfield': 'fields',
			'parenttype': 'DocType',
			'__custom_field': 1
		})
		doclist.append(custom_field)

	return doclist

def add_linked_with(doclist):
	"""add list of doctypes this doctype is 'linked' with"""
	doctype = doclist[0].name
	links = webnotes.conn.sql("""select parent, fieldname from tabDocField
		where (fieldtype="Link" and options=%s)
		or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype))
	links += webnotes.conn.sql("""select dt as parent, fieldname from `tabCustom Field`
		where (fieldtype="Link" and options=%s)
		or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype))

	links = dict(links)