diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index 7cc0b688..ee03ef52 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -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 diff --git a/crm/fcrm/doctype/crm_organization/crm_organization.py b/crm/fcrm/doctype/crm_organization/crm_organization.py index daca91ff..0636909c 100644 --- a/crm/fcrm/doctype/crm_organization/crm_organization.py +++ b/crm/fcrm/doctype/crm_organization/crm_organization.py @@ -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 [ diff --git a/frontend/src/pages/Deal.vue b/frontend/src/pages/Deal.vue index 3339f0a8..ffd0f416 100644 --- a/frontend/src/pages/Deal.vue +++ b/frontend/src/pages/Deal.vue @@ -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