diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 907964720ff..de34a879db7 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -152,7 +152,7 @@ def set_contact_details(party_details, party, party_type): def set_other_values(party_details, party, party_type): # copy - if party_type=="Customer": + if party_type == "Customer": to_copy = ["customer_name", "customer_group", "territory", "language"] else: to_copy = ["supplier_name", "supplier_group", "language"] @@ -171,12 +171,8 @@ def get_default_price_list(party): return party.default_price_list if party.doctype == "Customer": - price_list = frappe.get_cached_value("Customer Group", - party.customer_group, "default_price_list") - if price_list: - return price_list + return frappe.db.get_value("Customer Group", party.customer_group, "default_price_list") - return None def set_price_list(party_details, party, party_type, given_price_list, pos=None): # price list diff --git a/erpnext/accounts/test_party.py b/erpnext/accounts/test_party.py new file mode 100644 index 00000000000..f7a1a858ab8 --- /dev/null +++ b/erpnext/accounts/test_party.py @@ -0,0 +1,16 @@ +import frappe +from frappe.tests.utils import FrappeTestCase + +from erpnext.accounts.party import get_default_price_list + + +class PartyTestCase(FrappeTestCase): + def test_get_default_price_list_should_return_none_for_invalid_group(self): + customer = frappe.get_doc({ + 'doctype': 'Customer', + 'customer_name': 'test customer', + }).insert(ignore_permissions=True, ignore_mandatory=True) + customer.customer_group = None + customer.save() + price_list = get_default_price_list(customer) + assert price_list is None