Introducing a new way to review your PRs.

Read the announcement

frappe / crm

Fully featured, open source CRM

View on GitHub

24 documents · Updated Nov 23, 2026

docs / erpnext-synchronization

ERPNext synchronization

ERPNext synchronization connects Frappe CRM sales work with ERPNext customers, quotations, and items. It supports ERPNext on the same site or on a separate site. The integration keeps selected product data and access rules aligned while sending sync problems to a user-facing review path. See External business integrations and Lead source synchronization.

Integration configuration

The ERPNext CRM Settings record is the control point for the integration. It selects the ERPNext company and controls customer creation, product sync, and the connection mode. The settings page checks the connection and shows product sync status.

Site connection

The integration supports two site layouts. A same-site setup uses the ERPNext app installed in the current Frappe site. A separate-site setup uses an ERPNext URL with an API key and API secret. The selected company is required in both layouts.

SettingPurpose
EnabledTurns ERPNext-facing CRM actions on or off.
Company in ERPNext siteSelects the company used for ERPNext sales work.
ERPNext installed on a different siteSelects the remote-site connection mode.
ERPNext Site URL, API Key, API SecretAuthenticates the CRM site to a remote ERPNext site.

The settings page validates the remote URL and credentials before it saves the connection. In remote mode it also loads the available ERPNext companies so the user can select a valid company. References: crm/…/erpnext_crm_settings.json• L24-116, crm/…/erpnext_crm_settings.py• L207-216, crm/…/erpnext_crm_settings.py• L333-338, frontend/…/ERPNextSettings.vue• L572-590, frontend/…/ERPNextSettings.vue• L733-784

Customer creation

CRM can create an ERPNext Customer from a CRM Deal when the deal reaches a configured status. The customer represents an organization when the deal has one. Otherwise, the primary contact or lead name provides the individual customer name. CRM stores the resulting ERPNext customer name on the deal and can show a link to the customer.

The same-site path calls ERPNext directly. The remote-site path sends the deal data and its contacts and address through the ERPNext API. CRM checks territory and industry against the target site and leaves those values blank when they do not exist there. A Sales Order or a quotation opened from a CRM Deal can also fill or create the related customer when no customer is present. References: crm/…/erpnext_crm_settings.py• L341-371, crm/…/erpnext_crm_settings.py• L510-545, crm/…/erpnext_crm_settings.py• L569-634, crm/hooks.py• L186-194

Quotation handoff

The CRM Deal action creates a new ERPNext quotation entry point with the deal context. CRM passes the company, customer or prospect, primary contact, address, and deal products so the ERPNext user can continue the sales flow there. Same-site mode uses a local ERPNext form. Remote mode creates a prospect on the ERPNext site before opening its quotation form.

CRM adds a link from the quotation back to the CRM Deal. The quotation item form can then use the linked ERPNext Item for each CRM Product. References: crm/…/erpnext_crm_settings.py• L374-464, crm/…/erpnext_crm_settings.py• L637-690, crm/hooks.py• L52-54

Product synchronization

Product synchronization keeps a CRM Product and an ERPNext Item as one linked catalogue entry. The link uses the CRM product code and ERPNext item code. ERPNext Item data supplies the CRM catalogue view. An optional bidirectional setting lets CRM Product changes update the ERPNext Item.

Product ownership

When same-site synchronization is active, ERPNext is the creation path for new products. Creating a CRM Product directly is blocked when bidirectional product sync is enabled. Creating an ERPNext Item creates the linked CRM Product and copies the catalogue values.

DirectionWhen it runsMain result
Item to CRM ProductSame-site integration is enabledCreates or updates the CRM catalogue record.
CRM Product to ItemSame-site integration and Bidirectional Product Sync are enabledUpdates the linked ERPNext Item.

