Programatically Insert Payment Entries

Hello Community.

I am trying to programatically Register New Payment Entries in ERPNext, and my target is to register them and as well attach the references to Sales Invoices against which they are paid.
Below is my implementation.

payment_entry = frappe.new_doc("Payment Entry")
      payment_entry.naming_series = "ACC-PAY-.YYYY.-"
      payment_entry.payment_type = "Receive"
      payment_entry.mode_of_payment = "Cash"
      payment_entry.party_type = "Customer" = transaction["customer"]
      payment_entry.paid_amount = int(transaction["amount"])
      payment_entry.transaction_id = transaction["reference_id"]
      payment_entry.source_exchange_rate = 0.07
      payment_entry.target_exchange_rate = 0.07
      payment_entry.paid_to_account_currency = "UGX"
      payment_entry.received_amount = transaction["amount"]
      payment_entry.paid_to = "Cash - CA"
      payment_entry.append("references", {
        "reference_doctype": "Sales Invoice",
        "reference_name": transaction["invoice"],

I have a variable transaction which has a value of Sales Invoice, Payment Entry is created but it does not include the References. Is there something wrong with my implementation or Is there a correct way to achieve this?

Thank you!

Hi, did you find a solution for this? I’m facing the same issue :confused:

Hi, maybe this help

‘reference_doctype’: ‘Sales Order’,
‘due_date’: so_doc.delivery_date,
‘allocated_amount’: flt(paid_amount)

1 Like

That Worked for me, I was missing “allocated_amount” Thank you so much! I can’t mark this as solved because this is not my topic, but I will reference your answer on my topic.