예제 #1
0
	def set_doclist(self, docs):
		for i, d in enumerate(docs):
			if isinstance(d, dict):
				docs[i] = Document(fielddata=d)
		
		self.docs = self.doclist = webnotes.doclist(docs)
		self.doc, self.children = docs[0], webnotes.doclist(docs[1:])
		if self.obj:
			self.obj.doclist = self.doclist
			self.obj.doc = self.doc
예제 #2
0
    def set_doclist(self, docs):
        for i, d in enumerate(docs):
            if isinstance(d, dict):
                docs[i] = Document(fielddata=d)

        self.docs = self.doclist = webnotes.doclist(docs)
        self.doc, self.children = docs[0], webnotes.doclist(docs[1:])
        if self.obj:
            self.obj.doclist = self.doclist
            self.obj.doc = self.doc
예제 #3
0
	def add_communication_list(self):
		# remove communications if present
		self.doclist = webnotes.doclist(self.doclist).get({"doctype": ["!=", "Communcation"]})
		
		comm_list = webnotes.conn.sql("""select * from tabCommunication 
			where support_ticket=%s order by modified desc limit 20""", self.doc.name, as_dict=1)
		
		[d.update({"doctype":"Communication"}) for d in comm_list]
		
		self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
			for d in comm_list]))
예제 #4
0
    def add_communication_list(self):
        # remove communications if present
        self.doclist = webnotes.doclist(self.doclist).get(
            {"doctype": ["!=", "Communcation"]})

        comm_list = webnotes.conn.sql("""select * from tabCommunication 
			where %s=%s order by modified desc limit 20""" \
         % (self.doc.doctype.replace(" ", "_").lower(), "%s"),
         self.doc.name, as_dict=1, update={"doctype":"Communication"})

        self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
         for d in comm_list]))
예제 #5
0
	def add_communication_list(self):
		# remove communications if present
		self.doclist = webnotes.doclist(self.doclist).get({
			"doctype": ["!=", "Communcation"]})
		
		comm_list = webnotes.conn.sql("""select * from tabCommunication 
			where %s=%s order by modified desc limit 20""" \
			% (self.doc.doctype.replace(" ", "_").lower(), "%s"),
			self.doc.name, as_dict=1, update={"doctype":"Communication"})
		
		self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
			for d in comm_list]))
예제 #6
0
	def post(self):
		"""
			Save diff between Customize Form Bean and DocType Bean as property setter entries
		"""
		if self.doc.doc_type:
			from webnotes.model import doc
			from webnotes.core.doctype.doctype.doctype import validate_fields_for_doctype
			
			this_doclist = webnotes.doclist([self.doc] + self.doclist)
			ref_doclist = self.get_ref_doclist()
			dt_doclist = doc.get('DocType', self.doc.doc_type)
			
			# get a list of property setter docs
			self.idx_dirty = False
			diff_list = self.diff(this_doclist, ref_doclist, dt_doclist)
			
			if self.idx_dirty:
				self.make_idx_property_setter(this_doclist, diff_list)
			
			self.set_properties(diff_list)

			validate_fields_for_doctype(self.doc.doc_type)

			webnotes.clear_cache(doctype=self.doc.doc_type)
			webnotes.msgprint("Updated")
예제 #7
0
    def load_from_db(self, dt=None, dn=None):
        """
			Load doclist from dt
		"""
        from webnotes.model.doc import getchildren

        if not dt: dt = self.doc.doctype
        if not dn: dn = self.doc.name

        doc = Document(dt, dn)

        # get all children types
        tablefields = webnotes.model.meta.get_table_fields(dt)

        # load chilren
        doclist = webnotes.doclist([
            doc,
        ])
        for t in tablefields:
            doclist += getchildren(doc.name, t[0], t[1], dt)

        self.set_doclist(doclist)

        if dt == dn:
            self.convert_type(self.doc)
