Description
n8n-nodes-erpnext-stock




Community n8n node package for ERPNext/Frappe Stock v15-v16.
This package is part of the n8n2erpnext ecosystem. It focuses on real inventory movement, warehouse balances, batch/serial traceability, Bin verification, and Stock Ledger Entry verification.
Connected Ecosystem Coverage
Stock is the operational center of the n8n2erpnext ERP ecosystem. The live workflow suite proves that Buying, Stock, Selling, and Accounting work together as one business system, not as separate community nodes.
Two end-to-end enterprise workflows are included and live-tested:
- Standard Product Lifecycle: Supplier -> Purchase Receipt -> inventory increase -> Purchase Invoice -> Customer Sale -> Sales Invoice
update_stock = 1-> inventory decrease -> final Bin/SLE/accounting verification. - Exception / After-Sales Lifecycle: sale -> return credit note -> warranty warehouse -> defective warehouse -> repair/virtual workshop -> disposal -> final Bin/SLE/accounting verification.
- Linked Purchase Invoice blocks unsafe Purchase Receipt cancellation.
- Linked Sales Invoice blocks unsafe Delivery Note cancellation.
- Non-stock fee/rebate invoices do not create Stock Ledger Entry rows.
- Core inventory lifecycle: Item Group, parent/child Warehouse, Item, Material Receipt, Material Transfer, Stock Reconciliation, Delivery Note, Bin checks, and Stock Ledger Entry checks.
- Batch and Serial flows: batch receipt/issue, serial receipt/issue, duplicate protection, and serial reuse failure.
- Negative inventory protection: over-issue, wrong warehouse, disabled item, missing warehouse, duplicate Batch, and duplicate Serial No.
- Cross-module integrity: Buying Purchase Receipt/Purchase Invoice lock and Delivery Note cancel blocked by linked Sales Invoice.
- Retail operations: sale, customer return, warranty warehouse, defective warehouse, repair/virtual workshop movement, disposal, exchange, and non-stock return fee.
- Manufacturing basics: BOM, Work Order, WIP transfer, Manufacture Stock Entry, Finished Goods stock, and Sales Invoice
update_stock = 1. - FMCG/Fresh basics: batch expiry, batch sale, spoilage/damage issue, vendor claim warehouse movement, claim closure/return-to-supplier style issue, and non-stock fee/rebate invoice with no Stock Ledger Entry.
- ERP administrators who maintain ERPNext/Frappe.
- Warehouse, retail, manufacturing, finance, or operations teams that need reliable stock movement workflows.
- Integration teams that want repeatable n8n automations without writing custom Frappe client code for every inventory process.
The suite also verifies cross-module document protection:
This positions the project as ERPNext operational inventory workflow validation focused on Retail, Distribution, FMCG/Fresh basics, and Manufacturing basics.
Live-Tested Status
This package has been live-tested end to end on the project ERPNext/Frappe test environment:
| Area | Status |
| — | — |
| ERPNext/Frappe target | Live-tested on ERPNext v16/Frappe v16 behavior |
| n8n runtime | Live-tested on self-hosted n8n 2.20.7-exp.0 |
| Infrastructure | Live-tested through LXD ERPNext container at http://10.192.135.2:8001 with host header erp.thaiduy.digital |
| API coverage | Live-tested with Frappe API v1 read workflows and API v2 document workflows |
| Ecosystem coverage | Buying -> Stock -> Selling -> Accounting end-to-end workflows |
| Core stock lifecycle | Material Receipt, Material Transfer, Stock Reconciliation, Delivery Note, Bin, and Stock Ledger Entry |
| Retail and after-sales coverage | Sale, return credit note, warranty, defective stock, repair/virtual workshop, disposal, exchange, and return fee |
| Manufacturing coverage | BOM, Work Order, WIP transfer, Manufacture Stock Entry, Finished Goods, and finished-goods sale |
| FMCG/Fresh coverage | Batch expiry, batch sale, spoilage/damage, vendor claim warehouse, claim closure, and non-stock fee/rebate |
| Negative coverage | Over-issue, wrong warehouse, disabled item, missing warehouse, duplicate Batch/Serial, linked-document cancel locks |
| Security response policy | Public webhook responses were allowlisted summaries; securityFindings: [] |
| Cleanup | Temporary workflows were deactivated and verified as 404 Active version not found |
The live verification used traceable demo records in the ERPNext LXD test instance. The README intentionally includes test infrastructure routing values and document IDs, but no API keys, API secrets, Authorization headers, database passwords, npm tokens, or credential material.
Tested Operational Coverage
Stock is intentionally tested more deeply than Buying and Selling because submitted Stock documents change real inventory balances and ledger rows.
The current live workflow suite validates core Stock, retail, distribution, FMCG/Fresh basics, and Manufacturing basics:
The scope is operational validation, not enterprise planning. Advanced MRP, capacity planning, workstation scheduling, demand forecasting, dynamic pricing, chain-wide replenishment, and production analytics are intentionally outside this Stock node validation suite.
Who This Is For
This package is built for teams that run ERPNext Stock and want controlled inventory automations in n8n.
Typical users:
The node is intentionally conservative: it exposes standard Stock document operations, supports Frappe API v1 and v2, keeps Bin and Stock Ledger Entry read-only, and allows controlled fallback access to custom DocTypes and whitelisted Frappe methods.
Architecture At A Glance
Read workflow from left to right:
ERPNext / Frappe Stock <---- API token ----> n8n ERPNext Stock node <---- webhook/API ----> Client / App / Report
Common read pattern:
Client
-> n8n Webhook
-> ERPNext Stock node
-> Frappe REST API
-> ERPNext Stock DocType
-> filtered JSON response
Common inventory lifecycle pattern:
n8n Webhook / Schedule / App Event
-> validation / mapping / approval logic
-> ERPNext Stock node
-> Item, Warehouse, Stock Entry, Stock Reconciliation, Delivery Note, Batch, Serial No, Bin, or Stock Ledger Entry
-> safe summary response or downstream system
Recommended production network pattern:
Public Client
-> HTTPS reverse proxy / VPN / allowlist
-> n8n
-> private network or internal VPS address
-> ERPNext / Frappe site
Supported Resources
Bin and Stock Ledger Entry are intentionally read-only verification resources. They expose only Get and Get Many.
Custom DocType is used when a Stock workflow crosses into another ERPNext module, such as BOM, Work Order, Sales Invoice, or Purchase Invoice.
Node Identity
All n8n2erpnext module nodes use the same ERPNext-style logo shape. Each module changes only the main background color.
| Module | Color | Hex | Reason |
| — | — | — | — |
| Core | ERPNext blue | #2490EF | Foundation package, closest to the ERPNext brand color. |
| HRMS | People green | #2E7D5F | Human operations, employees, attendance, leave, payroll. |
| Accounting | Finance orange-red | #D94A2B | Ledger, journals, invoices, financial control. |
| Buying | Procurement amber | #C47F00 | Purchase flow, suppliers, RFQs, purchase orders, receipts, spend. |
| Selling | Commerce teal | #00A6A6 | Customer-facing pipeline, quotations, sales orders, revenue. |
| Stock | Frappe black | #171717 | Warehouses, items, inventory movement; aligned with Frappe black. |
When building another module, copy the HRMS/Accounting SVG structure and change only the main background fill to that module color.
Operations
For writable Stock doctypes:
For read-only verification doctypes:
For Frappe methods:
API Versions
The node supports both ERPNext/Frappe document API styles:
v1: /api/resource/:doctypev2: /api/v2/document/:doctypeUse v1 for broad compatibility. Use v2 when your ERPNext/Frappe v16 environment is ready for the newer document API behavior.
Submit and cancel use the shared n8n2erpnext helper rule:
{ doc } to frappe.client.submit.{ doctype, name } to frappe.client.cancel.Reference:
Credentials
Create an API key and secret in ERPNext/Frappe, then configure:
https://erp.example.comerp.example.comThe node authenticates with:
Authorization: token apikey:apisecret
Credential fields are marked as password fields where appropriate. Do not expose API keys, API secrets, Authorization headers, tokens, or passwords in webhook responses, logs, README examples, or package artifacts.
Internal URL With Public Host Header
When n8n and ERPNext run on the same VPS, you can point n8n at the internal ERPNext address and still send the public ERPNext host header:
http://erpnext.internal:8001erp.example.comThis avoids public reverse-proxy authentication while still letting ERPNext receive the expected site host.
For the current VPS/LXD test setup:
Site URL: http://10.192.135.2:8001
Site Host Header: erp.thaiduy.digital
This is infrastructure routing information for the project test environment, not credential material. API keys and API secrets are not included in this README.
For production, create a dedicated ERPNext integration user instead of using a daily admin account. Give that user only the roles required for the workflows it runs.
Official Frappe references:
Examples
Get current Bin quantity for an Item/Warehouse:
{
"resource": "bin",
"operation": "getMany",
"apiVersion": "v1",
"fields": "name,itemcode,warehouse,actualqty,projectedqty,valuationrate,stock_value",
"filtersJson": {
"item_code": "N8N-STOCK-ITEM-001",
"warehouse": "N8N Target Warehouse - TDD"
},
"returnAll": false,
"limit": 20,
"orderBy": "modified desc"
}
Get Stock Ledger Entries for a voucher:
{
"resource": "stockLedgerEntry",
"operation": "getMany",
"apiVersion": "v1",
"fields": "name,itemcode,warehouse,vouchertype,voucherno,actualqty,qtyaftertransaction,serialandbatch_bundle",
"filtersJson": {
"voucher_type": "Stock Entry",
"voucher_no": "MAT-STE-2026-00058"
},
"returnAll": false,
"limit": 20,
"orderBy": "postingdate desc, postingtime desc"
}
Create a Material Receipt Stock Entry:
{
"resource": "stockEntry",
"operation": "create",
"apiVersion": "v2",
"dataJson": {
"stockentrytype": "Material Receipt",
"company": "Your Company",
"items": [
{
"item_code": "N8N-STOCK-ITEM-001",
"t_warehouse": "N8N Target Warehouse - TDD",
"qty": 10,
"basic_rate": 25
}
]
}
}
Then submit it with:
{
"resource": "stockEntry",
"operation": "submit",
"apiVersion": "v2",
"documentName": "MAT-STE-2026-00058"
}
Use Custom DocType for manufacturing-adjacent documents:
{
"resource": "customDocType",
"customDocType": "Work Order",
"operation": "get",
"apiVersion": "v2",
"documentName": "MFG-WO-2026-00002"
}
Run a whitelisted Frappe method:
{
"resource": "frappeMethod",
"operation": "runMethod",
"methodName": "frappe.client.get_value",
"argumentsJson": {
"doctype": "Bin",
"filters": {
"item_code": "N8N-STOCK-ITEM-001",
"warehouse": "N8N Target Warehouse - TDD"
},
"fieldname": ["name", "actualqty", "stockvalue"]
}
}
Webhook From n8n to ERPNext Stock
Use this pattern when you want an HTTP endpoint in n8n that reads or writes Stock data in ERPNext.
Client / Browser / App / BI Tool
-> n8n webhook URL
-> ERPNext Stock node
-> GET/POST /api/resource or /api/v2/document
-> ERPNext Stock DocType
-> JSON response or safe summary
1. Configure the ERPNext Credential
In n8n, create or edit an ERPNext API credential:
http://erpnext.internal:8001erp.example.comfalseFor the current VPS/LXD production setup:
Site URL: http://10.192.135.2:8001
Site Host Header: erp.thaiduy.digital
2. Create a Read Workflow
Create a workflow with these nodes:
GET Webhook -> ERPNext Stock
Webhook node:
GETerpnext-stock-get-warehousesWhen Last Node FinishesAll EntriesERPNext Stock node:
ERPNext API credentialWarehouseGet Manyv1name,warehousename,parentwarehouse,company,is_group,disabled[]false20modified desc3. Activate and Test
Activate the workflow, then call:
curl -i https://n8n.example.com/webhook/erpnext-stock-get-warehouses
On the local VPS, you can test without going through the public proxy:
curl -i http://127.0.0.1:5678/webhook/erpnext-stock-get-warehouses
The working workflow artifact is included in this repository:
n8n-webhook-erpnext-stock-get-warehouses.workflow.json
Webhook From ERPNext v16 to n8n
Use this pattern when ERPNext should call n8n automatically after a Stock document is created, submitted, cancelled, or updated. For example, ERPNext can call a n8n workflow whenever a Stock Entry, Delivery Note, Batch, or Serial No changes.
ERPNext Doc Event
-> Frappe Webhook
-> POST n8n webhook URL
-> n8n workflow
-> validation, notification, sync, audit, replenishment, or downstream automation
1. Create The n8n Webhook Receiver
Create a workflow in n8n with a Webhook trigger:
Webhook -> your processing nodes
Webhook node:
POSTerpnext-stock-eventNone for a private/internal test, or Header Auth for productionImmediately or When Last Node FinishesThe production webhook URL will look like:
https://n8n.example.com/webhook/erpnext-stock-event
On this VPS, if ERPNext and n8n are on the same host/network, you can also use an internal n8n URL from ERPNext.
2. Add The Webhook In ERPNext/Frappe v16
In ERPNext/Frappe Desk:
1. Open the global search bar.
2. Search for Webhook.
3. Open Webhook from the Integrations area.
4. Click New.
Configure the Webhook:
Stock Entry, Delivery Note, Batch, Serial No, or another Stock DocTypeonsubmit, oncancel, afterinsert, or onupdate depending on the workflowPOSTJSONExample JSON body:
{
"event": "stockentrysubmitted",
"doctype": "{{ doc.doctype }}",
"name": "{{ doc.name }}",
"company": "{{ doc.company }}",
"stockentrytype": "{{ doc.stockentrytype }}",
"postingdate": "{{ doc.postingdate }}",
"fromwarehouse": "{{ doc.fromwarehouse }}",
"towarehouse": "{{ doc.towarehouse }}",
"docstatus": "{{ doc.docstatus }}",
"modified": "{{ doc.modified }}"
}
For production, add a shared secret header and validate it in n8n:
X-ERPNext-Webhook-Secret: your-long-random-secret
If you use Frappe’s Webhook Secret field, Frappe adds an X-Frappe-Webhook-Signature header generated from the payload and secret. You can verify this signature in n8n with a Code node if needed.
Official Frappe reference:
Tested Workflow Artifacts
The repository includes workflow artifacts used during live ERPNext LXD testing.
Read-only artifact:
n8n-webhook-erpnext-stock-get-warehouses.workflow.json
Core Stock lifecycle artifacts:
n8n-webhook-erpnext-stock-v2-inventory-lifecycle-test.workflow.json
n8n-webhook-erpnext-stock-v2-reconciliation-cancel-test.workflow.json
n8n-webhook-erpnext-stock-v2-delivery-note-test.workflow.json
n8n-webhook-erpnext-stock-v2-batch-test.workflow.json
n8n-webhook-erpnext-stock-v2-serial-test.workflow.json
n8n-webhook-erpnext-stock-v2-negative-cases-test.workflow.json
Cross-module and operational artifacts:
n8n-webhook-erpnext-stock-v2-linked-invoice-dn-cancel-test.workflow.json
n8n-webhook-erpnext-stock-v2-buying-receipt-invoice-lock-test.workflow.json
n8n-webhook-erpnext-stock-v2-repack-manufacturing-test.workflow.json
n8n-webhook-erpnext-stock-v2-retail-return-warranty-test.workflow.json
n8n-webhook-erpnext-stock-v2-retail-exchange-fee-test.workflow.json
n8n-webhook-erpnext-stock-v2-manufacturing-basic-test.workflow.json
n8n-webhook-erpnext-stock-v2-fmcg-fresh-basic-test.workflow.json
Enterprise E2E artifacts:
n8n-webhook-erpnext-stock-v2-e2e-standard-product-lifecycle-test.workflow.json
n8n-webhook-erpnext-stock-v2-e2e-exception-return-warranty-lifecycle-test.workflow.json
Stock write-test workflows create real demo/test documents in the ERPNext LXD test instance. They should be activated only during testing and deactivated after verification unless a trusted operator intentionally keeps them active.
Enterprise E2E And Stock Lifecycle Tests
Stock write tests are intentionally shipped as inactive workflow artifacts. Import and review them before activation because they create submitted inventory, selling, buying, and accounting documents.
Standard Product Lifecycle artifact:
n8n-webhook-erpnext-stock-v2-e2e-standard-product-lifecycle-test.workflow.json
Standard lifecycle shape:
POST Webhook
-> Create Supplier, Customer, Item Group, Warehouse, stock Item
-> Create and submit Purchase Receipt
-> Verify Bin and Stock Ledger Entry increase
-> Create and submit linked Purchase Invoice
-> Verify Purchase Receipt cancel is blocked by the linked invoice
-> Create and submit Sales Invoice with update_stock = 1
-> Verify Bin decrease and Stock Ledger Entry negative movement
-> Return safe allowlisted summary
Verified result:
Run ID: N8N-STOCK-E2E-STD-1779149074499
Status: passed
Purchase Receipt: MAT-PRE-2026-00005
Purchase Invoice: ACC-PINV-2026-00004
Sales Invoice: ACC-SINV-2026-00028
Purchased quantity: 5
Sold quantity: 2
Final Bin actual_qty: 3
Security findings: []
Exception / After-Sales Lifecycle artifact:
n8n-webhook-erpnext-stock-v2-e2e-exception-return-warranty-lifecycle-test.workflow.json
Exception lifecycle shape:
POST Webhook
-> Create Customer, Item Group, sellable/warranty/defective/repair Warehouses, stock Item
-> Create and submit Material Receipt
-> Create and submit Sales Invoice with update_stock = 1
-> Create and submit return Credit Note into warranty warehouse
-> Move stock warranty -> defective -> repair/virtual workshop
-> Material Issue disposal from repair/virtual workshop
-> Verify final Bin and Stock Ledger Entry rows
-> Return safe allowlisted summary
Verified result:
Run ID: N8N-STOCK-E2E-EXC-1779149074522
Status: passed
Sales Invoice: ACC-SINV-2026-00026
Credit Note: ACC-SINV-2026-00027
Receipt Stock Entry: MAT-STE-2026-00062
Disposal Stock Entry: MAT-STE-2026-00065
Sellable final actual_qty: 3
Warranty final actual_qty: 0
Defective final actual_qty: 0
Repair final actual_qty: 0
Security findings: []
Verification Fields
Database verification for Stock workflows should record:
Bin.actual_qtyStock Ledger Entry.actual_qtyStock Ledger Entry.qtyaftertransactionStock Ledger Entry.serialandbatch_bundleSerial and Batch Entry.batch_noStock Entry.docstatusDelivery Note.docstatusSales Invoice.docstatusSales Invoice.update_stockPurchase Receipt.docstatusPurchase Invoice.docstatusWork Order.statusWork Order.produced_qtySecurity Baseline
Stock data includes item master data, warehouse balances, batch and serial traceability, delivery documents, manufacturing movement, inventory valuation, and cross-module document links. Treat every workflow as sensitive by default.
Recommended baseline:
Get Many with explicit Fields over Get when exposing webhook responses, because Get can return full documents including comments, owners, child tables, and operational metadata.Site Host Header.Security Notice
This package pins transitive form-data resolution with an npm overrides entry so npm audit --omit=dev reports no known vulnerabilities at release time. Keep this override in place until upstream dependencies resolve to a safe version without assistance.
In this package’s tested deployment model, security risk is also reduced by:
Do not treat this mitigation as a permanent substitute for dependency maintenance. Re-run npm audit --omit=dev before publishing a new package version and upgrade compatible n8n dependencies when the upstream dependency chain allows it without breaking n8n node compatibility.
Deployment Checklist For SME And Mid-Market Teams
Before going live:
v1 or v2.Site Host Header if ERPNext is served by a named Frappe site.Get Many for each required resource with limited fields.Suggested production approach:
Troubleshooting
Common checks:
401 or 403: verify API key, API secret, user roles, and DocType permissions in ERPNext.EPROTO or tlsv1 alert internal error: use the internal ERPNext HTTP URL from n8n when the public domain is protected by a reverse proxy or VPN layer.[] response: the node is working, but filters may not match any records.Site Host Header to the public ERPNext site name./webhook/ URL, not /webhook-test/.Get to Get Many and set an explicit Fields list.fgcompletedqty.Development
npm install
npm run build
npm run lint
npm audit --omit=dev
npx @n8n/node-cli lint
npx @n8n/node-cli build
npm pack --dry-run
For local n8n testing, link this package into your n8n custom nodes directory or install it from a packed tarball.
Expected runtime dependency policy:
n8n-workflow stays in devDependencies for local TypeScript/lint/build tooling.n8n-workflow is declared in peerDependencies so the host n8n instance provides it at runtime.form-data is pinned through overrides to avoid vulnerable transitive versions.Useful n8n references:
Scope And Roadmap
This package is intentionally Stock-focused. Other ERPNext modules should live in separate packages so each module can evolve independently:
n8n-nodes-erpnext-hrmsn8n-nodes-erpnext-accountingn8n-nodes-erpnext-buyingn8n-nodes-erpnext-sellingRecommended positioning:
ERPNext operational inventory workflow validation focused on Retail, Distribution, FMCG/Fresh basics, and Manufacturing basics.
Recommended next hardening tasks before wider public adoption:
TESTING.md, WORKFLOWS.md, and focused docs under docs/.Official References
Frappe / ERPNext:
n8n:
License
MIT
Acknowledgement
Part of the n8n2erpnext ecosystem for connecting n8n automation with ERPNext/Frappe business operations.