REST API Create DN against Sales Invoice

Hello all,

I’m working on integrating my webshop into erpnext via REST API. I’ve got no issues with creating customers and sales invoices, however when I try to create a DN against a Sales Invoice it just creates a new Sale Invoice. How do I create a DN against SI, what fields do I need to submit with ref to the SI? I can’t seem to figure it out.

Thanks in advance!

@N85 what have you tried so far?

check this:

https://frappe.github.io/erpnext/current/models/accounts/sales_invoice.html#erpnext.accounts.doctype.sales_invoice.sales_invoice.make_delivery_note

Hi @rmehta, thanks for the reply. How to use the RPC functionality, I’m working with curl in PHP? I presume that I somehow will need pass the value of of the Sales Invoice to create the correct reference in the DN?

Till now I’ve been trying to use POST to ‘http://frappe.local:8000/api/resource/Delivery Note’. I’ll double check what I’ve done in the meanwhile.

@rmehta, the REST API call is now working fine. I was passing the wrong document type, must’ve been tired… :hushed:

Still very much interested in learing how to use the RPC. Thanks!

@rmehta when posting to the Journal Entry endpoint with reference to Sales Invoice the values reset to 0.0. Using the below as part of the data. Any suggestions why it is resetting to 0.0? I obscured some data - so proper cost centers, accounts etc are used.

"title" => "wc_order_575dcb45bb8d5"
    "naming_series" => "JV-"
    "voucher_type" => "Bank Entry"
    "doctype" => "Journal Entry"
    "accounts" => array:2 [
      0 => array:10 [
        "cost_center" => "costcenter"
        "party_type" => "Customer"
        "party" => "CUST-00001"
        "reference_type" => "Sales Invoice"
        "reference_name" => "SINV-00017"
        "debit" => 0.0
        "credit" => 125.0
        "against_account" => "Bank"
        "is_advance" => "No"
        "account" => "Debtors"
      ]
      1 => array:7 [
        "cost_center" => "costcenter"
        "debit" => 125.0
        "credit" => 0.0
        "against_account" => "CUST-00001"
        "account" => "Bank"
        "is_advance" => "No"
        "docstatus" => 1
      ]
    ]
    "total_credit" => 125.0
    "total_debit" => 125.0
    "cheque_no" => "tr_w5vHkJcmcN"
    "cheque_date" => "12-06-2016"
    "docstatus" => 1
    "company" => "Company"
    "remark" => "Reference #tr_w5vHkJcmcN dated 12-06-2016 € 125 against Sales Invoice SINV-00017."
    "write_off_based_on" => "Accounts Receivable"
    "is_opening" => "No"
    "posting_date" => "12-06-2016"

@N85 can’t think of a reason. Try adding “print” statements in the controller to debug.

Hi @rmehta used same input as mentioned above. Added

webnotes.errprint(["gl entries: ", gl_entries])

to

    def on_submit(self):
            self.check_credit_limit()
            webnotes.errprint(["gl entries: ", gl_entries])
            self.make_gl_entries()
            self.update_advance_paid()
            self.update_expense_claim()

in /home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py

retruned:
{ "data": { "write_off_amount": 0, "naming_series": "JV-", "cheque_date": "12-06-2016", "voucher_type": "Bank Entry", "doctype": "Journal Entry", "owner": "email@email.com", "letter_head": null, "accounts": [ { "creation": "2016-06-14 09:13:21.201316", "doctype": "Journal Entry Account", "exchange_rate": 1.0, "owner": "email@email.com", "cost_center": "costcenter", "modified_by": "email@email.com", "party_type": "Customer", "reference_type": "Sales Invoice", "debit": 0.0, "party": "CUST-00001", "against_account": "Bank", "account_type": "Receivable", "parent": "JV-00014", "reference_name": "SINV-00017", "debit_in_account_currency": 0.0, "party_balance": 0.0, "is_advance": "No", "docstatus": 1, "account_currency": "EUR", "account": "Debtors", "name": "6158168833", "idx": 1, "modified": "2016-06-14 09:13:21.201316", "credit": 0.0, "parenttype": "Journal Entry", "balance": 0, "credit_in_account_currency": 0.0, "parentfield": "accounts" }, { "creation": "2016-06-14 09:13:21.201316", "doctype": "Journal Entry Account", "exchange_rate": 1.0, "owner": "email@email.com", "cost_center": "costcenter", "modified_by": "email@email.com", "party_type": null, "reference_type": null, "debit": 0.0, "party": null, "against_account": "CUST-00001", "account_type": "Bank", "parent": "JV-00014", "reference_name": null, "debit_in_account_currency": 0.0, "party_balance": 0, "is_advance": "No", "docstatus": 1, "account_currency": "EUR", "account": "Bank", "name": "191e28a1ee", "idx": 2, "modified": "2016-06-14 09:13:21.201316", "credit": 0.0, "parenttype": "Journal Entry", "balance": 0, "credit_in_account_currency": 0.0, "parentfield": "accounts" } ], "cheque_no": "tr_w5vHkJcmcN", "bill_no": null, "user_remark": null, "modified_by": "email@email.com", "title": "wc_order_575dcb45bb8d5", "amended_from": null, "docstatus": 1, "total_amount_in_words": "", "bill_date": null, "due_date": null, "creation": "2016-06-14 09:13:21.201316", "parent": null, "multi_currency": 0, "company": "Company", "total_credit": 0.0, "clearance_date": null, "difference": 0.0, "pay_to_recd_from": "Name", "total_amount": 0.0, "remark": "Reference #tr_w5vHkJcmcN dated 06-12-2016", "name": "JV-00014", "idx": 0, "modified": "2016-06-14 09:13:21.201316", "write_off_based_on": "Accounts Receivable", "parenttype": null, "select_print_heading": null, "stock_entry": null, "total_debit": 0.0, "is_opening": "No", "posting_date": "12-06-2016", "parentfield": null } }

Hope to hear from you. N.

@rmehta Deliver Note creation was fine. With regards to the Journal Entry I figured out what the issue was I ran into FiscalYearErros at some stage. Field posting_date must me passed in as yy-mm-dd. Perhaps this could be updated somewhere in the documentation? I haven’t seen any input format requirements in the API docs.

So the RPC’s were quite easy after all, just add the params at the end of the URL.