Hi, I have created a Server Script that automatically creates a Sales Invoice and a Payment Entry after a Sales order is submitted, but the problem is that my payment entry is not getting linked to my Sales Invoice, how could I connect them?
This is my code:
# Create a Payment Entry
payment_entry = frappe.get_doc({
"doctype": "Payment Entry",
"party_type": party_type,
"party": sales_invoice.customer,
"payment_type": "Receive",
"posting_date": frappe.utils.today(),
"reference_date": frappe.utils.today(),
"reference_no": reference_no,
"company": sales_invoice.company,
"paid_to": payment_account,
"paid_from": paid_from,
"paid_received": sales_invoice.grand_total,
"paid_amount": sales_invoice.grand_total,
"received_amount": sales_invoice.grand_total,
"total_amount": sales_invoice.grand_total,
"mode_of_payment": mode_of_payment,
"target_exchange_rate": "MXN"
})
# add reference to Sales Invoice
payment_entry.append("references", {
"reference_doctype": "Sales Invoice",
"reference_name": sales_invoice.name,
"total_amount": sales_invoice.grand_total
})
# Insert payment entry
payment_entry.insert()
# Save and Submit Payment Entry
payment_entry.save()
payment_entry.submit()
Thanks for your help!