如何在python中调用另一个函数内的函数(不在另一个函数中编写函数)。
class OrderDetails(Document):
def validate(self):
# Remove duplicates
found={}
#global nfound
i=-1
#msgprint(_("00000"))
#msgprint(_(found))
#frappe.errprint(found)
for selected in self.adding:
i=i+1
if selected.selected in found:
#frappe.throw(_("Duplicate {0}").format(i))
self.adding[found[selected.selected]].quantity = self.adding[found[selected.selected]].quantity + self.adding[i].quantity
self.adding[i].quantity = 0
self.adding[i].selected = 'product-04'
return edit_quantity_on_hand(selected.selected)
if selected.selected not in found:
found[selected.selected] = i
return edit_quantity_on_hand(selected.selected)
q='product-04'
frappe.db.sql("DELETE FROM `tabAdd to Order` WHERE selected = (%s);" ,(q))
def edit_quantity_on_hand(data):
quantity_on_hand_f = frappe.db.get_value("Product Details", data, "quantity_on_hand")
product_name_f = frappe.db.get_value("Product Details", data, "product_name")
if quantity_on_hand_f - self.adding[found[data]].quantity < 0:
frappe.throw(_("Quantity on Hand {0} is less than orderd amount ").format(quantity_on_hand_f))
else :
quantity_on_hand_f = quantity_on_hand_f - self.adding[found[data]].quantity
frappe.db.sql("Update `tabProduct Details` Set quantity_on_hand = (%s) Where product_name =(%s); ",(quantity_on_hand_f, product_name_f))
如何使用args在“validate()”函数中调用“edit_quantity_on_hand()”?
答案 0 :(得分:3)
由于您尚未将edit_quantity_on_hand
指定为静态方法,因此需要将其作为具有self.edit_quantity_on_hand
的实例方法引用。此外,该函数需要一个包含实例本身的参数 - 它具有此功能,但此时它是data
。请改用def edit_quantity_on_hand(self, data):
。
答案 1 :(得分:0)
有帮助吗?
def execute(func_name, *args, **kwargs):
return func_name(*args, **kwargs)