Hello everyone,
I am using Frappe CRM and have run into an issue with our sales workflow. When I create a lead and convert it into a deal, and the deal is marked as Won, I generate a Quotation directly from that deal. The Quotation contains the correct customer details, and so does the Deal. However, when I create a Sales Order from that same Quotation, the customer details are missing in the Sales Order.
This is not limited to a single customer. It happens with every Sales Order I create through this flow. I am not sure whether this is a configuration problem, a missing customer link during the lead-to-deal conversion, or a bug in the current version.
Has anyone experienced this before, or does anyone know what could be causing it? Any guidance on how to fix it would be greatly appreciated.
Thank you in advance for your help.
Hi Abdul,
I came across a similar issue with Frappe CRM and ERPNext where the Quotation couldn’t be converted into a Sales Order because the system wasn’t resolving the correct Customer.
It was reported here:
opened 09:10AM - 19 Mar 26 UTC
closed 03:34PM - 17 Oct 26 UTC
bug
CRM
### Information about bug
When using the Frappe CRM ↔ ERPNext integration, crea… ting multiple CRM Deals for the same organization/customer causes [_make_customer()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:544:0-581:12) in [quotation.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:0:0-0:0) to throw a `DoesNotExistError` when converting a Quotation to a Sales Order. This is because the [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) field on `Customer` is a singular `Data` field (1:1 mapping), and the lookup only works for the **first** deal that created the customer.
### Steps to Reproduce
**Prerequisites:** Frappe CRM is installed and ERPNext CRM Settings is enabled with `create_customer_on_status_change` turned on.
1. **Create CRM Deal-1** for organization "Test Corp" in Frappe CRM
2. **Change Deal-1's status** to the configured "Won" status → a Customer "Test Corp" is created in ERPNext with `crm_deal = "CRM-DEAL-2025-00001"`
3. **Create CRM Deal-2** for the **same** organization "Test Corp"
4. **Change Deal-2's status** to "Won" → [create_customer()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/osg_frappe_crm_extend/osg_frappe_crm_extend/osg_frappe_crm_extend/overrides/frappe_crm_api.py:23:0-57:3) in [frappe_crm_api.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:0:0-0:0) finds Customer "Test Corp" already exists and **skips creation** — the Customer's [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) still points to `"CRM-DEAL-2025-00001"` (Deal-1)
5. **Create a Quotation** from Deal-2 (via the "Create Quotation" button in CRM) → Quotation is created with `quotation_to = "CRM Deal"`, `party_name = "CRM-DEAL-2025-00002"`
6. **Convert the Quotation to a Sales Order** → 💥 **Error**
### Expected Behavior
The Quotation should successfully convert to a Sales Order, finding the existing Customer "Test Corp".
### Actual Behavior
```
frappe.exceptions.DoesNotExistError: Customer not found
```
[_make_customer()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:544:0-581:12) does `frappe.get_doc("Customer", {"crm_deal": "CRM-DEAL-2025-00002"})` but no Customer has `crm_deal = "CRM-DEAL-2025-00002"` — the Customer's [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) field still points to `"CRM-DEAL-2025-00001"`.
### Root Cause
**1. [_make_customer()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:544:0-581:12) in [quotation.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:0:0-0:0) — no fallback lookup**
https://github.com/frappe/erpnext/blob/develop/erpnext/selling/doctype/quotation/quotation.py#L555-L556
```python
elif quotation.quotation_to == "CRM Deal":
return frappe.get_doc("Customer", {"crm_deal": quotation.party_name})
```
This assumes a 1:1 mapping between [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) and `Customer`. It does not check the `erpnext_customer` field on the CRM Deal as a fallback (which **is** correctly set for subsequent deals by [create_customer_in_erpnext()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/crm/crm/fcrm/doctype/erpnext_crm_settings/erpnext_crm_settings.py:281:0-329:49)).
**2. [create_customer()](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/osg_frappe_crm_extend/osg_frappe_crm_extend/osg_frappe_crm_extend/overrides/frappe_crm_api.py:23:0-57:3) in [frappe_crm_api.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:0:0-0:0) — never updates [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) on existing Customer**
https://github.com/frappe/erpnext/blob/develop/erpnext/crm/frappe_crm_api.py#L159-L165
```python
customer_name = frappe.db.exists("Customer", {"customer_name": customer_data.get("customer_name")})
if not customer_name:
customer = frappe.get_doc({"doctype": "Customer", **customer_data}).insert(...)
customer_name = customer.name
# ← When customer exists, crm_deal is never updated
```
When the customer already exists, the function returns the existing customer name but never updates the [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) field to point to the new deal.
### Proposed Fix
**Fix 1: [quotation.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/selling/doctype/quotation/quotation.py:0:0-0:0) — add fallback lookup**
```diff
elif quotation.quotation_to == "CRM Deal":
- return frappe.get_doc("Customer", {"crm_deal": quotation.party_name})
+ # Support multiple deals per customer: try direct lookup first,
+ # then fallback to the erpnext_customer stored on the CRM Deal.
+ customer_name = frappe.db.exists("Customer", {"crm_deal": quotation.party_name})
+ if not customer_name:
+ customer_name = frappe.db.get_value(
+ "CRM Deal", quotation.party_name, "erpnext_customer"
+ )
+ if customer_name:
+ return frappe.get_doc("Customer", customer_name)
```
**Fix 2: [frappe_crm_api.py](cci:7://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:0:0-0:0) — update [crm_deal](cci:1://file:///d:/Coding/frappe-benchs/osg-dev/apps/erpnext/erpnext/crm/frappe_crm_api.py:31:0-65:43) on existing Customer**
```diff
customer_name = customer.name
+elif customer_data.get("crm_deal"):
+ # Update existing customer's crm_deal to point to the latest deal
+ frappe.db.set_value("Customer", customer_name, "crm_deal", customer_data["crm_deal"])
```
### Module
selling, CRM
### Version
ERPNext: v15.102.1
Frappe CRM: v1.60.3
### Installation method
FrappeCloud
### Relevant log output / Stack trace / Full Error Message.
```shell
```
The maintainers mentioned on October 17 that this was fixed in newer versions of ERPNext and Frappe CRM.
I’m curious about two things:
Was the Quotation created from a CRM Deal?
Does that Deal already have a linked Customer in ERPNext?
It would also help to know which versions you’re running.
If you’re using an older version, you might be encountering the same problem. Otherwise, it would be interesting to see whether there’s another issue with the Customer link.