diff --git a/erpnext/accounts/doctype/payment_order/payment_order.js b/erpnext/accounts/doctype/payment_order/payment_order.js index e2d65423e8727a0c3c3de7d1fe0465c2d08c4f03..d64ba9a370bbea2f17a4e69bb4fbf6877944664e 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.js +++ b/erpnext/accounts/doctype/payment_order/payment_order.js @@ -11,6 +11,16 @@ frappe.ui.form.on('Payment Order', { } }); + frm.set_query("bank_account", "references", function(doc, cdt, cdn) { + const row = locals[cdt][cdn] + return { + filters: { + "party_type": "Supplier", + "party": row.supplier + } + } + }); + frm.set_df_property('references', 'cannot_add_rows', true); }, refresh: function(frm) { @@ -23,11 +33,15 @@ frappe.ui.form.on('Payment Order', { frm.trigger("get_from_payment_entry"); }, __("Get Payments from")); + frm.add_custom_button(__('Purchase Invoice'), function() { + frm.trigger("get_from_purchase_invoice"); + }, __("Get Payments from")); + frm.trigger('remove_button'); } // payment Entry - if (frm.doc.docstatus===1 && frm.doc.payment_order_type==='Payment Request') { + if (frm.doc.docstatus===1 && ["Payment Request", "Purchase Invoice"].includes(frm.doc.payment_order_type)) { frm.add_custom_button(__('Journal entries for one supplier'), function() { frm.trigger("make_payment_records"); }, __("Create")); @@ -123,6 +137,28 @@ frappe.ui.form.on('Payment Order', { }); }, + get_from_purchase_invoice: function(frm) { + frm.trigger("remove_row_if_empty"); + erpnext.utils.map_current_doc({ + method: "erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_payment_order", + source_doctype: "Purchase Invoice", + target: frm, + date_field: "due_date", + setters: { + supplier: frm.doc.supplier || "", + posting_date: null, + due_date: null, + company: frm.doc.company, + status: "Overdue", + outstanding_amount: null, + }, + get_query_filters: { + docstatus: 1, + outstanding_amount: (">", 0.0) + } + }); + }, + make_payment_records: function(frm){ var dialog = new frappe.ui.Dialog({ title: __("For Supplier"), diff --git a/erpnext/accounts/doctype/payment_order/payment_order.json b/erpnext/accounts/doctype/payment_order/payment_order.json index 88776bc5aec422d72a6d1709735f4a2623ab2825..a1f6768bd895d553aec96c225139482647782092 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.json +++ b/erpnext/accounts/doctype/payment_order/payment_order.json @@ -79,7 +79,7 @@ "fieldname": "payment_order_type", "fieldtype": "Select", "label": "Payment Order Type", - "options": "\nPayment Request\nPayment Entry", + "options": "\nPayment Request\nPayment Entry\nPurchase Invoice", "read_only": 1, "reqd": 1 }, @@ -115,7 +115,7 @@ "link_fieldname": "payment_order" } ], - "modified": "2023-11-27 17:19:23.959658", + "modified": "2024-04-11 16:51:34.723794", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Order", diff --git a/erpnext/accounts/doctype/payment_order/payment_order.py b/erpnext/accounts/doctype/payment_order/payment_order.py index ac1800977f364ba61a3791346e249a94c0afee51..6ff59dd358217a614a92438227f855b15100bfd4 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.py +++ b/erpnext/accounts/doctype/payment_order/payment_order.py @@ -31,7 +31,7 @@ class PaymentOrder(Document): company_bank_account: DF.Link naming_series: DF.Literal["PMO-"] party: DF.Link | None - payment_order_type: DF.Literal["", "Payment Request", "Payment Entry"] + payment_order_type: DF.Literal["", "Payment Request", "Payment Entry", "Purchase Invoice"] posting_date: DF.Date | None references: DF.Table[PaymentOrderReference] # end: auto-generated types diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 7a4a73c98f76a022773805f6091a950648156e8d..8e7c3107fedab275024a50e740508f54efba8cc0 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -196,6 +196,7 @@ "is_internal_supplier", "represents_company", "supplier_group", + "payment_order_status", "column_break_147", "inter_company_invoice_reference", "is_old_subcontracting_flow", @@ -1661,12 +1662,12 @@ "options": "Supplier Group" }, { - "default": "0", - "depends_on": "eval:!doc.is_return", - "fieldname": "is_down_payment_invoice", - "fieldtype": "Check", - "label": "Is Down Payment Invoice" - }, + "default": "0", + "depends_on": "eval:!doc.is_return", + "fieldname": "is_down_payment_invoice", + "fieldtype": "Check", + "label": "Is Down Payment Invoice" + }, { "default": "1", "depends_on": "eval: doc.is_return && doc.return_against", @@ -1674,6 +1675,13 @@ "fieldname": "update_outstanding_for_self", "fieldtype": "Check", "label": "Update Outstanding for Self" + }, + { + "fieldname": "payment_order_status", + "fieldtype": "Select", + "label": "Payment Order Status", + "options": "Initiated\nPayment Ordered", + "read_only": 1 } ], "icon": "uil uil-file-alt", @@ -1681,13 +1689,13 @@ "is_sealed": 1, "is_submittable": 1, "links": [ - { - "group": "Payment Request", - "link_doctype": "Payment Request", - "link_fieldname": "reference_name" - } + { + "group": "Payment Request", + "link_doctype": "Payment Request", + "link_fieldname": "reference_name" + } ], - "modified": "2024-03-22 16:15:09.099187", + "modified": "2024-04-11 17:13:37.934789", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index f86545d89bf3046e4de25ce2ddee86e230e23cfe..a9e64a96b402573dd620f073248d90cedd42b6ca 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -153,6 +153,7 @@ class PurchaseInvoice(BuyingController): outstanding_amount: DF.Currency paid_amount: DF.Currency party_account_currency: DF.Link | None + payment_order_status: DF.Literal["Initiated", "Payment Ordered"] payment_schedule: DF.Table[PaymentSchedule] payment_terms_template: DF.Link | None per_received: DF.Percent @@ -216,6 +217,7 @@ class PurchaseInvoice(BuyingController): total_qty: DF.Float total_taxes_and_charges: DF.Currency unrealized_profit_loss_account: DF.Link | None + unreconciled_amount: DF.Currency update_billed_amount_in_purchase_order: DF.Check update_billed_amount_in_purchase_receipt: DF.Check update_outstanding_for_self: DF.Check @@ -1999,3 +2001,36 @@ def make_purchase_receipt(source_name, target_doc=None): ) return doc + + +@frappe.whitelist() +def make_payment_order(source_name, target_doc=None): + from frappe.model.mapper import get_mapped_doc + + def set_missing_values(source, target): + target.payment_order_type = "Purchase Invoice" + bank_account = frappe.db.get_value("Supplier", source.supplier, "default_bank_account") + target.append( + "references", + { + "reference_doctype": source.doctype, + "reference_name": source.name, + "amount": source.outstanding_amount, + "supplier": source.supplier, + "bank_account": bank_account, + }, + ) + + doclist = get_mapped_doc( + "Purchase Invoice", + source_name, + { + "Purchase Invoice": { + "doctype": "Payment Order", + } + }, + target_doc, + set_missing_values, + ) + + return doclist