使用 REST API 集成外部订单管理系统和销售周期的标准白名单方法与流程
1. 销售订单
Frappe 框架为所有 DocType 原生生成 REST API。此方法可用于创建销售周期的第一个文档。如果您从销售订单开始,可以使用标准的 REST API POST 请求来生成订单。示例如下,您可以根据需要在请求体中包含自定义字段和其他文档类型详情。
POST /api/resource/Sales Order
# Body
{
"doctype": "Sales Order",
"customer": "Test Customer",
"company_address": "Test - Billing",
"customer_address": "Test-Billing-3",
"items": [{
"item_code": "Mobile Display",
"qty": 10,
"rate": 2000,
"delivery_date": "2022-11-06",
"delivery_warehouse": "Stores - GTPL"
}]
}
2. 交货单
如果您从交货单开始,请使用与上述销售订单相同的方法,只需将文档类型键值替换为 交货单 而不是 销售订单。如果您想从销售订单创建交货单,请使用以下端点。这里的 source_name 参数是销售订单 ID。
POST /api/method/erpnext.selling.doctype.sales_order.sales_order.make_delivery_note
# Body
{"source_name": "SO-2022-00001"}
该端点返回一个交货单 JSON 对象作为响应,其中包含订单中所有待交付的项目。
3. 销售发票
同样,如果您只是创建销售发票,最佳方法是使用标准 REST API。请参考销售订单部分提到的示例。
要从销售订单创建销售发票,请使用以下端点。这里的 source_name 参数是销售订单 ID。
POST /api/method/erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice
# Body
{"source_name": "SO-2022-00001"}
要从交货单创建销售发票,请使用以下端点。这里的 source_name 参数是交货单 ID。
POST /api/method/erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice
# Body
{"source_name": "SO-2022-00001"}
这两个端点都返回一个销售发票 JSON 对象,其中包含所有待开票的项目。
4. 针对订单或发票的付款
要针对销售订单或发票生成付款分录,请使用以下端点
POST /api/method/erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry
# Body
{
"dt": "Sales Invoice",
"dn": "SI-2022-0001",
"party_amount": 2000, # Pass if the document doesn't have an `outstanding_amount` field (optional parameter)
"bank_account": "Bank Name - CAB", # Pass is case want to use other than the default one (optional parameter)
"bank_amount": 2000, # Paid or received amount depending on the type of payment entry (optional parameter)
"party_type": "Customer", # If payment entry is against party type other than Customer or Supplier (optional parameter)
"payment_type": "Pay", # Pay or receive (optional parameter)
}