diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 9033f659e7..928d9a02dc 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -967,3 +967,23 @@ def get_party_and_account_balance(company, date, paid_from=None, paid_to=None, p "paid_from_account_balance": get_balance_on(paid_from, date, cost_center=cost_center), "paid_to_account_balance": get_balance_on(paid_to, date=date, cost_center=cost_center) }) + +@frappe.whitelist() +def make_payment_order(source_name, target_doc=None): + def set_missing_values(source, target): + target.append('references', { + 'amount': source.base_paid_amount, + 'supplier': source.party, + 'payment_request': source_name, + 'mode_of_payment': source.mode_of_payment, + 'bank_account': source.bank_account, + 'account': source.account + }) + + doclist = get_mapped_doc("Payment Request", source_name, { + "Payment Request": { + "doctype": "Payment Order", + } + }, target_doc, set_missing_values) + + return doclist diff --git a/erpnext/accounts/doctype/payment_order/payment_order.js b/erpnext/accounts/doctype/payment_order/payment_order.js index 10e199580b..5b4f9fbd1a 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.js +++ b/erpnext/accounts/doctype/payment_order/payment_order.js @@ -7,6 +7,9 @@ frappe.ui.form.on('Payment Order', { frm.add_custom_button(__('Payment Request'), function() { frm.trigger("get_from_payment_request"); }, __("Get from")); + frm.add_custom_button(__('Payment Entry'), function() { + frm.trigger("get_from_payment_entry"); + }, __("Get from")); } // payment Entry @@ -18,6 +21,22 @@ frappe.ui.form.on('Payment Order', { } }, + get_from_payment_entry: function(frm) { + erpnext.utils.map_current_doc({ + method: "erpnext.accounts.doctype.payment_entry.payment_entry.make_payment_order", + source_doctype: "Payment Entry", + target: frm, + date_field: "posting_date", + setters: { + party: frm.doc.supplier || "" + }, + get_query_filters: { + bank: frm.doc.bank, + docstatus: 1, + } + }); + }, + get_from_payment_request: function(frm) { erpnext.utils.map_current_doc({ method: "erpnext.accounts.doctype.payment_request.payment_request.make_payment_order",