예제 #8
0
def make_test_objects(doctype, test_records, verbose=None):
    records = []

    for doclist in test_records:
        if not "doctype" in doclist[0]:
            doclist[0]["doctype"] = doctype
        d = webnotes.bean((webnotes.doclist(doclist)).copy())
        if webnotes.test_objects.get(d.doc.doctype):
            # do not create test records, if already exists
            return []
        if has_field(d.doc.doctype, "naming_series"):
            if not d.doc.naming_series:
                d.doc.naming_series = "_T-" + d.doc.doctype + "-"

        # submit if docstatus is set to 1 for test record
        docstatus = d.doc.docstatus

        d.doc.docstatus = 0
        d.insert()

        if docstatus == 1:
            d.submit()

        records.append(d.doc.name)
    return records
예제 #9
0
    def load_from_db(self, dt=None, dn=None, prefix="tab"):
        """
			Load doclist from dt
		"""
        from webnotes.model.doc import getchildren

        if not dt:
            dt = self.doc.doctype
        if not dn:
            dn = self.doc.name

        doc = Document(dt, dn, prefix=prefix)

        # get all children types
        tablefields = webnotes.model.meta.get_table_fields(dt)

        # load chilren
        doclist = webnotes.doclist([doc])
        for t in tablefields:
            doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)

        self.set_doclist(doclist)

        if dt == dn:
            self.convert_type(self.doc)
예제 #10
0
def make_test_objects(doctype, test_records, verbose=None):
	records = []
		
	for doclist in test_records:
		if not "doctype" in doclist[0]:
			doclist[0]["doctype"] = doctype
		d = webnotes.bean((webnotes.doclist(doclist)).copy())
		if webnotes.test_objects.get(d.doc.doctype):
			# do not create test records, if already exists
			return []
		if has_field(d.doc.doctype, "naming_series"):
			if not d.doc.naming_series:
				d.doc.naming_series = "_T-" + d.doc.doctype + "-"

		# submit if docstatus is set to 1 for test record
		docstatus = d.doc.docstatus
		
		d.doc.docstatus = 0
		d.insert()

		if docstatus == 1:
			d.submit()
		
		records.append(d.doc.name)
	return records
예제 #11
0
def row_exists_in_target(parentfield, target_doclist):
	global row_exists_for_parentfield
	
	if parentfield not in row_exists_for_parentfield:
		row_exists_for_parentfield[parentfield] = True if \
			webnotes.doclist(target_doclist).get({"parentfield": parentfield}) else False

	return row_exists_for_parentfield[parentfield]
예제 #12
0
def row_exists_in_target(parentfield, target_doclist):
	global row_exists_for_parentfield
	
	if parentfield not in row_exists_for_parentfield:
		row_exists_for_parentfield[parentfield] = True if \
			webnotes.doclist(target_doclist).get({"parentfield": parentfield}) else False

	return row_exists_for_parentfield[parentfield]
예제 #13
0
def get_mapped_doclist(from_doctype, from_docname, table_maps, target_doclist=[], 
		postprocess=None, ignore_permissions=False):
	if isinstance(target_doclist, basestring):
		target_doclist = json.loads(target_doclist)
	
	source = webnotes.bean(from_doctype, from_docname)

	if not ignore_permissions and not webnotes.has_permission(from_doctype, "read", source.doc):
		webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)

	source_meta = webnotes.get_doctype(from_doctype)
	target_meta = webnotes.get_doctype(table_maps[from_doctype]["doctype"])
	
	# main
	if target_doclist:
		if isinstance(target_doclist[0], dict):
			target_doc = webnotes.doc(fielddata=target_doclist[0])
		else:
			target_doc = target_doclist[0]
	else:
		target_doc = webnotes.new_doc(table_maps[from_doctype]["doctype"])
	
	map_doc(source.doc, target_doc, table_maps[source.doc.doctype], source_meta, target_meta)
	if target_doclist:
		target_doclist[0] = target_doc
	else:
		target_doclist = [target_doc]
	
	# children
	for source_d in source.doclist[1:]:
		table_map = table_maps.get(source_d.doctype)
		if table_map:
			if "condition" in table_map:
				if not table_map["condition"](source_d):
					continue
			target_doctype = table_map["doctype"]
			parentfield = target_meta.get({
					"parent": target_doc.doctype, 
					"doctype": "DocField",
					"fieldtype": "Table", 
					"options": target_doctype
				})[0].fieldname
			
			if table_map.get("add_if_empty") and row_exists_in_target(parentfield, target_doclist):
				continue
		
			target_d = webnotes.new_doc(target_doctype, target_doc, parentfield)
			map_doc(source_d, target_d, table_map, source_meta, target_meta, source.doclist[0])
			target_doclist.append(target_d)
	
	target_doclist = webnotes.doclist(target_doclist)
	
	if postprocess:
		new_target_doclist = postprocess(source, target_doclist)
		if new_target_doclist:
			target_doclist = new_target_doclist
	
	return target_doclist
