ERPNext integration
The ERPNext integration connects Helpdesk customer records with ERPNext customer records. It keeps the two records and their access rules aligned so that helpdesk work can use customer data managed across both products. This page is a child of Integrations and telephony; the related Telephony and call logs page covers the other integration area.
Integration model
The integration is an optional bridge between the Helpdesk HD Customer record and the ERPNext Customer record. A link on each record identifies its counterpart, while Helpdesk continues to use HD Customer for ticket and customer desk work. The bridge is active only when ERPNext is installed and the integration setting is enabled. helpdesk/…/utils.py• L19-39 helpdesk/…/hd_customer.json• L9-24
Customer record pairing
Customer pairing gives each Helpdesk customer one ERPNext counterpart and each ERPNext customer one Helpdesk counterpart. The link is stored on both sides, so either system can find the record used by the other system. helpdesk/…/utils.py• L25-39
The initial sync reconciles existing records in both directions. It links records with a matching name when possible. If no matching record exists, it creates the missing counterpart instead of leaving the customer outside the bridge. helpdesk/…/api.py• L63-130
References: helpdesk/…/utils.py• L25-39 helpdesk/…/api.py• L63-130 helpdesk/…/hd_customer.json• L9-24 helpdesk/…/test_erpnext_integration.py• L951-971
Customer data mirroring
The paired records share selected customer data so that both products present a consistent customer view. The current shared fields are the image and customer type. A change on either side updates the counterpart without starting a second sync cycle. helpdesk/…/utils.py• L11-16 helpdesk/…/hd_customer.py• L373-404
Record creation also works in both directions. A new ERPNext customer can create an HD Customer, and a new Helpdesk customer can create an ERPNext customer. The integration skips this behavior when it is disabled or when an operation was already started by the bridge. helpdesk/…/customer.py• L15-40 helpdesk/…/hd_customer.py• L373-398
References: helpdesk/…/utils.py• L11-16 helpdesk/…/utils.py• L189-217 helpdesk/…/customer.py• L15-40 helpdesk/…/hd_customer.py• L373-404 helpdesk/…/test_erpnext_integration.py• L46-178
Record lifecycle alignment
The bridge treats the paired records as one customer identity across the two products. A rename carries the new name to the counterpart. Before the rename, the integration checks for an unrelated record that would make the pair ambiguous. Deleting one customer deletes its counterpart after the link is cleared. helpdesk/…/utils.py• L74-160 helpdesk/…/hd_customer.py• L406-425
These lifecycle rules protect the customer link while allowing Helpdesk tickets and customer membership to remain attached to the Helpdesk record. A name conflict is therefore a deliberate stop condition rather than an automatic merge with an unrelated customer. helpdesk/…/customer.py• L42-65
Record merges follow the same identity rule. The linked ERPNext record moves to the merge target when the target has no counterpart, combines with the target counterpart when both sides are linked, and stops when an unrelated ERPNext record would make the result ambiguous. helpdesk/…/test_erpnext_integration.py• L1007-1226
References: helpdesk/…/utils.py• L74-160 helpdesk/…/customer.py• L42-65 helpdesk/…/hd_customer.py• L406-425 helpdesk/…/test_erpnext_integration.py• L184-208 helpdesk/…/test_erpnext_integration.py• L1007-1226
Access rule mirroring
The integration carries customer access decisions across the paired records. It mirrors Frappe user permissions and document shares only for the two customer doctypes, which keeps a user's access to a customer aligned in Helpdesk and ERPNext. helpdesk/…/mirror_sync.py• L63-72
User permissions
User permissions restrict which customer records a user can access. When a permission points to an ERPNext customer, the integration creates the matching permission for the linked Helpdesk customer. The reverse direction works the same way, and repeated syncs do not create duplicate permissions. helpdesk/…/user_permission.py• L47-104
Changes to the permission target or allowed doctype replace the old mirror with one for the new identity. The mirror keeps the permission scope, including whether it applies to all doctypes or only a selected doctype. helpdesk/…/test_erpnext_integration.py• L696-845 helpdesk/…/test_erpnext_integration.py• L847-1001
References: helpdesk/…/user_permission.py• L28-44 helpdesk/…/user_permission.py• L47-104 helpdesk/…/mirror_sync.py• L74-96 helpdesk/…/test_erpnext_integration.py• L615-1001
Document shares
Document shares grant a user direct access to a customer record. The integration mirrors a share from HD Customer to Customer or from Customer to HD Customer, including later changes and deletion. Unlinked records are not mirrored because the bridge has no safe target. helpdesk/…/doc_share.py• L40-100
When a share changes its customer or doctype, the integration removes the old mirror and creates a new one for the new linked identity. If the new record is unlinked, it removes the old mirror without creating another. helpdesk/…/test_erpnext_integration.py• L451-610
References: helpdesk/…/doc_share.py• L7-38 helpdesk/…/doc_share.py• L40-100 helpdesk/…/mirror_sync.py• L27-61 helpdesk/…/test_erpnext_integration.py• L261-610
Synchronization workflow
The synchronization workflow combines automatic updates for new changes with one background reconciliation for records that existed before the integration was enabled. The settings interface uses the sync state to show whether the customer sets are complete. The server reports the state only when ERPNext is installed and the user can read both customer doctypes. helpdesk/…/api.py• L9-38
The main flow is:
flowchart TD
A[ERPNext installed] --> B[Enable integration]
B --> C{All customers linked?}
C -->|No| D[Start background customer sync]
D --> E[Link or create customer counterparts]
E --> F[Mirror user permissions and document shares]
F --> G[Report sync complete]
C -->|Yes| H[Automatic create and update sync]
G --> H
The manual sync checks write access to both customer records before it starts. It queues one long-running job and sends start and end events. The end event is sent after the database commit, so the desk can reload a completed sync state instead of reading links from before the job committed. helpdesk/…/api.py• L41-60 helpdesk/…/api.py• L63-142
The sync state is false while either side has unlinked customers and becomes true after reconciliation links or creates all required counterparts. Re-running permission sync is safe when the mirrors already exist. helpdesk/…/test_erpnext_integration.py• L912-971
References: helpdesk/…/api.py• L9-38 helpdesk/…/api.py• L41-60 helpdesk/…/api.py• L63-142 helpdesk/…/test_erpnext_integration.py• L912-971
Desk settings
The ERPNext settings page is the operational entry point for the bridge. It is available under the desk's Integrations settings for administrators and agent managers. The page reports whether ERPNext is installed, controls the enabled state, and exposes the initial sync action when existing customers need reconciliation. desk/…/settingsModal.ts• L138-152 desk/…/ERPNextIntegrationSettings.vue• L1-69
Installation and enablement state
The desk reads ERPNext's installed state from the site's boot app list and disables the switch when ERPNext is not installed. The server also checks that ERPNext is installed before it reports the integration as available. Enabling the setting creates the ERPNext-side link field needed to connect customer records. desk/…/ERPNextIntegrationSettings.vue• L43-69 helpdesk/…/erpnext_hd_settings.py• L11-26
The server hides the enabled state when the user lacks read access to either customer doctype. This prevents the settings page from presenting a usable integration state to a user who cannot inspect the records it would synchronize. helpdesk/…/api.py• L9-26
References: desk/…/ERPNextIntegrationSettings.vue• L1-69 helpdesk/…/api.py• L9-26 desk/…/settingsModal.ts• L138-152 helpdesk/…/erpnext_hd_settings.py• L11-26 helpdesk/…/erpnext_hd_settings.json• L8-17
Sync status and action
The page distinguishes a complete link set from a site that needs an initial sync. When records are missing links, an administrator or manager can start the background reconciliation. The page disables the action while the job runs and reloads its state after the completion event. desk/…/ERPNextIntegrationSettings.vue• L72-127 desk/…/ERPNextIntegrationSettings.vue• L153-235
The older Frappe form provides the same initial sync capability through a Sync Customers button. Both desk surfaces use the same server action, so they share the same permission checks and background behavior. helpdesk/…/erpnext_hd_settings.js• L4-45
References: desk/…/ERPNextIntegrationSettings.vue• L72-127 desk/…/ERPNextIntegrationSettings.vue• L153-235 helpdesk/…/erpnext_hd_settings.js• L4-45 helpdesk/…/api.py• L41-60
Helpdesk customer context
The Helpdesk desk presents HD Customer as the customer context for support work. Agents can list customers, open a customer page, and see its tickets and contacts; the ERPNext link supports cross-product identity without changing those support-facing views. desk/…/Customers.vue• L46-81 desk/…/Customer.vue• L37-79
The customer record also carries the hidden ERPNext counterpart name. This keeps the cross-product link available to the integration while the desk focuses on support details such as customer contacts and related tickets. helpdesk/…/hd_customer.json• L62-72
References: desk/…/Customers.vue• L46-81 desk/…/Customer.vue• L37-79 helpdesk/…/hd_customer.json• L62-72
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the two customer link fields and their name-resolution rules aligned when either customer doctype changes.
- Keep the shared customer field set consistent with both create-time mapping and update-time mirroring.
- Keep user permission and document share identity rules aligned with the target doctype names and linked customer names.
- Keep both desk settings surfaces aligned with the server sync status, permission checks, and real-time completion events.
- Keep customer deletion and rename behavior compatible with ticket links and the counterpart record.
- Keep the desk's installed-state and sync-state display aligned with the server's read and write permission checks.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| ERPNext is not installed while the setting is enabled | The setting cannot be saved and the desk cannot start synchronization | Installation checks run in the desk and in the settings document validation. |
| A user cannot read both customer doctypes | The settings API does not expose the integration as enabled | The sync status endpoint checks read permission before returning the enabled state. |
| A customer name conflicts with an unrelated counterpart during rename or merge | The customer pair can no longer map safely, so the operation stops | Rename validation rejects the conflict before the counterpart is changed. |
| The integration is enabled but existing customers are not linked | New updates can work while older records remain outside cross-product access and data sync | The settings page marks the site out of sync and offers the background reconciliation. |
| A permission or share points to an unlinked customer | No safe counterpart exists for the access rule | Mirror creation skips records that have no linked customer. |
| A user lacks write access to either customer doctype when starting a sync | The background reconciliation is not queued | The sync action checks write permission on both doctypes before enqueueing the job. |
| A mirror operation triggers the same integration hook again | The two sides can repeatedly create or update each other | Sync-created records carry an integration guard flag. |
Key files
| File | Why to read it |
|---|---|
| helpdesk/…/api.py | Shows the public sync status, permission gates, and full customer reconciliation flow. |
| helpdesk/…/utils.py | Defines the integration boundary, customer links, shared fields, and lifecycle rules. |
| helpdesk/…/hd_customer.py | Shows how Helpdesk customer creation, updates, renames, and deletes participate in the bridge. |
| helpdesk/…/customer.py | Shows the ERPNext-side customer events that complete the two-way lifecycle. |
| helpdesk/…/user_permission.py | Shows how customer access permissions cross the product boundary. |
| helpdesk/…/doc_share.py | Shows how direct customer shares cross the product boundary. |
| helpdesk/…/mirror_sync.py | Shows the shared behavior used to keep access records mirrored without loops or duplicates. |
| helpdesk/…/erpnext_hd_settings.py | Shows the server-side enablement checks for the integration setting. |
| desk/…/ERPNextIntegrationSettings.vue | Shows the desk enablement, sync-state display, and real-time job status. |
| desk/…/settingsModal.ts | Shows where ERPNext appears in the desk settings navigation and who can access it. |
| desk/…/Customers.vue | Shows the Helpdesk customer list that serves as the support-facing entry point. |
| desk/…/Customer.vue | Shows the customer detail context with related tickets and contacts. |
| helpdesk/…/test_erpnext_integration.py | Shows the supported two-way sync, access mirror, rename, merge, and disabled-state contracts. |