Пример #1
0
	def merge_warehouses(self):
		webnotes.conn.auto_commit_on_many_writes = 1
		
		# get items which dealt with current warehouse
		items = webnotes.conn.sql("select item_code from tabBin where warehouse=%s"	, self.doc.name)
		# delete old bins
		webnotes.conn.sql("delete from tabBin where warehouse=%s", self.doc.name)
		
		# replace link fields
		from webnotes.model import rename_doc
		link_fields = rename_doc.get_link_fields('Warehouse')
		rename_doc.update_link_field_values(link_fields, self.doc.name, self.doc.merge_with)
		
		account_link_fields = rename_doc.get_link_fields('Account')
		old_warehouse_account = webnotes.conn.get_value("Account", {"master_name": self.doc.name})
		new_warehouse_account = webnotes.conn.get_value("Account", 
			{"master_name": self.doc.merge_with})
		rename_doc.update_link_field_values(account_link_fields, old_warehouse_account, 
			new_warehouse_account)
			
		webnotes.conn.delete_doc("Account", old_warehouse_account)
		
		from utilities.repost_stock import repost
		for item_code in items:
			repost(item_code[0], self.doc.merge_with)
			
		webnotes.conn.auto_commit_on_many_writes = 0
		
		msgprint("Warehouse %s merged into %s. Now you can delete warehouse: %s" 
			% (self.doc.name, self.doc.merge_with, self.doc.name))
Пример #2
0
def check_if_doc_is_linked(dt, dn, method="Delete"):
    """
		Raises excption if the given doc(dt, dn) is linked in another record.
	"""
    from webnotes.model.rename_doc import get_link_fields

    link_fields = get_link_fields(dt)
    link_fields = [[lf["parent"], lf["fieldname"], lf["issingle"]] for lf in link_fields]

    for link_dt, link_field, issingle in link_fields:
        if not issingle:
            item = webnotes.conn.get_value(
                link_dt, {link_field: dn}, ["name", "parent", "parenttype", "docstatus"], as_dict=True
            )

            if (
                item
                and item.parent != dn
                and ((method == "Delete" and item.docstatus < 2) or (method == "Cancel" and item.docstatus == 1))
            ):
                webnotes.msgprint(
                    method
                    + " "
                    + _("Error")
                    + ":"
                    + ("%s (%s) " % (dn, dt))
                    + _("is linked in")
                    + (" %s (%s)") % (item.parent or item.name, item.parent and item.parenttype or link_dt),
                    raise_exception=LinkExistsError,
                )
Пример #3
0
def check_if_doc_is_linked(dt, dn):
    """
		Raises excption if the given doc(dt, dn) is linked in another record.
	"""
    sql = webnotes.conn.sql

    from webnotes.model.rename_doc import get_link_fields

    link_fields = get_link_fields(dt)
    link_fields = [[lf["parent"], lf["fieldname"]] for lf in link_fields]

    for l in link_fields:
        link_dt, link_field = l
        issingle = sql("select issingle from tabDocType where name = '%s'" % link_dt)

        # no such doctype (?)
        if not issingle:
            continue

        if issingle[0][0]:
            item = sql(
                "select doctype from `tabSingles` where field='%s' and value = '%s' and doctype = '%s' "
                % (link_field, dn, l[0])
            )
            if item:
                webnotes.msgprint(
                    "Cannot delete %s <b>%s</b> because it is linked in <b>%s</b>" % (dt, dn, item[0][0]),
                    raise_exception=1,
                )

        else:
            item = None
            try:
                # (ifnull(parent, '')='' or `%s`!=`parent`)
                # this condition ensures that it allows deletion when child table field references parent

                item = sql(
                    "select name, parent, parenttype from `tab%s` where `%s`='%s' and docstatus!=2 and (ifnull(parent, '')='' or `%s`!=`parent`) \
					limit 1"
                    % (link_dt, link_field, dn, link_field)
                )

            except Exception, e:
                if e.args[0] == 1146:
                    pass
                else:
                    raise e
            if item:
                webnotes.msgprint(
                    "Cannot delete %s <b>%s</b> because it is linked in %s <b>%s</b>"
                    % (dt, dn, item[0][2] or link_dt, item[0][1] or item[0][0]),
                    raise_exception=1,
                )
