diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.py b/crm/fcrm/doctype/crm_deal/crm_deal.py index be40f3d4..8e56dad0 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.py +++ b/crm/fcrm/doctype/crm_deal/crm_deal.py @@ -230,3 +230,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/frontend/src/components/Modals/DealModal.vue b/frontend/src/components/Modals/DealModal.vue new file mode 100644 index 00000000..a83778e1 --- /dev/null +++ b/frontend/src/components/Modals/DealModal.vue @@ -0,0 +1,330 @@ + + + + + + {{ __('Choose Existing Organization') }} + + + + {{ __('Choose Existing Contact') }} + + + + + + + + {{ field.label }} + + + + + + (deal[field.name] = v)" + :placeholder="__(field.placeholder)" + :onCreate="field.create" + /> + (deal[field.name] = v)" + :placeholder="__(field.placeholder)" + :hideMe="true" + > + + + + + + + + + + {{ getUser(option.value).full_name }} + + + + + + + + + + + + + + + + + + + + + + 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 @@ - - - - - - {{ field.label }} - - - - - - - field.change(e)" - :placeholder="field.placeholder" - :onCreate="field.create" - /> - field.change(e)" - :placeholder="field.placeholder" - :hideMe="true" - > - - - - - - - - - - {{ getUser(option.value).full_name }} - - - - - - - - - - - - - - - diff --git a/frontend/src/pages/Deals.vue b/frontend/src/pages/Deals.vue index 098ee0d3..efa64340 100644 --- a/frontend/src/pages/Deals.vue +++ b/frontend/src/pages/Deals.vue @@ -11,7 +11,7 @@ @@ -49,31 +49,12 @@ > {{ __('No Deals Found') }} - + - - - - - - - - - - +