Lead-to-opportunity lifecycle
The lead-to-opportunity lifecycle turns an identified person or organization into a tracked sales deal. It keeps prospect identity, contact details, conversations, events, appointments, qualification state, and deal progress connected so that sales work can move from CRM activity into the commercial flow described in Sales and commerce. This page is a child of Customer relationship management.
Prospect and lead capture
Lead records
A lead is an early sales record for a person or organization that may become a customer. It holds identity and contact data together with ownership, source data, organization details, territory, request type, and a status that describes the current response from the prospect. Leads can be entered directly or created from an incoming communication or an appointment when no matching lead exists. Incoming communication can reuse a lead matched by email or phone before it creates a new lead. erpnext/…/lead.py and erpnext/…/mapper.py support these capture paths.
The lead record also carries a qualification state. Unqualified, In Process, and Qualified show whether the sales team has assessed the lead. The qualification fields record the user and date for that assessment. A qualification state is separate from the broader lead status, so qualification can describe readiness while status describes the sales response. erpnext/…/lead.json• L370-406
Lead status also reflects linked sales records. The standard lead view presents the path from an initial lead through open response, interest, opportunity, quotation, conversion, and contact suppression. Statuses set by linked opportunities or quotations are treated as system states rather than free moves in the lead pipeline. erpnext/…/lead.json• L147-159, erpnext/…/lead_kanban.js• L1-17
References: erpnext/…/lead.json• L118-159 erpnext/…/lead.json• L370-406 erpnext/…/lead.py• L91-126 erpnext/…/mapper.py• L120-155 erpnext/…/lead_kanban.js• L1-17
Prospect groups
A prospect is the organization-level view of a possible customer. It groups one or more leads with shared company information and can also group the opportunities that arise from those leads. This lets a sales team follow an account across several people or sales conversations instead of treating each lead as an isolated record.
The lead form can add a lead to an existing prospect or create a new prospect. When a lead is added to a prospect, the prospect stores a linked lead row. Changes to the lead refresh that row, and removing the lead removes the link or the prospect when it has no other leads. When an opportunity is created from that lead or from the prospect itself, the prospect stores a linked opportunity row with the deal amount, stage, owner, probability, expected close date, currency, and contact. The lead and opportunity records update these summary links as they change. erpnext/…/lead.js• L31-43, erpnext/…/lead.js• L103-210, erpnext/…/lead.py• L214-243, erpnext/…/prospect.py• L48-66, and erpnext/…/opportunity.py• L277-317
References: erpnext/…/lead.js• L31-43 erpnext/…/lead.js• L103-210 erpnext/…/lead.py• L214-243 erpnext/…/prospect.json• L44-49 erpnext/…/prospect.json• L153-187 erpnext/…/prospect.py• L48-66 erpnext/…/opportunity.py• L277-317 erpnext/…/prospect_lead.json• L16-75 erpnext/…/prospect_opportunity.json• L19-86
Contact and event continuity
Contact links
Contacts provide the reusable person record behind a lead or an opportunity. CRM settings can create a contact when a lead is captured. The contact keeps the lead link and can carry the lead's name, role, email, and phone data. When a user creates an opportunity from a lead, the workflow can create the missing prospect and contact before it opens the new opportunity.
An opportunity keeps its party type and party name separate. Its party can be a Lead, Prospect, or Customer, while a separate contact link identifies the person involved in the deal. This separation supports both a person-level lead and an organization-level prospect without losing the main contact. erpnext/…/opportunity.json• L115-136, erpnext/…/opportunity.json• L255-329
References: erpnext/…/lead.py• L109-129 erpnext/…/lead.py• L272-301 erpnext/…/lead.js• L103-189 erpnext/…/opportunity.json• L115-136 erpnext/…/opportunity.json• L255-329
Activity links
Activities keep the sales history attached as ownership moves from one CRM record to the next. Open tasks and events are linked to a newly created opportunity. Open events are also added to the prospect when a lead or opportunity belongs to that prospect. When a lead is added to a prospect, an optional CRM setting also carries comments and communications forward. Another setting can refresh the linked record's modified time when new inbound communication arrives.
The result is a connected activity trail across lead, prospect, opportunity, and later commercial documents. It supports a handoff without forcing a salesperson to reconstruct prior contact from separate timelines. erpnext/…/utils.py• L39-71, erpnext/…/utils.py• L106-148, erpnext/…/opportunity.py• L116-131, erpnext/…/crm_settings.json• L85-105
References: erpnext/…/lead.py• L416-423 erpnext/…/utils.py• L53-71 erpnext/…/utils.py• L123-148 erpnext/…/prospect.py• L74-91 erpnext/…/crm_settings.json• L85-105
Opportunity management
Opportunity records
An opportunity is a possible sales deal. It identifies the party, owner, sales stage, expected closing date, probability, value, currency, primary contact, and any proposed items. The party may be a lead, prospect, or existing customer, so the same deal model supports both new acquisition and expansion work.
The opportunity can be created from a lead or prospect and can then produce a quotation or customer record through the sales flow. It can also be opened from an incoming communication: the system reuses the communication's lead when one is referenced or matched, creates one when needed, and links the communication to the new opportunity. When it is created from a lead, key identity, contact, owner, and notes data are mapped into the opportunity. Missing party data can also cause the system to find an existing customer or create a lead from the opportunity contact email. New opportunities use Sales as their default opportunity type. erpnext/…/lead.js• L103-189, erpnext/…/mapper.py• L65-94, erpnext/…/mapper.py• L146-180, erpnext/…/prospect.py• L165-186, erpnext/…/opportunity.py• L116-131, and erpnext/…/opportunity.py• L320-366
References: erpnext/…/opportunity.json• L115-241 erpnext/…/opportunity.json• L346-355 erpnext/…/opportunity.py• L133-153 erpnext/…/opportunity.py• L320-366 erpnext/…/lead.js• L103-189 erpnext/…/mapper.py• L65-94 erpnext/…/mapper.py• L146-180
Sales progression
Sales stage expresses where the deal is in the sales process. Opportunity status expresses its broader state, such as open work, quotation activity, conversion, loss, or closure. The amount and probability give the sales team a view of expected value, while the expected closing date supports planning and reporting.
An opportunity can be marked lost only after the system checks for an active quotation. Lost opportunities record lost reasons and may record competitors or a detailed reason. A deal can be reopened from the user interface, but reopening clears its stored lost reasons. Quotation and converted states follow the linked quotation outcome, so users cannot use a status move to bypass the commercial flow. erpnext/…/opportunity.py• L190-224, erpnext/…/opportunity.py• L369-423, erpnext/…/opportunity.js• L25-29, erpnext/…/opportunity_kanban.js• L1-30
The following diagram shows the main path from first contact to commercial follow-up and terminal deal states.
flowchart LR
Capture[Lead or appointment capture] --> Qualify[Lead qualification]
Qualify --> Group[Prospect grouping]
Group --> Deal[Opportunity]
Capture --> Deal
Deal --> Quote[Quotation]
Deal --> Customer[Customer creation]
Deal --> Won[Converted]
Deal --> Lost[Lost]
Deal --> Closed[Closed]
Quote --> Won
References: erpnext/…/opportunity.json• L161-182 erpnext/…/opportunity.py• L190-224 erpnext/…/opportunity.py• L369-423 erpnext/…/opportunity.js• L25-29 erpnext/…/opportunity_kanban.js• L1-30
Pipeline views
Pipeline views give sales users a shared way to inspect work by status while keeping record-controlled states accurate. The lead pipeline highlights qualification, ownership, territory, source, and organization context. The opportunity pipeline highlights value, closing date, sales stage, probability, owner, and party.
The standard list views focus work on open or unassigned leads, newly created leads, converted leads, open opportunities, deals closing this month, and lost opportunities. A user can move ordinary work between suitable pipeline states, but linked documents remain the source of truth for system-controlled lead and opportunity statuses. erpnext/…/lead_pipeline.json• L49-192, erpnext/…/opportunity_pipeline.json• L64-160, erpnext/…/lead_open.json• L5-20, and erpnext/…/opportunity_open.json• L5-20
References: erpnext/…/lead_pipeline.json• L49-192 erpnext/…/lead_pipeline.json• L198-387 erpnext/…/lead_converted.json• L5-20 erpnext/…/lead_new_this_week.json• L5-20 erpnext/…/lead_open.json• L5-20 erpnext/…/lead_unassigned.json• L5-20 erpnext/…/opportunity_pipeline.json• L64-160 erpnext/…/opportunity_pipeline.json• L167-325 erpnext/…/opportunity_closing_this_month.json• L5-20 erpnext/…/opportunity_lost.json• L5-20 erpnext/…/opportunity_open.json• L5-20
Appointment handling
Public booking
The appointment portal lets a visitor select a time and submit name, email, phone, and notes. The portal first checks that booking is enabled. It presents slots from the configured schedule and filters them by time zone, holidays, advance-booking limits, and concurrent agent capacity. The server applies the same schedule rules when it saves the appointment, including past-time, duration, slot-grid, and overlap checks. erpnext/…/index.py• L21-40, erpnext/…/index.py• L49-86, erpnext/…/appointment.py• L55-163
The new appointment starts as Unverified when it comes from the portal. The system sends a confirmation link to the visitor. A valid link changes the appointment to Open; an invalid, expired, or reused link does not create a second confirmation. Manual appointments start active and do not need email verification. The portal requires scheduling to be enabled, and its verification window is configured in Appointment Booking Settings. erpnext/…/appointment.py• L79-94, erpnext/…/appointment.py• L165-180, erpnext/…/index.py• L15-45
References: erpnext/…/index.py• L21-40 erpnext/…/index.py• L49-86 erpnext/…/index.py• L106-127 erpnext/…/appointment.json• L59-139 erpnext/…/appointment.py• L55-180 erpnext/…/test_appointment.py• L208-300
Party matching and assignment
After a manually created appointment or a verified portal appointment becomes active, the system links it to a party by email. It prefers an existing customer, then an existing lead, and creates a lead when neither exists. The appointment is assigned to an agent and linked to a calendar event. If the party has a recent opportunity, the system first tries to keep the same assignee when that agent is free.
The appointment stores both the party type and party name. Its calendar event includes the party and assigned employee as participants. Changes to appointment time or status are reflected in the calendar event and related open assignments. Closed appointments release their time slot, while reopening them checks capacity again. erpnext/…/appointment.py• L234-342, erpnext/…/appointment.py• L440-462
References: erpnext/…/appointment.py• L142-180 erpnext/…/appointment.py• L234-342 erpnext/…/appointment.py• L440-462 erpnext/…/appointment.json• L67-110 erpnext/…/test_appointment.py• L599-629
Automated closure
Opportunity inactivity
The daily maintenance task closes opportunities that remain in Replied status without a modification for the configured number of days. The setting defaults to 15 days. This rule only targets the Replied state, so it does not replace a sales decision to mark a deal lost or converted. erpnext/…/opportunity.py• L577-591, erpnext/…/crm_settings.json• L64-74, and erpnext/hooks.py• L497-500
Appointment expiry
The hourly maintenance task handles portal appointments that stay Unverified beyond the configured verification window. The configured action either marks them Closed or deletes them permanently. Closed appointments no longer count as active bookings, and their verification links cannot be used to reopen them. erpnext/…/appointment.py• L465-479, erpnext/…/appointment_booking_settings.json• L115-148, and erpnext/hooks.py• L481-487
References: erpnext/…/opportunity.py• L577-591 erpnext/…/appointment.py• L465-479 erpnext/…/test_appointment.py• L529-569 erpnext/…/appointment_booking_settings.json• L115-148 erpnext/hooks.py• L481-500
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the lead-to-opportunity field mapping aligned with the fields used by the Lead and Opportunity records. A new contact or owner field can otherwise disappear during deal creation.
- Preserve the party type and party name contract. Opportunity, contact, event, and appointment links depend on knowing whether the party is a Lead, Prospect, or Customer.
- Keep prospect summary rows in step with their source records. Prospect views use linked lead and opportunity rows as the account-level summary.
- Keep pipeline columns and standard list filters aligned with the status values that users can set. Linked quotations and conversions remain the source of truth for system-controlled states.
- Review both portal slot display and server appointment validation when booking rules change. They must apply the same time, holiday, capacity, duration, and slot-grid rules.
- Review the scheduler entry and the matching setting when changing closure timing or expiry action. A valid rule has no effect if its maintenance task is not scheduled.
- Check activity carry-forward behavior when changing record creation paths. Open tasks, events, comments, and communications must remain linked to the new CRM record when the related setting is enabled.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A lead is created with an email that already belongs to another lead while duplicate emails are not allowed | Lead creation stops and the new prospect is not captured | Enable duplicate emails only when the business process can distinguish repeated contacts. erpnext/…/lead.py• L179-196 |
| A lead or opportunity card is moved to a status controlled by linked documents | The move is blocked and the linked record remains the source of the status | Change the linked opportunity or quotation instead of the pipeline card. erpnext/…/lead_kanban.js• L1-17, erpnext/…/opportunity_kanban.js• L1-17 |
An opportunity is marked Lost without lost reasons | The save is rejected | Supply at least one lost reason through the lost-deal flow. erpnext/…/opportunity.js• L25-29, erpnext/…/opportunity.py• L369-392 |
| A user marks an opportunity lost while an active quotation exists | The opportunity remains active and the loss is rejected | Close, cancel, expire, or otherwise resolve the active quotation first. erpnext/…/opportunity.py• L201-224, erpnext/…/opportunity.py• L394-423 |
| A portal visitor does not verify the appointment before the expiry window | The appointment is closed or deleted by maintenance and the link cannot be used | Book again or increase the configured verification window within its allowed range. erpnext/…/appointment.py• L465-479, erpnext/…/index.py• L23-39 |
| A requested appointment is in the past, outside the schedule, off the slot grid, or overlaps configured capacity | The appointment is rejected even if a client displayed a slot | Keep portal slot calculation and server schedule validation aligned. erpnext/…/appointment.py• L96-163, erpnext/…/test_appointment.py• L769-823 |
A user tries to move several opportunity cards to Lost at once | The move is blocked because each deal needs its own loss details | Declare opportunities lost one at a time. erpnext/…/opportunity_kanban.js• L19-30 |
Key files
| File | Why to read it |
|---|---|
| erpnext/…/lead.py | Lead validation, contact creation, prospect links, and lead-to-prospect activity transfer |
| erpnext/…/lead.js | User actions that create a prospect, contact, opportunity, quotation, or customer from a lead |
| erpnext/…/mapper.py | Data handoff from lead to opportunity, customer, and quotation, including communication-based lead capture |
| erpnext/…/lead.json | Lead identity, response status, qualification state, and contact model |
| erpnext/…/lead_pipeline.json | Lead pipeline states and the fields used to guide qualification work |
| erpnext/…/prospect.py | Prospect grouping and conversion from an organization-level prospect to an opportunity or customer |
| erpnext/…/opportunity.py | Opportunity validation, party selection, quotation checks, prospect updates, and automatic closure |
| erpnext/…/opportunity.js | Opportunity form behavior for party selection, status changes, loss checks, and commercial handoff |
| erpnext/…/opportunity.json | Opportunity states, stages, deal value, party, and contact model |
| erpnext/…/mapper.py | Opportunity handoff to commercial documents and creation from incoming communication |
| erpnext/…/opportunity_pipeline.json | Opportunity pipeline states and deal fields used for sales review |
| erpnext/…/appointment.py | Appointment verification, schedule checks, party matching, assignment, calendar linking, and expiry handling |
| erpnext/…/index.py | Public slot lookup and portal appointment capture |
| erpnext/…/index.py | Email verification and activation of portal appointments |
| erpnext/…/utils.py | Shared links for communications, tasks, events, and prospects |
| erpnext/…/crm_settings.json | CRM switches for contact creation, activity carry-forward, and opportunity closure timing |
| erpnext/…/appointment_booking_settings.json | Appointment schedule, capacity, portal verification, and expiry policy |
| erpnext/hooks.py | Scheduler registration for appointment expiry and opportunity auto-closure |