Skip to content

Commit 17a488f

Browse files
authored
Merge pull request #39 from rtCamp/fix/lead-contact-manual
fix: lead: use ERPNext logic and solve error on existing contact
2 parents f5f3b5b + fd4a331 commit 17a488f

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

next_crm/overrides/lead.py

+4-27
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def share_with_agent(self, agent):
7979
elif user != agent:
8080
frappe.share.remove(self.doctype, self.name, user)
8181

82-
def create_contact(self, throw=True):
82+
def create_contact(self, throw=False):
8383
if not self.lead_name:
8484
self.set_full_name()
8585
self.set_lead_name()
@@ -162,36 +162,13 @@ def contact_exists(self, throw=True):
162162
return False
163163

164164
def create_opportunity(self, contact, customer):
165-
opportunity = frappe.new_doc("Opportunity")
166-
167-
lead_opportunity_map = {
168-
"lead_owner": "opportunity_owner",
169-
}
170-
171-
restricted_fieldtypes = ["Tab Break", "Section Break", "Column Break", "HTML", "Button", "Attach", "Table"]
172-
restricted_map_fields = ["name", "naming_series", "creation", "owner", "modified", "modified_by", "idx", "docstatus", "status", "email_id", "mobile_no", "phone", "sla", "sla_status", "response_by", "first_response_time", "first_responded_on", "communication_status", "sla_creation"]
173-
174-
for field in self.meta.fields:
175-
if field.fieldtype in restricted_fieldtypes:
176-
continue
177-
if field.fieldname in restricted_map_fields:
178-
continue
179-
180-
fieldname = field.fieldname
181-
if field.fieldname in lead_opportunity_map:
182-
fieldname = lead_opportunity_map[field.fieldname]
183-
184-
if hasattr(opportunity, fieldname):
185-
if fieldname == "customer":
186-
opportunity.update({fieldname: customer})
187-
else:
188-
opportunity.update({fieldname: self.get(field.fieldname)})
165+
from erpnext.crm.doctype.lead.lead import make_opportunity
166+
opportunity = make_opportunity(self.name)
189167

190168
opportunity.update(
191169
{
192-
"opportunity_from": "lead",
193-
"party_name": self.name,
194170
"contacts": [{"contact": contact}],
171+
"customer": customer
195172
}
196173
)
197174

0 commit comments

Comments
 (0)