예제 #14
0
    def set_doclist(self, doclist):
        for i, d in enumerate(doclist):
            if isinstance(d, dict):
                doclist[i] = Document(fielddata=d)

        self.doclist = webnotes.doclist(doclist)
        self.doc = self.doclist[0]
        if self.obj:
            self.obj.doclist = self.doclist
            self.obj.doc = self.doc
예제 #15
0
	def set_doclist(self, doclist):
		for i, d in enumerate(doclist):
			if isinstance(d, dict):
				doclist[i] = Document(fielddata=d)
		
		self.doclist = webnotes.doclist(doclist)
		self.doc = self.doclist[0]
		if self.obj:
			self.obj.doclist = self.doclist
			self.obj.doc = self.doc
예제 #16
0
	def cleanup_raw_materials_supplied(self, parent_items, raw_material_table):
		"""Remove all those child items which are no longer present in main item table"""
		delete_list = []
		for d in self.doclist.get({"parentfield": raw_material_table}):
			if [d.main_item_code, d.reference_name] not in parent_items:
				# mark for deletion from doclist
				delete_list.append([d.main_item_code, d.reference_name])

		# delete from doclist
		self.doclist = webnotes.doclist(filter(lambda d: [d.main_item_code, d.reference_name]
			not in delete_list, self.doclist))
예제 #17
0
    def get_ref_doclist(self):
        """
			* Gets doclist of type self.doc.doc_type
			* Applies property setter properties on the doclist
			* returns the modified doclist
		"""
        from webnotes.model.doctype import get

        ref_doclist = get(self.doc.doc_type)
        ref_doclist = webnotes.doclist([ref_doclist[0]] + ref_doclist.get({"parent": self.doc.doc_type}))

        return ref_doclist
예제 #18
0
    def cleanup_raw_materials_supplied(self, parent_items, raw_material_table):
        """Remove all those child items which are no longer present in main item table"""
        delete_list = []
        for d in self.doclist.get({"parentfield": raw_material_table}):
            if [d.main_item_code, d.reference_name] not in parent_items:
                # mark for deletion from doclist
                delete_list.append([d.main_item_code, d.reference_name])

        # delete from doclist
        self.doclist = webnotes.doclist(
            filter(
                lambda d: [d.main_item_code, d.reference_name] not in
                delete_list, self.doclist))
예제 #19
0
    def get_ref_doclist(self):
        """
			* Gets doclist of type self.doc.doc_type
			* Applies property setter properties on the doclist
			* returns the modified doclist
		"""
        from webnotes.model.doctype import get

        ref_doclist = get(self.doc.doc_type)
        ref_doclist = webnotes.doclist(
            [ref_doclist[0]] + ref_doclist.get({"parent": self.doc.doc_type}))

        return ref_doclist
예제 #20
0
def cleanup_packing_list(obj, parent_items):
	"""Remove all those child items which are no longer present in main item table"""
	delete_list = []
	for d in obj.doclist.get({"parentfield": "packing_details"}):
		if [d.parent_item, d.parent_detail_docname] not in parent_items:
			# mark for deletion from doclist
			delete_list.append([d.parent_item, d.parent_detail_docname])

	if not delete_list:
		return obj.doclist
	
	# delete from doclist
	obj.doclist = webnotes.doclist(filter(lambda d: [d.parent_item, d.parent_detail_docname] 
		not in delete_list, obj.doclist))
		
	return obj.doclist
