Skip to content

Commit

Permalink
Merge pull request #7 from navariltd/mpesa_dialog_form
Browse files Browse the repository at this point in the history
fix: rename Mpesa Payments to Mpesa Payment Reconciliation
  • Loading branch information
emmanuel-mwendwa authored Oct 31, 2024
2 parents f106b44 + 7bbf7a9 commit f40516c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def submit_instant_mpesa_payment():
def process_mpesa_payment(mpesa_payment, customer, submit_payment=False):
try:
doc = frappe.get_doc("Mpesa C2B Payment Register", mpesa_payment)
print(f"Mpesa Payment: {doc}")
doc.customer = customer
# doc.mode_of_payment = mode_of_payment
#TODO: after testing, mode of payment
Expand Down
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
@@ -1,7 +1,7 @@
// Copyright (c) 2024, Navari Limited and contributors
// For license information, please see license.txt

frappe.ui.form.on("Mpesa Payments", {
frappe.ui.form.on("Mpesa Payment Reconciliation", {
onload(frm) {
const default_company = frappe.defaults.get_user_default("Company");
frm.set_value("company", default_company);
Expand All @@ -12,25 +12,27 @@ frappe.ui.form.on("Mpesa Payments", {

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 Payments", {
},

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 @@ -18,9 +18,9 @@
"column_break_asbv",
"invoice_name",
"full_name",
"sales_invoices_section",
"section_break_czej",
"invoices",
"section_break_lqip",
"section_break_abzl",
"mpesa_payments"
],
"fields": [
Expand Down Expand Up @@ -86,8 +86,22 @@
"label": "To Mpesa Payment Date"
},
{
"depends_on": "eval: doc.customer",
"fieldname": "sales_invoices_section",
"fieldname": "full_name",
"fieldtype": "Data",
"label": "Full Name"
},
{
"fieldname": "column_break_asbv",
"fieldtype": "Column Break"
},
{
"fieldname": "invoice_name",
"fieldtype": "Link",
"label": "Invoice Name",
"options": "Sales Invoice"
},
{
"fieldname": "section_break_czej",
"fieldtype": "Section Break"
},
{
Expand All @@ -97,40 +111,24 @@
"options": "Mpesa Payments Invoices"
},
{
"depends_on": "eval: doc.customer",
"fieldname": "section_break_lqip",
"fieldname": "section_break_abzl",
"fieldtype": "Section Break"
},
{
"fieldname": "mpesa_payments",
"fieldtype": "Table",
"label": "Mpesa Payments",
"options": "Mpesa Draft Payments"
},
{
"fieldname": "full_name",
"fieldtype": "Data",
"label": "Full Name"
},
{
"fieldname": "column_break_asbv",
"fieldtype": "Column Break"
},
{
"fieldname": "invoice_name",
"fieldtype": "Link",
"label": "Invoice Name",
"options": "Sales Invoice"
}
],
"index_web_pages_for_search": 1,
"is_virtual": 1,
"issingle": 1,
"links": [],
"modified": "2024-10-30 07:46:40.558666",
"modified": "2024-10-31 12:04:36.731193",
"modified_by": "Administrator",
"module": "Frappe Mpsa Payments",
"name": "Mpesa Payments",
"name": "Mpesa Payment Reconciliation",
"owner": "Administrator",
"permissions": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from frappe.model.document import Document


class MpesaPayments(Document):
class MpesaPaymentReconciliation(Document):

_table_fieldnames = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from frappe.tests.utils import FrappeTestCase


class TestMpesaPayments(FrappeTestCase):
class TestMpesaPaymentReconciliation(FrappeTestCase):
pass
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 f40516c

Please sign in to comment.