From 7bbf7a9e1f3ff85f4bc8e28021ce79e0caf8d147 Mon Sep 17 00:00:00 2001 From: emmanuel-mwendwa Date: Thu, 31 Oct 2024 14:23:54 +0300 Subject: [PATCH] fix: remove custom Allocate button after processing payment Make the child table fields read-only --- .../mpesa_draft_payments.json | 14 ++-- .../mpesa_payment_reconciliation.js | 84 +++++++++---------- .../mpesa_payment_reconciliation.json | 8 +- .../mpesa_payments_invoices.json | 14 ++-- 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_draft_payments/mpesa_draft_payments.json b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_draft_payments/mpesa_draft_payments.json index 77461b5..8138685 100644 --- a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_draft_payments/mpesa_draft_payments.json +++ b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_draft_payments/mpesa_draft_payments.json @@ -20,7 +20,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Payment ID", - "options": "Mpesa C2B Payment Register" + "options": "Mpesa C2B Payment Register", + "read_only": 1 }, { "fieldname": "full_name", @@ -28,7 +29,8 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Full Name" + "label": "Full Name", + "read_only": 1 }, { "fieldname": "date", @@ -36,7 +38,8 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Date" + "label": "Date", + "read_only": 1 }, { "fieldname": "amount", @@ -44,7 +47,8 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Amount" + "label": "Amount", + "read_only": 1 }, { "fieldname": "column_break_fnjs", @@ -55,7 +59,7 @@ "is_virtual": 1, "istable": 1, "links": [], - "modified": "2024-10-17 07:35:16.568396", + "modified": "2024-10-31 14:23:46.793043", "modified_by": "Administrator", "module": "Frappe Mpsa Payments", "name": "Mpesa Draft Payments", diff --git a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.js b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.js index 548ed64..79b2ca8 100644 --- a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.js +++ b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.js @@ -12,25 +12,27 @@ frappe.ui.form.on("Mpesa Payment Reconciliation", { frm.set_df_property("invoices", "cannot_add_rows", true); frm.set_df_property("mpesa_payments", "cannot_add_rows", true); - }, customer(frm) { - let fetch_btn = frm.add_custom_button(__("Get Unreconciled Entries"), () => { + let fetch_btn = frm.add_custom_button( + __("Get Unreconciled Entries"), + () => { frm.trigger("fetch_entries"); - }); + } + ); }, onload_post_render(frm) { - frm.set_query('invoice_name', function() { - return { - filters: { - docstatus: 1, - outstanding_amount: ['>', 0], - company: frm.doc.company, - customer: frm.doc.customer, - } - }; + frm.set_query("invoice_name", function () { + return { + filters: { + docstatus: 1, + outstanding_amount: [">", 0], + company: frm.doc.company, + customer: frm.doc.customer, + }, + }; }); }, @@ -119,53 +121,40 @@ frappe.ui.form.on("Mpesa Payment Reconciliation", { }, process_payments(frm, retryCount = 0) { - let unpaid_invoices = frm.doc.invoices || []; let mpesa_payments = frm.doc.mpesa_payments || []; if (unpaid_invoices.length === 0 || mpesa_payments.length === 0) { frappe.msgprint({ title: __("No Entries Found"), - message: __("Please add at least one invoice and one Mpesa payment for processing."), + message: __( + "Please add at least one invoice and one Mpesa payment for processing." + ), indicator: "orange", }); return; } - - let invoice_names = unpaid_invoices.map(invoice => invoice.invoice); - let mpesa_names = mpesa_payments.map(payment => payment.payment_id); + + let invoice_names = unpaid_invoices.map((invoice) => invoice.invoice); + let mpesa_names = mpesa_payments.map((payment) => payment.payment_id); frappe.call({ - method: "frappe_mpsa_payments.frappe_mpsa_payments.api.payment_entry.process_mpesa_c2b_reconciliation", - args: { - invoice_names: invoice_names, - mpesa_names: mpesa_names - }, - callback: function (response) { - if (response) { - frappe.msgprint({ - title: __("Success"), - message: __("Payment reconciliation successful."), - indicator: "green", - }); - - frm.clear_table("invoices"); - frm.clear_table("mpesa_payments"); - frm.refresh_field("invoices"); - frm.refresh_field("mpesa_payments"); - - check_for_process_payments_button(frm); - } else { - frappe.msgprint({ - title: __("Payment Processing Failed"), - message: __("Some payments could not be processed. Please try again."), - indicator: "red", - }); - } - } - }) - }, + method: + "frappe_mpsa_payments.frappe_mpsa_payments.api.payment_entry.process_mpesa_c2b_reconciliation", + args: { + invoice_names: invoice_names, + mpesa_names: mpesa_names, + }, + callback: function () { + frm.clear_table("invoices"); + frm.clear_table("mpesa_payments"); + frm.refresh_field("invoices"); + frm.refresh_field("mpesa_payments"); + check_for_process_payments_button(frm); + }, + }); + }, }); function check_for_process_payments_button(frm) { @@ -176,4 +165,7 @@ function check_for_process_payments_button(frm) { process_btn.addClass("btn-primary"); } + else { + frm.remove_custom_button("Allocate"); + } } diff --git a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.json b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.json index a368c23..440b9de 100644 --- a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.json +++ b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payment_reconciliation/mpesa_payment_reconciliation.json @@ -108,8 +108,7 @@ "fieldname": "invoices", "fieldtype": "Table", "label": "Invoices", - "options": "Mpesa Payments Invoices", - "read_only": 1 + "options": "Mpesa Payments Invoices" }, { "fieldname": "section_break_abzl", @@ -119,15 +118,14 @@ "fieldname": "mpesa_payments", "fieldtype": "Table", "label": "Mpesa Payments", - "options": "Mpesa Draft Payments", - "read_only": 1 + "options": "Mpesa Draft Payments" } ], "index_web_pages_for_search": 1, "is_virtual": 1, "issingle": 1, "links": [], - "modified": "2024-10-31 11:01:38.554837", + "modified": "2024-10-31 12:04:36.731193", "modified_by": "Administrator", "module": "Frappe Mpsa Payments", "name": "Mpesa Payment Reconciliation", diff --git a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payments_invoices/mpesa_payments_invoices.json b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payments_invoices/mpesa_payments_invoices.json index 3e1428b..bfe6a39 100644 --- a/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payments_invoices/mpesa_payments_invoices.json +++ b/frappe_mpsa_payments/frappe_mpsa_payments/doctype/mpesa_payments_invoices/mpesa_payments_invoices.json @@ -20,7 +20,8 @@ "in_preview": 1, "in_standard_filter": 1, "label": "Invoice", - "options": "Sales Invoice" + "options": "Sales Invoice", + "read_only": 1 }, { "fieldname": "date", @@ -28,7 +29,8 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Date" + "label": "Date", + "read_only": 1 }, { "fieldname": "column_break_uznl", @@ -40,7 +42,8 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Total" + "label": "Total", + "read_only": 1 }, { "fieldname": "outstanding_amount", @@ -48,14 +51,15 @@ "in_list_view": 1, "in_preview": 1, "in_standard_filter": 1, - "label": "Outstanding Amount" + "label": "Outstanding Amount", + "read_only": 1 } ], "index_web_pages_for_search": 1, "is_virtual": 1, "istable": 1, "links": [], - "modified": "2024-10-22 08:37:00.706403", + "modified": "2024-10-31 14:23:20.897922", "modified_by": "Administrator", "module": "Frappe Mpsa Payments", "name": "Mpesa Payments Invoices",