From dd2ec1796229cce53ded01dde0351f0a6381e122 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 13 Aug 2013 13:57:53 +0530 Subject: [PATCH] [fix] [minor] pull credit days from customer, update credit days in account of customer --- accounts/doctype/sales_invoice/sales_invoice.py | 8 +++++--- selling/doctype/customer/customer.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 87afd74d08a..c9059cca598 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -250,10 +250,15 @@ class DocType(SellingController): def get_cust_and_due_date(self): """Set Due Date = Posting Date + Credit Days""" + if self.doc.debit_to: + self.doc.customer = webnotes.conn.get_value('Account', self.doc.debit_to, 'master_name') + if self.doc.posting_date: credit_days = 0 if self.doc.debit_to: credit_days = webnotes.conn.get_value("Account", self.doc.debit_to, "credit_days") + if self.doc.customer and not credit_days: + credit_days = webnotes.conn.get_value("Customer", self.doc.customer, "credit_days") if self.doc.company and not credit_days: credit_days = webnotes.conn.get_value("Company", self.doc.company, "credit_days") @@ -261,9 +266,6 @@ class DocType(SellingController): self.doc.due_date = add_days(self.doc.posting_date, credit_days) else: self.doc.due_date = self.doc.posting_date - - if self.doc.debit_to: - self.doc.customer = webnotes.conn.get_value('Account',self.doc.debit_to,'master_name') def get_barcode_details(self, barcode): return get_obj('Sales Common').get_barcode_details(barcode) diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index f516ef2495d..2eabf12ddec 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -77,9 +77,9 @@ class DocType(TransactionBase): msgprint("Please Select Company under which you want to create account head") def update_credit_days_limit(self): - sql("""update tabAccount set credit_days = %s, credit_limit = %s - where name = %s""", (self.doc.credit_days or 0, self.doc.credit_limit or 0, - self.doc.name + " - " + self.get_company_abbr())) + webnotes.conn.sql("""update tabAccount set credit_days = %s, credit_limit = %s + where master_type='Customer' and master_name = %s""", + (self.doc.credit_days or 0, self.doc.credit_limit or 0, self.doc.name)) def create_lead_address_contact(self): if self.doc.lead_name: