diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index be40f3d4..e9a1dd61 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -18,7 +18,6 @@ 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.share_with_agent(self.deal_owner) self.assign_agent(self.deal_owner) @@ -69,20 +68,6 @@ class CRMDeal(Document): self.mobile_no = "" self.phone = "" - 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 @@ -230,3 +215,78 @@ def set_primary_contact(deal, contact): deal.save() return True +def create_organization(doc): + if not doc.get("organization_name"): + return + + existing_organization = frappe.db.exists("CRM Organization", {"organization_name": doc.get("organization_name")}) + if existing_organization: + return existing_organization + + organization = frappe.new_doc("CRM Organization") + organization.update( + { + "organization_name": doc.get("organization_name"), + "website": doc.get("website"), + "territory": doc.get("territory"), + "industry": doc.get("industry"), + "annual_revenue": doc.get("annual_revenue"), + } + ) + organization.insert(ignore_permissions=True) + return organization.name + +def contact_exists(doc): + email_exist = frappe.db.exists("Contact Email", {"email_id": doc.get("email")}) + mobile_exist = frappe.db.exists("Contact Phone", {"phone": doc.get("mobile_no")}) + + doctype = "Contact Email" if email_exist else "Contact Phone" + name = email_exist or mobile_exist + + if name: + return frappe.db.get_value(doctype, name, "parent") + + return False + +def create_contact(doc): + existing_contact = contact_exists(doc) + if existing_contact: + return existing_contact + + contact = frappe.new_doc("Contact") + contact.update( + { + "first_name": doc.get("first_name"), + "last_name": doc.get("last_name"), + "salutation": doc.get("salutation"), + "company_name": doc.get("organization") or doc.get("organization_name"), + } + ) + + if doc.get("email"): + contact.append("email_ids", {"email_id": doc.get("email"), "is_primary": 1}) + + if doc.get("mobile_no"): + contact.append("phone_nos", {"phone": doc.get("mobile_no"), "is_primary_mobile_no": 1}) + + contact.insert(ignore_permissions=True) + contact.reload() # load changes by hooks on contact + + return contact.name + +@frappe.whitelist() +def create_deal(args): + deal = frappe.new_doc("CRM Deal") + + contact = args.get("contact") + if not contact and (args.get("first_name") or args.get("last_name") or args.get("email") or args.get("mobile_no")): + contact = create_contact(args) + + deal.update({ + "organization": args.get("organization") or create_organization(args), + "contacts": [{"contact": contact, "is_primary": 1}] if contact else [], + "deal_owner": args.get("deal_owner"), + "status": args.get("status"), + }) + deal.insert(ignore_permissions=True) + return deal.name diff --git a/crm/fcrm/doctype/crm_organization/crm_organization.py b/crm/fcrm/doctype/crm_organization/crm_organization.py index f1ecaae9..6d9a2a14 100644 --- a/crm/fcrm/doctype/crm_organization/crm_organization.py +++ b/crm/fcrm/doctype/crm_organization/crm_organization.py @@ -6,26 +6,6 @@ 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 default_list_data(): columns = [ diff --git a/frontend/index.html b/frontend/index.html index 7560ce74..31a720b7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -11,7 +11,7 @@ href="/assets/crm/crm_logo.png" /> -
+ diff --git a/frontend/src/components/Modals/DealModal.vue b/frontend/src/components/Modals/DealModal.vue new file mode 100644 index 00000000..f48cfbc8 --- /dev/null +++ b/frontend/src/components/Modals/DealModal.vue @@ -0,0 +1,339 @@ + + + + + + + diff --git a/frontend/src/components/Modals/LeadModal.vue b/frontend/src/components/Modals/LeadModal.vue new file mode 100644 index 00000000..a3f87769 --- /dev/null +++ b/frontend/src/components/Modals/LeadModal.vue @@ -0,0 +1,307 @@ + + + + + + + diff --git a/frontend/src/components/NewDeal.vue b/frontend/src/components/NewDeal.vue deleted file mode 100644 index 06b08e07..00000000 --- a/frontend/src/components/NewDeal.vue +++ /dev/null @@ -1,190 +0,0 @@ - -