fix: initially closing amt should be equal to expected amt

(cherry picked from commit af9524920b)
This commit is contained in:
Ninad1306
2024-11-25 10:44:25 +05:30
committed by Mergify
parent 5e7cfeb514
commit 3f577779be

View File

@@ -147,7 +147,7 @@ frappe.ui.form.on("POS Closing Entry", {
frm.doc.grand_total += flt(doc.grand_total); frm.doc.grand_total += flt(doc.grand_total);
frm.doc.net_total += flt(doc.net_total); frm.doc.net_total += flt(doc.net_total);
frm.doc.total_quantity += flt(doc.total_qty); frm.doc.total_quantity += flt(doc.total_qty);
refresh_payments(doc, frm); refresh_payments(doc, frm, false);
refresh_taxes(doc, frm); refresh_taxes(doc, frm);
refresh_fields(frm); refresh_fields(frm);
set_html_data(frm); set_html_data(frm);
@@ -172,7 +172,7 @@ function set_form_data(data, frm) {
frm.doc.grand_total += flt(d.grand_total); frm.doc.grand_total += flt(d.grand_total);
frm.doc.net_total += flt(d.net_total); frm.doc.net_total += flt(d.net_total);
frm.doc.total_quantity += flt(d.total_qty); frm.doc.total_quantity += flt(d.total_qty);
refresh_payments(d, frm); refresh_payments(d, frm, true);
refresh_taxes(d, frm); refresh_taxes(d, frm);
}); });
} }
@@ -186,7 +186,7 @@ function add_to_pos_transaction(d, frm) {
}); });
} }
function refresh_payments(d, frm) { function refresh_payments(d, frm, is_new) {
d.payments.forEach((p) => { d.payments.forEach((p) => {
const payment = frm.doc.payment_reconciliation.find( const payment = frm.doc.payment_reconciliation.find(
(pay) => pay.mode_of_payment === p.mode_of_payment (pay) => pay.mode_of_payment === p.mode_of_payment
@@ -196,9 +196,7 @@ function refresh_payments(d, frm) {
} }
if (payment) { if (payment) {
payment.expected_amount += flt(p.amount); payment.expected_amount += flt(p.amount);
if (payment.closing_amount === 0) { if (is_new) payment.closing_amount = payment.expected_amount;
payment.closing_amount = payment.expected_amount;
}
payment.difference = payment.closing_amount - payment.expected_amount; payment.difference = payment.closing_amount - payment.expected_amount;
} else { } else {
frm.add_child("payment_reconciliation", { frm.add_child("payment_reconciliation", {