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
This commit is contained in:
Ankush Menat
2025-05-26 17:05:34 +05:30
committed by GitHub
parent ff59b89f3e
commit def9d8c9e0

View File

@@ -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",