Introducing a new way to review your PRs.

Read the announcement

frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)

View on GitHub

20 documents · Updated Nov 23, 2026

docs / customer-relationship-management

Customer relationship management

ERPNext's CRM area helps sales teams capture people and organizations, move qualified interest through a sales pipeline, keep customer activity in context, and track the commitments that follow a deal. It connects acquisition records with campaigns, meetings, communications, customers, and downstream sales documents.

Customer acquisition model

The CRM model moves from an early contact to a known organization and then to a potential deal. A lead represents an unqualified person or organization. A prospect groups the organization's leads and opportunities. An opportunity records the possible sale and its expected value.

This relationship keeps work at the right level. Sales staff can act on a person through a lead, see the wider account through a prospect, and forecast a deal through an opportunity. The lead-to-opportunity lifecycle explains this path in detail.

flowchart LR
    Campaign[Campaign reach] --> Lead[Lead]
    Lead --> Prospect[Prospect organization]
    Lead --> Opportunity[Opportunity]
    Prospect --> Opportunity
    Opportunity --> Sales[Quotation and sales documents]
    Lead -. activity history .-> Activity[Communications and events]
    Prospect -. activity history .-> Activity
    Opportunity -. activity history .-> Activity

Lead and prospect records

Lead capture

A lead is the first working record for a possible customer. It can hold contact details, organization facts, ownership, source data, qualification state, and a link to an existing customer when the inquiry comes from that customer. Lead status shows whether the contact is open, interested, moving toward an opportunity, converted, or not to be contacted. References: erpnext/…/lead.json• L138-159, erpnext/…/lead.json• L370-407

Lead validation checks the email format and can reject duplicate email addresses when CRM settings do not allow them. Lead creation can establish a contact when CRM settings allow it. For an inquiry from an existing customer, it can reuse that customer's linked contact. References: erpnext/…/lead.py• L91-122, erpnext/…/crm_settings.json• L48-63

Inbound email can also start lead work. CRM checks access to the email and to lead creation, reuses a lead when the sender email or phone matches, or creates a new lead and links the email to it. References: erpnext/…/mapper.py• L120-155

Lead information can move into an opportunity, quotation, or customer record. These paths carry the party and contact context forward, and customer creation can use the lead's default address and contact. Contact phone changes also update the phone data on a linked lead. References: erpnext/…/mapper.py• L15-117, erpnext/…/utils.py• L16-49

The lead also acts as a source for later account work. Users can create a prospect, contact, opportunity, quotation, or customer from the lead. When an opportunity is created, CRM can offer to create any missing prospect and contact first. Adding a lead to a prospect can carry comments, communications, and open events when CRM settings enable that behavior. References: erpnext/…/lead.py• L245-334, erpnext/…/lead.py• L408-429, erpnext/…/lead.js• L26-189

Prospect organization

A prospect is the account-level view of a possible customer. It groups related leads and opportunities under a required organization and adds shared context such as industry, market segment, territory, customer group, contacts, addresses, activities, and notes. This view lets a team manage several contacts or deals without losing the organization behind them. A lead can belong to only one prospect. References: erpnext/…/prospect.json• L44-187, erpnext/…/prospect.py• L48-66

The prospect relationship also gives related activity an account-level view. CRM can connect communications and events that reference a lead or opportunity to the matching prospect. References: erpnext/…/utils.py• L69-149, erpnext/…/prospect.py• L68-110

Opportunity pipeline

An opportunity is a potential sales deal. It links to a lead, prospect, or customer and records the owner, sales stage, expected closing date, probability, value, items, contact, source, and status. These fields give the sales team a shared view of deal health and give forecasts a time and value basis. References: erpnext/…/opportunity.json• L115-240, erpnext/…/opportunity.json• L630-665

Opportunities connect CRM work to the commercial flow. They can become the source for quotations and later sales documents, while their stage, amount, probability, expected close, and status feed pipeline views. The sales and commerce page covers the later quotation, order, fulfilment, and billing stages. References: erpnext/…/opportunity.py• L116-165, erpnext/…/sales_pipeline_analytics.py• L97-186

An opportunity can also produce a quotation, a request for quotation, or a customer record. An inbound email can create an opportunity through a lead and keep the email linked to the new deal. References: erpnext/…/mapper.py• L15-112, erpnext/…/mapper.py• L146-180

The opportunity pipeline also records why a deal is lost. The loss flow requires at least one lost reason, and an opportunity cannot be marked lost while it has an active quotation. These checks protect the link between a live commercial offer and the pipeline result. References: erpnext/…/opportunity.js• L25-29, erpnext/…/opportunity.py• L190-224, erpnext/…/opportunity.py• L368-392