예제 #21
0
def make_test_objects(doctype, test_records):		
	records = []
		
	for doclist in test_records:
		if not "doctype" in doclist[0]:
			doclist[0]["doctype"] = doctype
		d = webnotes.model_wrapper((webnotes.doclist(doclist)).copy())
		if webnotes.test_objects.get(d.doc.doctype):
			# do not create test records, if already exists
			return []
		if has_field(d.doc.doctype, "naming_series"):
			if not d.doc.naming_series:
				d.doc.naming_series = "_T-" + d.doc.doctype + "-"

		d.insert()
		records.append(d.doc.name)
	return records
예제 #22
0
def cleanup_packing_list(obj, parent_items):
    """Remove all those child items which are no longer present in main item table"""
    delete_list = []
    for d in obj.doclist.get({"parentfield": "packing_details"}):
        if [d.parent_item, d.parent_detail_docname] not in parent_items:
            # mark for deletion from doclist
            delete_list.append([d.parent_item, d.parent_detail_docname])

    if not delete_list:
        return obj.doclist

    # delete from doclist
    obj.doclist = webnotes.doclist(
        filter(
            lambda d: [d.parent_item, d.parent_detail_docname] not in
            delete_list, obj.doclist))

    return obj.doclist
예제 #23
0
	def load_from_db(self, dt=None, dn=None, prefix='tab'):
		
		from webnotes.model.doc import Document, getchildren

		if not dt: dt = self.doc.doctype
		if not dn: dn = self.doc.name

		doc = Document(dt, dn, prefix=prefix)

		# get all children types
		tablefields = webnotes.model.meta.get_table_fields(dt)

		# load chilren
		doclist = webnotes.doclist([doc,])
		for t in tablefields:
			doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)

		self.set_doclist(doclist)
		self.run_method("onload")
예제 #24
0
def make_purchase_order_based_on_supplier(source_name, target_doclist=None):
    from webnotes.model.mapper import get_mapped_doclist
    if target_doclist:
        if isinstance(target_doclist, basestring):
            import json
            target_doclist = webnotes.doclist(json.loads(target_doclist))
        target_doclist = target_doclist.get(
            {"parentfield": ["!=", "po_details"]})

    material_requests, supplier_items = get_material_requests_based_on_supplier(
        source_name)

    def postprocess(source, target_doclist):
        target_doclist[0].supplier = source_name
        set_missing_values(source, target_doclist)

        po_items = target_doclist.get({"parentfield": "po_details"})
        target_doclist = target_doclist.get({"parentfield": ["!=", "po_details"]}) + \
         [d for d in po_items
          if d.fields.get("item_code") in supplier_items and d.fields.get("qty") > 0]

        return target_doclist

    for mr in material_requests:
        target_doclist = get_mapped_doclist(
            "Material Request", mr, {
                "Material Request": {
                    "doctype": "Purchase Order",
                },
                "Material Request Item": {
                    "doctype":
                    "Purchase Order Item",
                    "field_map": [["name", "prevdoc_detail_docname"],
                                  ["parent", "prevdoc_docname"],
                                  ["parenttype", "prevdoc_doctype"],
                                  ["uom", "stock_uom"], ["uom", "uom"]],
                    "postprocess":
                    update_item
                }
            }, target_doclist, postprocess)

    return [d.fields for d in target_doclist]
	def post(self):
		"""
			Save diff between Customize Form ModelWrapper and DocType ModelWrapper as property setter entries
		"""
		if self.doc.doc_type:
			from webnotes.model import doc
			from core.doctype.doctype.doctype import validate_fields_for_doctype
			
			this_doclist = webnotes.doclist([self.doc] + self.doclist)
			ref_doclist = self.get_ref_doclist()
			dt_doclist = doc.get('DocType', self.doc.doc_type)
			
			# get a list of property setter docs
			diff_list = self.diff(this_doclist, ref_doclist, dt_doclist)
			
			self.set_properties(diff_list)

			validate_fields_for_doctype(self.doc.doc_type)

			webnotes.clear_cache(doctype=self.doc.doc_type)
