From d20846ef809773002f9b7029400c6ef766858f60 Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Mon, 25 Nov 2024 10:44:25 +0530 Subject: [PATCH] fix: initially closing amt should be equal to expected amt --- .../pos_closing_entry/pos_closing_entry.js | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js index a12a10bc3a..e8b20c7e08 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js @@ -158,6 +158,31 @@ frappe.ui.form.on("POS Closing Entry", { ]); frappe.dom.unfreeze(); } + + await Promise.all([ + frappe.call({ + method: "erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices", + args: { + start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date), + end: frappe.datetime.get_datetime_as_string(frm.doc.period_end_date), + pos_profile: frm.doc.pos_profile, + user: frm.doc.user, + }, + callback: (r) => { + let pos_invoices = r.message; + for (let doc of pos_invoices) { + frm.doc.grand_total += flt(doc.grand_total); + frm.doc.net_total += flt(doc.net_total); + frm.doc.total_quantity += flt(doc.total_qty); + refresh_payments(doc, frm, false); + refresh_taxes(doc, frm); + refresh_fields(frm); + set_html_data(frm); + } + }, + }), + ]); + frappe.dom.unfreeze(); }, }); @@ -174,7 +199,7 @@ function set_form_data(data, frm) { frm.doc.grand_total += flt(d.grand_total); frm.doc.net_total += flt(d.net_total); frm.doc.total_quantity += flt(d.total_qty); - refresh_payments(d, frm); + refresh_payments(d, frm, true); refresh_taxes(d, frm); }); set_closing_amount(frm); @@ -189,7 +214,7 @@ function add_to_pos_transaction(d, frm) { }); } -function refresh_payments(d, frm) { +function refresh_payments(d, frm, is_new) { d.payments.forEach((p) => { const payment = frm.doc.payment_reconciliation.find( (pay) => pay.mode_of_payment === p.mode_of_payment @@ -199,6 +224,7 @@ function refresh_payments(d, frm) { } if (payment) { payment.expected_amount += flt(p.amount); + if (is_new) payment.closing_amount = payment.expected_amount; payment.difference = payment.closing_amount - payment.expected_amount; } else { frm.add_child("payment_reconciliation", { -- GitLab