The shared catalogue values are standard rate, image, disabled state, and description. When CRM reads the current price, an ERPNext Item Price takes priority over the Item standard rate. If no Item Price exists, CRM uses the Item standard rate. A missing rate becomes zero before CRM stores it. Link fields are maintained on both records so later changes can find the other side. References: crm/…/utils.py• L9-23, crm/…/item.py• L13-45, crm/…/item.py• L48-79, crm/…/crm_product.py• L37-61, crm/…/crm_product.py• L88-100

Product reconciliation

Reconciliation is a background repair pass for the linked catalogue. It compares all ERPNext Items and CRM Products by product code, restores links for exact code matches, creates missing records, and clears links to deleted ERPNext Items. Enabling the integration queues this pass. The settings page also provides a manual sync action for same-site installations.

The reconciliation uses ERPNext Items as the source for CRM records. It creates ERPNext Items from CRM Products only when bidirectional product sync is enabled. It also runs the access-rule and document-share mirror passes after the product links are settled.

This diagram shows the main reconciliation path from settings to linked catalogue records and access data.

flowchart LR
    A[ERPNext CRM Settings] --> B[Queue reconciliation]
    B --> C[Read Items and CRM Products]
    C --> D[Match by product code]
    D --> E[Create or update product links]
    D --> F[Record orphan links]
    E --> G[Mirror User Permissions]
    E --> H[Mirror DocShare records]

References: crm/…/erpnext_crm_settings.py• L54-66 crm/…/erpnext_crm_settings.py• L218-225 crm/…/reconcile_job.py• L11-37 crm/…/reconcile_job.py• L50-68 crm/…/reconcile_job.py• L131-194 crm/…/reconciliation.py• L15-38

Product names and lifecycle

CRM keeps the product name usable by falling back to the product code when no name is set. Updates move across the active sync direction without starting a second sync cycle. Renames cascade to the linked record. An unrelated record with the requested new name blocks the rename so two catalogue entries do not become linked by mistake.

Deleting a linked CRM Product can fail when its ERPNext Item is used by a quotation. Deleting an ERPNext Item removes the linked CRM Product when the integration is active. A missing linked Item is treated as an orphan during reconciliation and the CRM link is cleared. References: crm/…/crm_product.py• L48-85, crm/…/item.py• L82-102, crm/…/utils.py• L55-120

Document sharing

Document sharing mirrors access to a linked CRM Product and ERPNext Item. A DocShare record is the Frappe record that grants a user access to one document. When the integration is active, a share on one side creates the matching share on the other side.

The mirror keeps the same user and share settings while changing the target doctype and name. Updates to the target or share state are copied. Changes to the target document or its share name remove the old mirror before the new one is created. Delete operations remove the matching mirror. A full sync repairs missing shares after product reconciliation.

References: crm/…/doc_share.py• L7-48 crm/…/doc_share.py• L51-82 crm/…/mirror_sync.py• L37-126

Permission synchronization

User permission synchronization gives a user matching restrictions for a linked CRM Product and ERPNext Item. A User Permission record limits which value a user can use for an allowed doctype. The mirror keeps the user, target value, and permission scope aligned across both doctypes.

The sync includes the permission scope that identifies an applicable doctype and whether the rule applies to all doctypes. It avoids duplicate mirrors. A bulk pass repairs missing permissions after product reconciliation, while document events keep later changes aligned.

References: crm/…/user_permission.py• L7-17 crm/…/user_permission.py• L20-52 crm/…/user_permission.py• L55-87 crm/…/mirror_sync.py• L47-113 crm/hooks.py• L203-214

Sync issue handling

Sync issues record cases that need human review instead of silently restoring a bad link. The current issue type is an orphan CRM Product whose linked ERPNext Item no longer exists. The issue stores the product, issue kind, detail, detection time, and dismissal state.

The product sync log shows linked CRM Products, linked ERPNext Items, and open failed logs. The status view also reports records that are not yet synced. A user with CRM Product read access can view the status and dismiss an issue. Dismissal hides the issue from the open list. It does not recreate the missing Item or link.

