Update sales_invoice.py
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index ab44247..14a1207 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -444,15 +444,17 @@
msgprint("Customer %s does not match with customer of %s: %s." %(self.doc.customer, dt, dt_no), raise_exception=1)
- def validate_customer_account(self):
- """Validates Debit To Account and Customer Matches"""
- if self.doc.customer and self.doc.debit_to and not cint(self.doc.is_pos):
- acc_head = webnotes.conn.sql("select master_name from `tabAccount` where name = %s and docstatus != 2", self.doc.debit_to)
-
- if (acc_head and cstr(acc_head[0][0]) != cstr(self.doc.customer)) or \
- (not acc_head and (self.doc.debit_to != cstr(self.doc.customer) + " - " + self.get_company_abbr())):
- msgprint("Debit To: %s do not match with Customer: %s for Company: %s.\n If both correctly entered, please select Master Type \
- and Master Name in account master." %(self.doc.debit_to, self.doc.customer,self.doc.company), raise_exception=1)
+ def validate_customer(self):
+ """ Validate customer name with SO and DN"""
+ if self.doc.customer:
+ for d in getlist(self.doclist,'entries'):
+ dt = d.delivery_note and 'Delivery Note' or d.sales_order and 'Sales Order' or ''
+ if dt:
+ dt_no = d.delivery_note or d.sales_order
+ cust = webnotes.conn.get_value(dt, dt_no, "customer")
+ if cust and cstr(cust) != cstr(self.doc.customer):
+ msgprint("Customer %s does not match with customer of %s: %s."
+ %(self.doc.customer, dt, dt_no), raise_exception=1)
def validate_debit_acc(self):