Campaign engagement

Campaign planning

A campaign defines a named sales or marketing effort. It can include a description and a sequence of email templates with a delay for each message. Campaign source data is mirrored into the shared UTM campaign record, so leads and opportunities can retain campaign attribution even when the campaign display name changes. References: erpnext/…/campaign.json• L21-66, erpnext/…/campaign.py• L28-61, erpnext/…/lead.json• L518-545

The Campaign form provides a direct view of leads attributed to that campaign. This lets a user move from campaign planning to the affected acquisition records without losing the campaign source filter. References: erpnext/…/campaign.js• L14-25, erpnext/…/lead.json• L539-545

An Email Campaign enrolls a lead, contact, or email group in that sequence. Its active window starts on the chosen date and ends after the latest scheduled delay. The recipient must have an email address, the linked campaign must have a schedule, and the same recipient cannot have another scheduled or active enrollment for that campaign. References: erpnext/…/email_campaign.json• L20-74, erpnext/…/email_campaign.py• L31-110

The campaign sender checks active enrollments each day and sends the message scheduled for that date. It records the communication with the campaign and supports unsubscribe handling for both individual recipients and email groups. The campaign communications page explains the message flow in detail. References: erpnext/…/email_campaign.py• L131-187, erpnext/…/email_campaign.py• L190-302

Campaign measurement

Campaign reporting follows a contact from lead creation through opportunity, quotation, and ordered sales activity. It reports counts, order value, and conversion rates so a team can judge which campaign sources produce commercial results rather than only measuring message delivery. References: erpnext/…/campaign_efficiency.py• L13-69, erpnext/…/opportunities_via_campaigns.json• L1-28

Campaign names also provide a common source for tracking. CRM keeps the campaign record aligned with its marketing source record, which allows source fields on leads and opportunities to support campaign analysis. References: erpnext/…/campaign.py• L35-61, erpnext/…/lead.json• L524-545, erpnext/…/opportunity.json• L626-658

Appointments and communication history

Appointment scheduling

An appointment captures a planned customer meeting or call. It stores the person's contact details, scheduled time, status, and an optional link to a lead or customer. Portal bookings can require email verification. Confirmed appointments can assign an agent and create a calendar event, so the meeting becomes part of the team's shared activity record. References: erpnext/…/appointment.json• L10-28, erpnext/…/appointment.py• L165-196, erpnext/…/appointment.py• L234-246

Appointment booking can enforce working slots, holiday rules, advance-booking limits, and agent capacity. These checks prevent the CRM from promising a time that the configured team cannot support. References: erpnext/…/appointment.py• L55-163, erpnext/…/appointment_booking_settings.py• L42-133

Communication history

Communications and comments form the shared history around a lead, prospect, or opportunity. A communication can link to its main record and to related records. When a contact moves into a prospect or opportunity, CRM can carry forward the relevant comments, emails, open tasks, and events when that setting is enabled. References: erpnext/…/utils.py• L52-90, erpnext/…/prospect.py• L74-91, erpnext/…/opportunity.py• L116-131, erpnext/…/crm_settings.json• L86-106

The activity view separates open work from completed work and checks access to the referenced CRM record before returning it. Received communications can also update the record's modified time when configured, which helps teams notice new customer replies in their work queues. An open event scheduled for the current day can reopen its linked lead or opportunity for follow-up. References: erpnext/…/utils.py• L111-122, erpnext/…/utils.py• L176-287

CRM keeps related work connected as records move through the customer journey. It can link open tasks and events to a new record, show communications through the related prospect, and require write access before a user edits a CRM note. Direct activity access is still controlled by the referenced record. References: erpnext/…/utils.py• L93-181, erpnext/…/utils.py• L212-311

Contract commitments

Contract lifecycle

A contract records the formal terms for a party and can link those terms to a quotation, project, sales or purchase order, or sales or purchase invoice. It tracks whether the agreement is signed, whether it is active for its date range, and whether it has been cancelled or has ended. Contract templates provide reusable terms that are checked as restricted templates and rendered with the contract's party and date data after the template permission is checked. References: erpnext/…/contract.json• L46-101, erpnext/…/contract.json• L157-224, erpnext/…/contract.py• L53-116, erpnext/…/contract_template.py• L31-63

Fulfilment tracking

Contracts can carry a set of fulfilment terms when an agreement requires work after signing. The contract reports whether those terms are unfulfilled, partly fulfilled, fulfilled, or past their deadline. This gives sales and delivery teams a common view of the obligations created by the customer relationship. References: erpnext/…/contract.json• L177-200, erpnext/…/contract.py• L135-180

