fix: update organization fields if deal is updated and vice-versa
This commit is contained in:
parent
f4cd8bf6b3
commit
ed5a4b53ba
@ -17,6 +17,7 @@ class CRMDeal(Document):
|
||||
def validate(self):
|
||||
self.set_primary_contact()
|
||||
self.set_primary_email_mobile_no()
|
||||
self.update_organization()
|
||||
if self.deal_owner and not self.is_new():
|
||||
self.assign_agent(self.deal_owner)
|
||||
|
||||
@ -61,6 +62,20 @@ class CRMDeal(Document):
|
||||
self.email = ""
|
||||
self.mobile_no = ""
|
||||
|
||||
def update_organization(self):
|
||||
if self.organization:
|
||||
if self.has_value_changed("organization"):
|
||||
organization = frappe.get_cached_doc("CRM Organization", self.organization)
|
||||
self.website = organization.website
|
||||
self.territory = organization.territory
|
||||
self.annual_revenue = organization.annual_revenue
|
||||
if self.has_value_changed("website"):
|
||||
frappe.db.set_value("CRM Organization", self.organization, "website", self.website)
|
||||
if self.has_value_changed("territory"):
|
||||
frappe.db.set_value("CRM Organization", self.organization, "territory", self.territory)
|
||||
if self.has_value_changed("annual_revenue"):
|
||||
frappe.db.set_value("CRM Organization", self.organization, "annual_revenue", self.annual_revenue)
|
||||
|
||||
def assign_agent(self, agent):
|
||||
if not agent:
|
||||
return
|
||||
|
||||
@ -1,11 +1,31 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class CRMOrganization(Document):
|
||||
def on_update(self):
|
||||
self.update_deal_organization_fields()
|
||||
|
||||
def update_deal_organization_fields(self):
|
||||
if (
|
||||
self.has_value_changed("website")
|
||||
or self.has_value_changed("territory")
|
||||
or self.has_value_changed("annual_revenue")
|
||||
):
|
||||
for deal in frappe.get_all(
|
||||
"CRM Deal",
|
||||
filters={"organization": self.name},
|
||||
):
|
||||
if self.has_value_changed("website"):
|
||||
frappe.db.set_value("CRM Deal", deal.name, "website", self.website)
|
||||
if self.has_value_changed("territory"):
|
||||
frappe.db.set_value("CRM Deal", deal.name, "territory", self.territory)
|
||||
if self.has_value_changed("annual_revenue"):
|
||||
frappe.db.set_value("CRM Deal", deal.name, "annual_revenue", self.annual_revenue)
|
||||
|
||||
@staticmethod
|
||||
def sort_options():
|
||||
return [
|
||||
|
||||
@ -444,11 +444,13 @@ const detailSections = computed(() => {
|
||||
function getParsedFields(sections, contacts) {
|
||||
sections.forEach((section) => {
|
||||
section.fields.forEach((field) => {
|
||||
if (['website', 'annual_revenue'].includes(field.name)) {
|
||||
field.value = organization.value?.[field.name]
|
||||
field.tooltip =
|
||||
'This field is read-only and is fetched from the organization'
|
||||
} else if (field.name == 'organization') {
|
||||
if (
|
||||
!deal.data.organization &&
|
||||
['website', 'territory', 'annual_revenue'].includes(field.name)
|
||||
) {
|
||||
field.hidden = true
|
||||
}
|
||||
if (field.name == 'organization') {
|
||||
field.create = (value, close) => {
|
||||
_organization.value.organization_name = value
|
||||
showOrganizationModal.value = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user