From 89433b4bea0bc9dd86696356f7fb58f13a513798 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 30 Aug 2019 22:57:51 +0530 Subject: [PATCH] fix: get credit limit --- .../v12_0/move_credit_limit_to_customer_credit_limit.py | 4 ++-- erpnext/selling/doctype/customer/customer.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py b/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py index 3cfabe48ad..344dd82958 100644 --- a/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py +++ b/erpnext/patches/v12_0/move_credit_limit_to_customer_credit_limit.py @@ -18,8 +18,8 @@ def move_credit_limit_to_child_table(): ''' maps data from old field to the new field in the child table ''' credit_limit_data = frappe.db.sql(''' SELECT - name, credit_limit, - bypass_credit_limit_check_at_sales_order + name, credit_limit, + bypass_credit_limit_check_at_sales_order FROM `tabCustomer`''', as_dict=1) companies = frappe.get_all("Company", 'name') diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 3e9a824dae..940aa34e78 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -335,12 +335,13 @@ def get_credit_limit(customer, company): c.name = %s AND c.name = ccl.parent AND ccl.company = %s - """, (customer, company), as_dict=1) + """, (customer, company)) - credit_limit = credit_record.credit_limit + if credit_record: + customer_group, credit_limit = credit_record[0] - if not credit_limit: - credit_limit = frappe.get_cached_value("Customer Group", credit_record.customer_group, "credit_limit") + if not credit_limit and customer_group: + credit_limit = frappe.get_cached_value("Customer Group", customer_group, "credit_limit") if not credit_limit: credit_limit = frappe.get_cached_value('Company', company, "credit_limit")