예제 #26
0
	def post(self):
		"""
			Save diff between Customize Form ModelWrapper and DocType ModelWrapper as property setter entries
		"""
		if self.doc.doc_type:
			from webnotes.model import doc
			from core.doctype.doctype.doctype import validate_fields_for_doctype
			
			this_doclist = webnotes.doclist([self.doc] + self.doclist)
			ref_doclist = self.get_ref_doclist()
			dt_doclist = doc.get('DocType', self.doc.doc_type)
			
			# get a list of property setter docs
			diff_list = self.diff(this_doclist, ref_doclist, dt_doclist)
			
			self.set_properties(diff_list)

			validate_fields_for_doctype(self.doc.doc_type)

			webnotes.clear_cache(doctype=self.doc.doc_type)
예제 #27
0
def make_purchase_order_based_on_supplier(source_name, target_doclist=None):
	from webnotes.model.mapper import get_mapped_doclist
	if target_doclist:
		if isinstance(target_doclist, basestring):
			import json
			target_doclist = webnotes.doclist(json.loads(target_doclist))
		target_doclist = target_doclist.get({"parentfield": ["!=", "po_details"]})
		
	material_requests, supplier_items = get_material_requests_based_on_supplier(source_name)
	
	def postprocess(source, target_doclist):
		target_doclist[0].supplier = source_name
		set_missing_values(source, target_doclist)
		
		po_items = target_doclist.get({"parentfield": "po_details"})
		target_doclist = target_doclist.get({"parentfield": ["!=", "po_details"]}) + \
			[d for d in po_items 
				if d.fields.get("item_code") in supplier_items and d.fields.get("qty") > 0]
		
		return target_doclist
		
	for mr in material_requests:
		target_doclist = get_mapped_doclist("Material Request", mr, 	{
			"Material Request": {
				"doctype": "Purchase Order", 
			}, 
			"Material Request Item": {
				"doctype": "Purchase Order Item", 
				"field_map": [
					["name", "prevdoc_detail_docname"], 
					["parent", "prevdoc_docname"], 
					["parenttype", "prevdoc_doctype"], 
					["uom", "stock_uom"],
					["uom", "uom"]
				],
				"postprocess": update_item
			}
		}, target_doclist, postprocess)
	
	return [d.fields for d in target_doclist]
예제 #28
0
def cleanup_packing_list(obj, parent_items):
	"""Remove all those child items which are no longer present in main item table"""
	delete_list = []
	for d in obj.doclist.get({"parentfield": "packing_details"}):
		if [d.parent_item, d.parent_detail_docname] not in parent_items:
			# mark for deletion from doclist
			delete_list.append(d.name)

	if not delete_list:
		return obj.doclist
	
	# delete from doclist
	obj.doclist = webnotes.doclist(filter(lambda d: d.name not in delete_list, obj.doclist))
	
	# delete from db
	webnotes.conn.sql("""\
		delete from `tabPacked Item`
		where name in (%s)"""
		% (", ".join(["%s"] * len(delete_list))),
		tuple(delete_list))
		
	return obj.doclist
예제 #29
0
	def cleanup_packing_list(self, obj, parent_items):
		"""Remove all those child items which are no longer present in main item table"""
		delete_list = []
		for d in getlist(obj.doclist, 'packing_details'):
			if [d.parent_item, d.parent_detail_docname] not in parent_items:
				# mark for deletion from doclist
				delete_list.append(d.name)

		if not delete_list:
			return obj.doclist
		
		# delete from doclist
		obj.doclist = webnotes.doclist(filter(lambda d: d.name not in delete_list, obj.doclist))
		
		# delete from db
		webnotes.conn.sql("""\
			delete from `tabDelivery Note Packing Item`
			where name in (%s)"""
			% (", ".join(["%s"] * len(delete_list))),
			tuple(delete_list))
			
		return obj.doclist
예제 #30
0
    def load_from_db(self, dt=None, dn=None, prefix='tab'):
        """
			Load doclist from dt
		"""
        from webnotes.model.doc import Document, getchildren

        if not dt: dt = self.doc.doctype
        if not dn: dn = self.doc.name

        doc = Document(dt, dn, prefix=prefix)

        # get all children types
        tablefields = webnotes.model.meta.get_table_fields(dt)

        # load chilren
        doclist = webnotes.doclist([
            doc,
        ])
        for t in tablefields:
            doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)

        self.set_doclist(doclist)
        self.run_method("onload")