CRM visibility

CRM reports turn records into views of ownership, conversion, engagement, expected sales, and response speed. Lead reports focus on capture, lead detail, and conversion time. Pipeline reports group opportunity count or value by owner or sales stage over monthly or quarterly periods. First-response reporting shows how quickly opportunities receive a response. This visibility connects daily customer work with sales planning. References: erpnext/…/lead_details.py• L14-120, erpnext/…/lead_conversion_time.py• L13-53, erpnext/…/first_response_time_for_opportunity.py• L13-47, erpnext/…/sales_pipeline_analytics.py• L19-45

The Prospects Engaged But Not Converted report highlights recent, unconverted leads that have received communications. It follows references on the lead and related opportunity, quotation, or open issue so the team can see where engagement occurred before conversion. Its default view considers leads created in the last 60 days and shows one received interaction unless the user changes the filters. References: erpnext/…/prospects_engaged_but_not_converted.py• L20-25, erpnext/…/prospects_engaged_but_not_converted.py• L62-115, erpnext/…/prospects_engaged_but_not_converted.py• L124-134

The CRM workspace gives users a quick view of incoming leads, open opportunities, recent leads, and recent wins. The CRM sidebar provides direct entry to the main sales records, reports, campaigns, appointments, communications, contracts, setup records, and CRM settings. References: erpnext/…/crm.json• L3-37, erpnext/…/crm.json• L47-556, erpnext/…/crm.json• L8-612

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the lead, prospect, and opportunity links aligned when changing how a record is created or converted. Their activity history and account view depend on those links.
  • Preserve lead email validation, duplicate-email settings, and contact reuse when changing lead creation or intake paths.
  • Protect communication-driven lead and opportunity creation with permission checks on both the source communication and the target CRM record. Preserve matching by sender email or phone and the final communication link.
  • Keep contact phone synchronization aligned with the phone fields used by lead intake and later customer work.
  • Preserve the campaign-to-UTM mirror mapping when changing campaign naming or source fields. Campaign reports and campaign lead navigation use the shared source to calculate and display attribution.
  • Keep Campaign schedules and Email Campaign enrollment dates aligned. The enrollment window and daily send dates come from those schedules.
  • Keep Email Campaign recipient validation, duplicate active enrollment checks, and unsubscribe status aligned when changing campaign delivery.
  • Keep engagement reports aligned with the document types and received-communication links that define an engaged but unconverted lead.
  • Review appointment, Event, assignment, and portal verification behavior together when changing booking states or scheduling rules. Capacity checks must still cover concurrent bookings.
  • Review both the contract status rules and fulfilment status rules when changing signed dates, deadlines, or fulfilment terms.
  • Keep contract template validation, restricted rendering, and permission checks aligned when changing reusable contract terms or how templates are applied.
  • Keep activity reads behind permission checks on the referenced CRM record. Keep CRM note edits behind the same write-permission rule as other record changes. Direct child-row updates can otherwise bypass the parent record's access check.
  • Keep the CRM workspace cards, charts, and number cards aligned with the records and reports that remain available to users. Keep the CRM sidebar links aligned with the same navigation surface.
  • Update the cross-links if the child page names change: Lead-to-opportunity lifecycle and Campaign communications.

Important failure modes

