Node library to use the frappe/erpnext api
Add the following line under dependencies in your package.json:
"erpnext-node": "sohzaz/erpnext-node"
Then run npm
npm install
In order to use this module, first import it in you application:
const ERPNext = require('erpnext-node');
Next, initialize the ERPNext object with the connection information for your Erpnext instance:
const erp = new ERPNext({
host: 'HOST', //e.g. 'http://localhost:8000'
user: 'USER',
password: 'PASSWORD'
erp.call('dotted.path.to.function', data)
.then(res => {//do something})
.catch(err => {//handle error})
The Call method accepts the frappe/erpnext method path and the necessary input data. It returns a Promise object.
Start by selecting the resource to use:
const resource = erp.resource('DOCTYPE')
the resource object exposes those methods:
-
find(params)
Returns an Array. params can contain any of these properties:
name type fields Array An array of field names to be included filters Array An array of sql conditions each following this format : [{doctype}, {field}, {operator}, {operand}]
page_length Number The number of results returned per page page_start Number The offset at which the first result of the page should be -
get(docname)
Returns a document as an Object
parameters :
name type docname String The name of the document to fetch -
create(data)
Persist a new document and returns it as an Object
parameters :
name type data Object -
update(docname, data)
Update a document
parameters :
name type docname String data Object -
delete(docname)
Delete a document
parameters:
name type docname String
- Create a Sales Invoice from a Sales Order
const salesOrderName = 'SO-test';
erp.call('erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice',
{source_name: salesOrderName})
.then(tmpInvoice => {
return erp.resource('Sales Invoice')
.create(tmpInvoice)
})
.then(invoice => {
console.log(invoice)
})
.catch(err => {throw err})
- Find all variants for a item template
erp.resource('Item')
.find({filters: [['variant_of', '=', 'item']]})
.then(res => {console.log(res)})
.catch(err => {throw err})
In case you never heard about the ISC license it is functionally equivalent to the MIT license.
See the LICENSE file for details.