optimize patch for faster execution (#13068)

This commit is contained in:
Zarrar 2018-02-23 17:41:32 +05:30 committed by Nabin Hait
parent 91fc1a8fbe
commit 96002c28bd
2 changed files with 17 additions and 15 deletions

View File

@ -1,13 +1,13 @@
import frappe
from frappe.model.rename_doc import update_linked_doctypes
from frappe.model.rename_doc import update_linked_doctypes, get_fetch_fields
def execute():
customers = frappe.get_all('Customer')
customers = frappe.get_all('Customer', fields=["name", "territory", "customer_group"])
territory_fetch = get_fetch_fields('Customer', 'Territory')
customer_group_fetch = get_fetch_fields('Customer', 'Customer Group')
for customer in customers:
# Update Territory across all transaction
terr = frappe.get_value('Customer', customer, 'territory')
update_linked_doctypes("Customer", "Territory", customer.name, terr)
update_linked_doctypes(territory_fetch, customer.name, customer.territory_value)
# Update Territory across all transaction
cust_group = frappe.get_value('Customer', customer, 'customer_group')
update_linked_doctypes("Customer", "Customer Group", customer.name, cust_group)
update_linked_doctypes(customer_group_fetch, customer.name, customer.customer_group_value)

View File

@ -11,7 +11,7 @@ from frappe.desk.reportview import build_match_conditions
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
from frappe.model.rename_doc import update_linked_doctypes
from frappe.model.rename_doc import update_linked_doctypes, get_fetch_fields
class Customer(TransactionBase):
def get_feed(self):
@ -57,13 +57,13 @@ class Customer(TransactionBase):
self.check_customer_group_or_territory_change()
def check_customer_group_or_territory_change(self):
frappe.flags.customer_group, frappe.flags.territory = False, False
frappe.flags.customer_group_changed, frappe.flags.territory_changed = False, False
if not self.get('__islocal'):
if self.customer_group != frappe.db.get_value('Customer', self.name, 'customer_group'):
frappe.flags.customer_group = True
frappe.flags.customer_group_changed = True
if self.territory != frappe.db.get_value('Customer', self.name, 'territory'):
frappe.flags.territory = True
frappe.flags.territory_changed = True
def on_update(self):
self.validate_name_with_customer_group()
@ -76,10 +76,12 @@ class Customer(TransactionBase):
if self.flags.is_new_doc:
self.create_lead_address_contact()
if frappe.flags.territory:
update_linked_doctypes("Customer", "Territory", self.name, self.territory)
if frappe.flags.customer_group:
update_linked_doctypes("Customer", "Customer Group", self.name, self.customer_group)
if frappe.flags.territory_changed:
territory_fetch = get_fetch_fields('Customer', 'Territory')
update_linked_doctypes(territory_fetch, self.name, self.territory)
if frappe.flags.customer_group_changed:
customer_group_fetch = get_fetch_fields('Customer', 'Customer Group')
update_linked_doctypes(customer_group_fetch, self.name, self.customer_group)
def create_primary_contact(self):
if not self.customer_primary_contact and not self.lead_name: