Override ERPNext DocTypes functions?

In ERPNext, when a Lead is created with a Phone Number, but not a Mobile Number, then the Phone Number will be inserted into the Lead as it’s Mobile Number.

I find this very annoying, since it causes users to think that the Lead has a mobile phone number, when they actually don’t.

I’d like to prevent whatever code that does that fom running.I think it might be part of the code that runs that creates a new Contact when a Lead is created. Is it possible to override that function and prevent this from happening?

Hi there,

I don’t know the particulars about how Contacts are generated from Leads, but if you can find in the code where the phone number is getting applied to the mobile field, you should be able to override it with a custom class.

https://docs.frappe.io/framework/user/en/python-api/hooks

This seems like a bug, though, so you might just submit a pull request to get it fixed once and for all.

It’s not a bug, it’s written intentionally. I found the code that did it, but I forgot where it is. I do believe it’s actually part of the contact.py.

It’s a very annoying and completely unnecessary function, however. The issue with it is that I’ve built a custom app that lets users send SMS directly from ERPNext, but if they create a Lead, the Lead ends up getting its mobile_number field populated with the phone_number field, even if the phone_number isn’t actually a mobile number, which results in sales agents trying (and failing) to send a bunch of SMS to numbers that aren’t actually mobile numbers.

It certainly sounds like wrong/buggy behavior to me! In any case, if the maintainers don’t want to change it, it should be possible to fix it with a class override hook.

1 Like

If the messages are sent from Contact doctype records, you can prevent auto contact creation in CRM Setting. Go to CRM setting, uncheck the checkbox for Auto Contact Creation.

It’s definitely not a bug. It’s just an idiotic “feature” that serves absolutely no useful purpose, unless I am missing something. In fact, it could be quite harmful if a person tries to use Twilio (or any other SMS API) to send SMS in bulk.

For instance, suppose I want to send an SMS to all of my Leads using Twilio. If I try to send an SMS to all of my Leads with a mobile_no, then it will send an SMS API call to every Lead that has a ‘phone’ number, even if that number isn’t actually a mobile/cell phone number. This means Twilio will bill me for a bunch of SMS messages that won’t go through (and may get me in trouble with Twilio for sending a bunch of invald API calls?).

I know it’s not a bug because it’s written specifically in erpnext/crm/utils.py in this function `def update_lead_phone_numbers(contact, method):
if contact.phone_nos:
contact_lead = contact.get_link_for(“Lead”)
if contact_lead:
phone = mobile_no = contact.phone_nos[0].phone

		if len(contact.phone_nos) > 1:
			# get the default phone number
			primary_phones = [
				phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_phone
			]
			if primary_phones:
				phone = primary_phones[0]

			# get the default mobile number
			primary_mobile_nos = [
				phone_doc.phone for phone_doc in contact.phone_nos if phone_doc.is_primary_mobile_no
			]
			if primary_mobile_nos:
				mobile_no = primary_mobile_nos[0]

		lead = frappe.get_doc("Lead", contact_lead)
		lead.db_set("phone", phone)
		lead.db_set("mobile_no", mobile_no)

`

For some reason they seem to think that it’s vital for a Lead to have a number in the mobile_no field. I see absolutely ZERO reason why that would be important enough to force the ‘phone’ value into the ‘mobile_no’ field.

I’ve raised the issue a few times now on github, and they don’t seem to care.

There’s no need for name calling. The options forward available to you are clear. You can submit a PR, patch it yourself locally, or learn to live with it.