2016-07-04 20 views
-4

他の関数の中で関数を呼び出す方法(別の関数内で関数を書くのではなく)。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()」を呼び出すにはどうすればよいですか?

答えて

3

edit_quantity_on_handを静的メソッドとして指定していないため、self.edit_quantity_on_handをインスタンスメソッドとして参照する必要があります。また、その関数にはインスタンス自体を含むパラメータが必要ですが、それは現時点ではdataです。代わりにdef edit_quantity_on_hand(self, data):を使用してください。

関連する問題