refactored customer and supplier details fetch for sales and purchase return stock entry

This commit is contained in:
Anand Doshi 2012-11-19 13:59:25 +05:30
parent 45fd518ed0
commit f26511e466

View File

@ -510,16 +510,19 @@ class DocType(TransactionBase):
def get_cust_values(self): def get_cust_values(self):
tbl = self.doc.delivery_note_no and 'Delivery Note' or 'Sales Invoice' """fetches customer details"""
record_name = self.doc.delivery_note_no or self.doc.sales_invoice_no if self.doc.delivery_note_no:
res = sql("select customer,customer_name, customer_address from `tab%s` where name = '%s'" % (tbl, record_name)) doctype = "Delivery Note"
ret = { name = self.doc.delivery_note_no
'customer' : res and res[0][0] or '', else:
'customer_name' : res and res[0][1] or '', doctype = "Sales Invoice"
'customer_address' : res and res[0][2] or ''} name = self.doc.sales_invoice_no
return ret result = webnotes.conn.sql("""select customer, customer_name,
address_display as customer_address
from `tab%s` where name=%s""" % (doctype, "%s"), (name,), as_dict=1)
return result and result[0] or {}
def get_cust_addr(self): def get_cust_addr(self):
res = sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer) res = sql("select customer_name from `tabCustomer` where name = '%s'"%self.doc.customer)
@ -530,16 +533,13 @@ class DocType(TransactionBase):
return ret return ret
def get_supp_values(self): def get_supp_values(self):
res = sql("select supplier,supplier_name,supplier_address from `tabPurchase Receipt` where name = '%s'"%self.doc.purchase_receipt_no) result = webnotes.conn.sql("""select supplier, supplier_name,
ret = { address_display as supplier_address
'supplier' : res and res[0][0] or '', from `tabPurchase Receipt` where name=%s""", (self.doc.purchase_receipt_no,),
'supplier_name' :res and res[0][1] or '', as_dict=1)
'supplier_address' : res and res[0][2] or ''}
return ret
return result and result[0] or {}
def get_supp_addr(self): def get_supp_addr(self):
res = sql("select supplier_name,address from `tabSupplier` where name = '%s'"%self.doc.supplier) res = sql("select supplier_name,address from `tabSupplier` where name = '%s'"%self.doc.supplier)