From 3b8d4776a23392b3b8d8c9f53c0a65d9df1921ab Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 18 May 2012 18:36:56 +0530 Subject: [PATCH] company validation --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 5f09a432d1f..7aa80110d8b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -98,7 +98,13 @@ class DocType(TransactionBase): # Get Account Head to which amount needs to be Debited based on Customer # ---------------------------------------------------------------------- def get_customer_account(self): - acc_head = webnotes.conn.sql("select name from `tabAccount` where (name = %s or (master_name = %s and master_type = 'customer')) and docstatus != 2", (cstr(self.doc.customer) + " - " + self.get_company_abbr(),self.doc.customer)) + if not self.doc.company: + msgprint("Please select company first and re-select the customer after doing so", raise_exception=1) + + acc_head = webnotes.conn.sql("""select name from `tabAccount` + where (name = %s or (master_name = %s and master_type = 'customer')) and docstatus != 2""", + (cstr(self.doc.customer) + " - " + self.get_company_abbr(),self.doc.customer)) + if acc_head and acc_head[0][0]: return acc_head[0][0] else: