Skip to content

Commit

Permalink
fix: remove custom Allocate button after processing payment
Browse files Browse the repository at this point in the history
Make the child table fields read-only
  • Loading branch information
emmanuel-mwendwa committed Oct 31, 2024
1 parent 277cc73 commit 7bbf7a9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,35 @@
"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",
"fieldtype": "Data",
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Full Name"
"label": "Full Name",
"read_only": 1
},
{
"fieldname": "date",
"fieldtype": "Date",
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Date"
"label": "Date",
"read_only": 1
},
{
"fieldname": "amount",
"fieldtype": "Currency",
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Amount"
"label": "Amount",
"read_only": 1
},
{
"fieldname": "column_break_fnjs",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
});
},

Expand Down Expand Up @@ -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) {
Expand All @@ -176,4 +165,7 @@ function check_for_process_payments_button(frm) {

process_btn.addClass("btn-primary");
}
else {
frm.remove_custom_button("Allocate");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
"in_preview": 1,
"in_standard_filter": 1,
"label": "Invoice",
"options": "Sales Invoice"
"options": "Sales Invoice",
"read_only": 1
},
{
"fieldname": "date",
"fieldtype": "Date",
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Date"
"label": "Date",
"read_only": 1
},
{
"fieldname": "column_break_uznl",
Expand All @@ -40,22 +42,24 @@
"in_list_view": 1,
"in_preview": 1,
"in_standard_filter": 1,
"label": "Total"
"label": "Total",
"read_only": 1
},
{
"fieldname": "outstanding_amount",
"fieldtype": "Currency",
"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",
Expand Down

0 comments on commit 7bbf7a9

Please sign in to comment.