feat: show PE count, grand total and draft note in payment dialog

This commit is contained in:
Shllokkk
2026-08-01 19:16:24 +05:30
parent 7fdb768259
commit bb5b71643b
2 changed files with 40 additions and 5 deletions

View File

@@ -51,7 +51,13 @@ def get_payable_invoices(invoices: str | list | None = None):
names = [d["voucher_no"] for d in frappe.parse_json(invoices or "[]") if d.get("voucher_no")]
payable, excluded = _partition_payable_invoices(names)
return {"payable": payable, "excluded": excluded}
currency = None
if payable:
company = frappe.get_cached_value("Purchase Invoice", payable[0]["voucher_no"], "company")
currency = frappe.get_cached_value("Company", company, "default_currency")
return {"payable": payable, "excluded": excluded, "currency": currency}
def _partition_payable_invoices(names):
@@ -63,7 +69,7 @@ def _partition_payable_invoices(names):
if not names:
return [], []
rows = frappe.get_all(
rows = frappe.get_list(
"Purchase Invoice",
filters={"name": ["in", names], "docstatus": 1},
fields=[
@@ -75,6 +81,7 @@ def _partition_payable_invoices(names):
"is_return",
"is_internal_supplier",
],
limit_page_length=0,
)
payable, excluded = [], []
@@ -95,6 +102,12 @@ def _partition_payable_invoices(names):
}
)
# names not returned were cancelled/deleted or no longer readable after the report loaded
found = {r.name for r in rows}
for name in names:
if name not in found:
excluded.append({"voucher_no": name, "reason": _("Not available")})
return payable, excluded

View File

@@ -239,17 +239,17 @@ function create_payment_entries_from_payable_report(report) {
method: "erpnext.accounts.bulk_payment.get_payable_invoices",
args: { invoices: rows.map((r) => ({ voucher_no: r.voucher_no })) },
callback: ({ message }) => {
const { payable = [], excluded = [] } = message || {};
const { payable = [], excluded = [], currency } = message || {};
if (!payable.length) {
frappe.msgprint(__("None of the selected invoices are payable"));
return;
}
show_create_payment_entries_dialog(report, payable, excluded);
show_create_payment_entries_dialog(report, payable, excluded, currency);
},
});
}
function show_create_payment_entries_dialog(report, payable, excluded) {
function show_create_payment_entries_dialog(report, payable, excluded, currency) {
// group by (supplier, party_account) for the overview — matches the backend grouping key
const supplierMap = {};
for (const inv of payable) {
@@ -319,6 +319,14 @@ function show_create_payment_entries_dialog(report, payable, excluded) {
})),
});
const pe_count = Object.keys(supplierMap).length;
const grand_total = Object.values(supplierMap).reduce((sum, d) => sum + d.outstanding, 0);
fields.push({
fieldtype: "HTML",
fieldname: "summary_footer",
options: summary_footer_html(pe_count, grand_total, currency),
});
const dialog = new frappe.ui.Dialog({
title: __("Create Payment Entries"),
fields: fields,
@@ -348,6 +356,20 @@ function show_create_payment_entries_dialog(report, payable, excluded) {
dialog.show();
}
function summary_footer_html(pe_count, grand_total, currency) {
return `<div style="
display: flex;
justify-content: space-between;
align-items: center;
margin-top: var(--margin-sm);
font-size: var(--text-sm);
">
<span class="text-muted">${__("Payment Entries are created as drafts for your review")}</span>
<span>${__("{0} Payment Entries", [pe_count])} ·
<strong>${format_currency(grand_total, currency)}</strong></span>
</div>`;
}
function excluded_note_html(excluded) {
const counts = {};
for (const e of excluded) {