Пример #4
0
    def merge_warehouses(self):
        webnotes.conn.auto_commit_on_many_writes = 1

        # get items which dealt with current warehouse
        items = webnotes.conn.sql(
            "select item_code from tabBin where warehouse=%s", self.doc.name)
        # delete old bins
        webnotes.conn.sql("delete from tabBin where warehouse=%s",
                          self.doc.name)

        # replace link fields
        from webnotes.model import rename_doc
        link_fields = rename_doc.get_link_fields('Warehouse')
        rename_doc.update_link_field_values(link_fields, self.doc.name,
                                            self.doc.merge_with)

        account_link_fields = rename_doc.get_link_fields('Account')
        old_warehouse_account = webnotes.conn.get_value(
            "Account", {"master_name": self.doc.name})
        new_warehouse_account = webnotes.conn.get_value(
            "Account", {"master_name": self.doc.merge_with})
        rename_doc.update_link_field_values(account_link_fields,
                                            old_warehouse_account,
                                            new_warehouse_account)

        webnotes.conn.delete_doc("Account", old_warehouse_account)

        from utilities.repost_stock import repost
        for item_code in items:
            repost(item_code[0], self.doc.merge_with)

        webnotes.conn.auto_commit_on_many_writes = 0

        msgprint(
            "Warehouse %s merged into %s. Now you can delete warehouse: %s" %
            (self.doc.name, self.doc.merge_with, self.doc.name))
Пример #5
0
def check_if_doc_is_linked(dt, dn, method="Delete"):
	"""
		Raises excption if the given doc(dt, dn) is linked in another record.
	"""
	from webnotes.model.rename_doc import get_link_fields
	link_fields = get_link_fields(dt)
	link_fields = [[lf['parent'], lf['fieldname'], lf['issingle']] for lf in link_fields]

	for link_dt, link_field, issingle in link_fields:
		if not issingle:
			item = webnotes.conn.get_value(link_dt, {link_field:dn}, 
				["name", "parent", "parenttype", "docstatus"], as_dict=True)
			
			if item and item.parent != dn and (method=="Delete" or 
					(method=="Cancel" and item.docstatus==1)):
				webnotes.msgprint(method + " " + _("Error") + ":"+\
					("%s (%s) " % (dn, dt)) + _("is linked in") + (" %s (%s)") % 
					(item.parent or item.name, item.parent and item.parenttype or link_dt),
					raise_exception=LinkExistsError)
Пример #6
0
	def merge_warehouses(self):
		webnotes.conn.auto_commit_on_many_writes = 1
		
		# get items which dealt with current warehouse
		items = webnotes.conn.sql("select item_code from tabBin where warehouse=%s"	, self.doc.name)
		# delete old bins
		webnotes.conn.sql("delete from tabBin where warehouse=%s", self.doc.name)
		
		# replace link fields
		from webnotes.model import rename_doc
		link_fields = rename_doc.get_link_fields('Warehouse')
		rename_doc.update_link_field_values(link_fields, self.doc.name, self.doc.merge_with)
		
		for item_code in items:
			self.repost(item_code[0], self.doc.merge_with)
			
		webnotes.conn.auto_commit_on_many_writes = 0
		
		msgprint("Warehouse %s merged into %s. Now you can delete warehouse: %s" 
			% (self.doc.name, self.doc.merge_with, self.doc.name))
Пример #7
0
	def merge_warehouses(self):
		webnotes.conn.auto_commit_on_many_writes = 1
		
		# get items which dealt with current warehouse
		items = webnotes.conn.sql("select item_code from tabBin where warehouse=%s"	, self.doc.name)
		# delete old bins
		webnotes.conn.sql("delete from tabBin where warehouse=%s", self.doc.name)
		
		# replace link fields
		from webnotes.model import rename_doc
		link_fields = rename_doc.get_link_fields('Warehouse')
		rename_doc.update_link_field_values(link_fields, self.doc.name, self.doc.merge_with)
		
		for item_code in items:
			self.repost(item_code[0], self.doc.merge_with)
			
		webnotes.conn.auto_commit_on_many_writes = 0
		
		msgprint("Warehouse %s merged into %s. Now you can delete warehouse: %s" 
			% (self.doc.name, self.doc.merge_with, self.doc.name))
Пример #8
0
def check_if_doc_is_linked(dt, dn, method="Delete"):
	"""
		Raises excption if the given doc(dt, dn) is linked in another record.
	"""
	sql = webnotes.conn.sql

	from webnotes.model.rename_doc import get_link_fields
	link_fields = get_link_fields(dt)
	link_fields = [[lf['parent'], lf['fieldname']] for lf in link_fields]

	for l in link_fields:
		link_dt, link_field = l

		item = webnotes.conn.get_value(link_dt, {link_field:dn}, ["name", "parent", "parenttype",
			"docstatus"])
		
		if (method=="Delete" and item) or (method=="Cancel" and item and item[3]==1):
			webnotes.msgprint(method + " " + _("Error") + ":"+\
				("%s (%s) " % (dn, dt)) + _("is linked in") + (" %s (%s)") % (item[1] or item[0], 
					item[1] and item[2] or link_dt),
				raise_exception=LinkExistsError)