From def9d8c9e0409bce90f015b0028a5aa2519fe356 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 26 May 2025 17:05:34 +0530 Subject: [PATCH] perf: speed up customer import (#47738) * perf: Avoid fetching customer from DB This is likely code from bygone era where is_new and doc_before_save didn't exist? I see no reason to do it in this weird manner. This code still appears to be wrong but I'll leave it as is for now. * fix: don't validate internal customer for non-internal customer This was likely missed out while adding validations --- erpnext/selling/doctype/customer/customer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 8d61d0fa246..acaca341a17 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -152,8 +152,7 @@ class Customer(TransactionBase): self.validate_currency_for_receivable_payable_and_advance_account() # set loyalty program tier - if frappe.db.exists("Customer", self.name): - customer = frappe.get_doc("Customer", self.name) + if not self.is_new() and (customer := self.get_doc_before_save()): if self.loyalty_program == customer.loyalty_program and not self.loyalty_program_tier: self.loyalty_program_tier = customer.loyalty_program_tier @@ -207,6 +206,7 @@ class Customer(TransactionBase): def validate_internal_customer(self): if not self.is_internal_customer: self.represents_company = "" + return internal_customer = frappe.db.get_value( "Customer",