예제 #31
0
파일: doc.py 프로젝트: appost/wnframework
	def clear_table(self, doclist, tablefield, save=0):
		"""
		Clears the child records from the given `doclist` for a particular `tablefield`
		"""
		from webnotes.model.utils import getlist
		
		table_list = getlist(doclist, tablefield)
				
		delete_list = [d.name for d in table_list]
		
		if delete_list:
			#filter doclist
			doclist = filter(lambda d: d.name not in delete_list, doclist)
		
			# delete from db
			webnotes.conn.sql("""\
				delete from `tab%s`
				where parent=%s and parenttype=%s"""
				% (table_list[0].doctype, '%s', '%s'),
				(self.name, self.doctype))

			self.fields['__unsaved'] = 1
		
		return webnotes.doclist(doclist)
예제 #32
0
    def clear_table(self, doclist, tablefield, save=0):
        """
		Clears the child records from the given `doclist` for a particular `tablefield`
		"""
        from webnotes.model.utils import getlist

        table_list = getlist(doclist, tablefield)

        delete_list = [d.name for d in table_list]

        if delete_list:
            #filter doclist
            doclist = filter(lambda d: d.name not in delete_list, doclist)

            # delete from db
            webnotes.conn.sql(
                """\
				delete from `tab%s`
				where parent=%s and parenttype=%s""" % (table_list[0].doctype, '%s', '%s'),
                (self.name, self.doctype))

            self.fields['__unsaved'] = 1

        return webnotes.doclist(doclist)
예제 #33
0
 def get_parent_doclist(self):
     return webnotes.doclist([self[0]] + self.get({"parent": self[0].name}))
예제 #34
0
def get_mapped_doclist(from_doctype, from_docname, table_maps, target_doclist=None, 
		postprocess=None, ignore_permissions=False):
	if target_doclist is None:
		target_doclist = []
		
	if isinstance(target_doclist, basestring):
		target_doclist = json.loads(target_doclist)
	
	source = webnotes.bean(from_doctype, from_docname)

	if not ignore_permissions and not webnotes.has_permission(from_doctype, "read", source.doc):
		webnotes.msgprint("No Permission", raise_exception=webnotes.PermissionError)

	source_meta = webnotes.get_doctype(from_doctype)
	target_meta = webnotes.get_doctype(table_maps[from_doctype]["doctype"])
	
	# main
	if target_doclist:
		if isinstance(target_doclist[0], dict):
			target_doc = webnotes.doc(fielddata=target_doclist[0])
		else:
			target_doc = target_doclist[0]
	else:
		target_doc = webnotes.new_doc(table_maps[from_doctype]["doctype"])
	
	map_doc(source.doc, target_doc, table_maps[source.doc.doctype], source_meta, target_meta)
	if target_doclist:
		target_doclist[0] = target_doc
	else:
		target_doclist = [target_doc]
	
	target_doclist = webnotes.doclist(target_doclist)
	
	# children
	for source_d in source.doclist[1:]:
		table_map = table_maps.get(source_d.doctype)
		if table_map:
			if "condition" in table_map:
				if not table_map["condition"](source_d):
					continue
			target_doctype = table_map["doctype"]
			parentfield = target_meta.get({
					"parent": target_doc.doctype, 
					"doctype": "DocField",
					"fieldtype": "Table", 
					"options": target_doctype
				})[0].fieldname
			
			if table_map.get("add_if_empty") and row_exists_in_target(parentfield, target_doclist):
				continue
		
			target_d = webnotes.new_doc(target_doctype, target_doc, parentfield)
			map_doc(source_d, target_d, table_map, source_meta, target_meta, source.doclist[0])
			target_d.idx = None
			target_doclist.append(target_d)

	target_doclist = webnotes.doclist(target_doclist)
	
	if postprocess:
		new_target_doclist = postprocess(source, target_doclist)
		if new_target_doclist:
			target_doclist = new_target_doclist
	
	return target_doclist
예제 #35
0
	def get_parent_doclist(self):
		return webnotes.doclist([self[0]] + self.get({"parent": self[0].name}))