Opportunity cannot be created from Lead in non-English languages due to translated Opportunity Type
Information about bug
When creating an Opportunity from a Lead while using a non-English language, such as Persian, the Opportunity cannot be saved.
The issue occurs because the Opportunity Type value is translated when the Opportunity is created from the Lead.
For example:
- Actual Opportunity Type name:
Sales - Persian translation:
فروش
When the Opportunity is created in Persian, opportunity_type is populated with the translated value فروش.
However, when the document is saved, Frappe validates the Link field against the actual name of the Opportunity Type document. Since there is no Opportunity Type record named فروش (the actual record is Sales), the save fails with a LinkValidationError.
Steps to Reproduce
- Set the system/user language to a non-English language, for example Persian.
- Create and save a new Lead.
- Open the Lead.
- Click Create → Opportunity.
- Create the Opportunity.
- Click Save.
Actual Behavior
The Opportunity fails to save with the following error:
frappe.exceptions.LinkValidationError: نوع فرصت: فروش پیدا نشدThe corresponding untranslated error is:
Could not find Opportunity Type: SalesThe opportunity_type field contains the translated value rather than the underlying Opportunity Type name.
For example:
Actual Opportunity Type name: Sales
Translated value: فروشExpected Behavior
The opportunity_type field should always contain the actual name of the linked Opportunity Type document, regardless of the user's language.
For example:
Stored value: Sales
Displayed value: فروشThe translation should only affect the displayed label/value and should not replace the underlying Link value used for document validation.
Technical Details
In ERPNext v16, the Opportunity Type DocType has:
"translated_doctype": 1Also, the Opportunity controller sets the default opportunity_type using the hard-coded value:
if (this.frm.is_new() && this.frm.doc.opportunity_type === undefined) {
this.frm.doc.opportunity_type = "Sales";
}When creating an Opportunity from a Lead, the Lead mapper creates the Opportunity but does not explicitly map opportunity_type.
This appears to result in an interaction between the hard-coded default value and the translated Opportunity Type DocType, causing the translated value to be used as the Link value.
Error Trace
frappe.exceptions.LinkValidationError: نوع فرصت: فروش پیدا نشدFull traceback:
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 121, in application
response = frappe.api.handle(request)
File "apps/frappe/frappe/api/__init__.py", line 63, in handle
data = endpoint(**arguments)
File "apps/frappe/frappe/api/v1.py", line 41, in handle_rpc_call
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 53, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1147, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/utils/typing_validations.py", line 36, in wrapper
return func(*args, **kwargs)
File "apps/frappe/frappe/desk/form/save.py", line 43, in savedocs
doc.save()
File "apps/frappe/frappe/model/document.py", line 557, in save
return self._save(*args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 579, in _save
return self.insert()
File "apps/frappe/frappe/model/document.py", line 479, in insert
self._validate_links()
File "apps/frappe/frappe/model/document.py", line 1221, in _validate_links
frappe.throw(
frappe.exceptions.LinkValidationError: نوع فرصت: فروش پیدا نشدModule
CRM
Version
ERPNext Version - 16.33.0
Installation method
No response
Relevant log output / Stack trace / Full Error Message.
Source: frappe/erpnext