Update Territory & Customer Group across all transaction (#13004)
* added method for update query based on changes * patch added * updated function, moved util function
This commit is contained in:
parent
f1755fb5b1
commit
91fc1a8fbe
@ -490,3 +490,4 @@ erpnext.patches.v10_0.set_default_payment_terms_based_on_company
|
||||
erpnext.patches.v10_0.update_sales_order_link_to_purchase_order
|
||||
erpnext.patches.v10_0.added_extra_gst_custom_field_in_gstr2 #2018-02-13
|
||||
erpnext.patches.v10_0.set_b2c_limit
|
||||
erpnext.patches.v10_0.update_territory_and_customer_group
|
||||
|
13
erpnext/patches/v10_0/update_territory_and_customer_group.py
Normal file
13
erpnext/patches/v10_0/update_territory_and_customer_group.py
Normal file
@ -0,0 +1,13 @@
|
||||
import frappe
|
||||
from frappe.model.rename_doc import update_linked_doctypes
|
||||
|
||||
def execute():
|
||||
customers = frappe.get_all('Customer')
|
||||
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 Territory across all transaction
|
||||
cust_group = frappe.get_value('Customer', customer, 'customer_group')
|
||||
update_linked_doctypes("Customer", "Customer Group", customer.name, cust_group)
|
@ -11,6 +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
|
||||
|
||||
class Customer(TransactionBase):
|
||||
def get_feed(self):
|
||||
@ -53,6 +54,16 @@ class Customer(TransactionBase):
|
||||
self.flags.old_lead = self.lead_name
|
||||
validate_party_accounts(self)
|
||||
self.validate_credit_limit_on_change()
|
||||
self.check_customer_group_or_territory_change()
|
||||
|
||||
def check_customer_group_or_territory_change(self):
|
||||
frappe.flags.customer_group, frappe.flags.territory = 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
|
||||
if self.territory != frappe.db.get_value('Customer', self.name, 'territory'):
|
||||
frappe.flags.territory = True
|
||||
|
||||
def on_update(self):
|
||||
self.validate_name_with_customer_group()
|
||||
@ -65,6 +76,11 @@ 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)
|
||||
|
||||
def create_primary_contact(self):
|
||||
if not self.customer_primary_contact and not self.lead_name:
|
||||
if self.mobile_no or self.email_id:
|
||||
|
Loading…
x
Reference in New Issue
Block a user