When a sync fails during customer creation or a remote-site operation, CRM writes the error details to the Error Log and returns a clear error to the user. Remote custom-field setup can also warn that fields must be enabled in ERPNext CRM Settings when automatic creation is not available. References: crm/…/crm_product_sync_issue.json• L15-50, crm/…/erpnext_crm_settings.py• L19-28, crm/…/erpnext_crm_settings.py• L147-164, crm/…/erpnext_crm_settings.py• L229-266, crm/…/erpnext_crm_settings.py• L620-628, frontend/…/ERPNextSettings.vue• L524-570

Change checklist

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

  • Keep the same-site and remote-site rules aligned between the settings form and the server-side guards. Remote credentials must not become required for a same-site setup.
  • Keep the two product link fields aligned when product naming, creation, rename, or delete behavior changes: CRM Product.erpnext_item_code and Item.crm_product_code.
  • If catalogue price behavior changes, review the Item Price lookup, standard-rate fallback, and the CRM Product to Item path together.
  • If the catalogue fields change, update Item-to-Product sync, Product-to-Item sync, reconciliation, and the product status view together.
  • If the product matching rule changes, review orphan detection and the mirrored DocShare and User Permission targets.
  • If a new sync issue kind is added, update the issue schema and the settings log so users can identify and dismiss it.
  • If the quotation or customer contract changes, check both local ERPNext calls and remote ERPNext API payloads.
  • Keep Item event handlers in crm/hooks.py aligned with their import paths. These handlers must remain document events rather than class overrides.

Important failure modes

TriggerConsequenceGuard
Integration is enabled without ERPNext installed in same-site modeSettings validation fails and product reconciliation skipsUse remote-site mode with valid connection details or install ERPNext on the current site.
Remote URL, API key, or API secret is missing or invalidCompany lookup or customer and prospect creation failsValidate the site connection before saving or using ERPNext actions.
No default ERPNext selling price list existsCRM cannot use an Item Price and falls back to the Item standard rateConfigure the default selling price list when Item Prices must drive CRM rates.
Product code matches an unrelated record on the other sideA link could point to the wrong catalogue entryReconciliation links exact codes. Rename conflict checks block unrelated collisions.
A linked ERPNext Item is deletedThe CRM Product becomes an orphanRun product reconciliation and review the recorded orphan issue.
CRM Product deletion is attempted while its Item is used by a quotationDeletion is rejected to protect the quotationRemove the quotation reference or delete the Item in ERPNext first.
A user lacks read access to CRM Product or ItemSync status or one side of access data may be unavailableGrant the required read permission before reviewing sync state.

Key files

FileWhy to read it
crm/…/erpnext_crm_settings.pyDefines the integration settings, customer flow, quotation handoff, status data, and error handling.
crm/…/erpnext_crm_settings.jsonDefines the settings contract and the options exposed to users.
frontend/…/ERPNextSettings.vueShows how users validate the connection, start product sync, and review sync status.
crm/…/reconcile_job.pyDefines the full catalogue reconciliation lifecycle.
crm/…/crm_product.pyDefines CRM Product behavior when ERPNext Item sync is active.
crm/…/item.pyDefines Item events, Item Price selection, and the Item-to-CRM Product path.
crm/…/utils.pyDefines sync activation, link lookup, and rename coordination.
crm/…/mirror_sync.pyDefines the shared mirror behavior used for access records.
crm/…/doc_share.pyDefines document-share mirroring and repair.
crm/…/user_permission.pyDefines user-permission mirroring and repair.
crm/…/crm_product_sync_issue.jsonDefines the issue data shown in the product sync log.
crm/…/test_utils.pyShows the supported hook wiring and the price selection and fallback behavior guarded by tests.
crm/hooks.pyShows which CRM and ERPNext document events start the integration flows.