TriggerConsequenceGuard
A lead uses an email already used by another lead while duplicate emails are disabledThe new lead is rejected and the acquisition record is not createdKeep the email uniqueness setting and the lead validation rule aligned.
A lead or contact has no email when enrolled in an Email CampaignThe enrollment is rejected and no recipient can receive the sequenceSet a valid recipient email before creating the enrollment.
An Email Campaign starts before the current date or its Campaign has no scheduleThe enrollment is rejected and its delivery window cannot be derivedUse a current or future start date and define at least one schedule entry.
A recipient already has an active or scheduled enrollment for the same CampaignThe duplicate enrollment is rejectedReuse the existing enrollment or wait until it completes.
A scheduled campaign record or recipient has no matching Campaign or email at send timeThe message is not sent and the error is loggedKeep linked Campaign records and recipient email data available through the send window.
A recipient unsubscribes from an Email CampaignIndividual delivery stops through an unsubscribed status or group membershipPreserve unsubscribe events and do not reactivate the recipient without consent.
An opportunity is marked Lost without a lost reasonThe opportunity cannot be saved as lostRequire at least one lost reason in the loss flow.
A team marks an opportunity lost while an active quotation existsThe pipeline cannot show a lost deal that still has a live offerClose, cancel, or let the quotation expire before declaring the opportunity lost.
A caller lacks access to the source Communication or permission to create a Lead during email-based intakeLead or opportunity creation is rejected and the email is not linked to a new CRM recordCheck source-document access and target-record create permission before starting the conversion.
A caller requests open activities without access to the referenced CRM recordActivity data is not returnedKeep activity reads tied to permission on the referenced lead, opportunity, or other CRM record.
An engaged lead has no received communication on the lead or its supported related documentsThe engagement report does not show the leadKeep received communications linked to the correct Lead, Opportunity, Quotation, or open Issue.
A portal appointment is opened before email verificationThe appointment cannot become a confirmed calendar activityComplete the verification step before opening the appointment.
A booking falls outside an allowed slot, holiday rule, advance limit, or agent capacityThe appointment is rejected and no supported time is promisedKeep Appointment Booking Settings current with real team availability.
Two bookings consume the same remaining agent capacity at the same timeMore appointments can be accepted than the team can handlePreserve the capacity lock and overlapping-booking check.
A user edits a CRM note without write access to its recordThe note change is rejected instead of changing the recordCheck write permission before allowing note edits.
A contract template contains invalid template syntaxThe template cannot be saved for use in a contractValidate contract terms before saving the template.
A caller requests a contract template without permissionThe template terms are not returned for renderingCheck access to the template before using it.
A signed contract has an end date before its start dateThe contract fails date validationCheck the contract period before signing or submitting it.
A signed contract is changed after submissionThe signature or fulfilment row set cannot be changed in placeAmend the contract for signature or term changes.
A contract fulfilment deadline passes before all terms are completeThe fulfilment state becomes lapsedTrack the checklist against the deadline and update fulfilled terms.

Key files

FileWhy to read it
erpnext/…/lead.jsonDefines the customer inquiry data, qualification fields, lead status model, and role access for lead records.
erpnext/…/lead.pyShows how lead validation, contact creation, prospect links, and activity carry-forward support the acquisition flow.
erpnext/…/lead.jsShows the lead actions that create or connect prospects, contacts, opportunities, quotations, and customers.
erpnext/…/mapper.pyShows how leads become opportunities, quotations, customers, or new lead records from inbound communications.
erpnext/…/lead_pipeline.jsonShows the lead pipeline view used to follow lead status.
erpnext/…/prospect.jsonDefines the organization-level view that groups leads and opportunities with shared account context.
erpnext/…/opportunity.jsonDefines deal value, stage, probability, ownership, and commercial context.
erpnext/…/opportunity.jsShows opportunity party selection, loss validation, status actions, and links to commercial records.
erpnext/…/opportunity.pyShows the relationship between opportunities, leads, activities, and quotation safeguards.
erpnext/…/mapper.pyShows how opportunities become commercial records and how inbound communications create linked opportunities.
erpnext/…/opportunity_pipeline.jsonShows the opportunity pipeline view used to follow sales stages.
erpnext/…/campaign.jsonDefines campaigns, their descriptions, and their scheduled message sequence.
erpnext/…/campaign.pyKeeps campaign records aligned with their source identity for lead and opportunity attribution.
erpnext/…/email_campaign.pyShows how recipient enrollment, delivery windows, daily sends, and unsubscribe events control campaign communications.
erpnext/…/campaign_efficiency.pyShows how campaign sources are compared with later sales outcomes.
erpnext/…/prospects_engaged_but_not_converted.pyShows how recent received communications identify leads that remain unconverted.
erpnext/…/appointment.pyShows how customer bookings become verified, assigned, and calendar-linked activities.
erpnext/…/appointment_booking_settings.pyDefines the availability and portal rules that control appointment booking.
erpnext/…/utils.pyDefines the shared activity and communication links used across CRM records and protects CRM note edits with record permissions.
erpnext/…/contract.jsonDefines contract parties, terms, links to business documents, signature state, and fulfilment data.
erpnext/…/contract.pyDefines signed status, date status, fulfilment status, and party access for customer commitments.
erpnext/…/contract_template.pyDefines contract template validation, permission checks, and restricted term rendering.
erpnext/…/sales_pipeline_analytics.pyShows how opportunity count and value are grouped by owner or sales stage over time.
erpnext/…/first_response_time_for_opportunity.pyShows how opportunity response speed is measured.
erpnext/…/crm.jsonShows the CRM dashboard cards, charts, and entry points for the main customer-management capabilities.
erpnext/…/crm.jsonShows the CRM navigation groups and links for sales records, reports, campaigns, appointments, communications, contracts, setup, and settings.