fix: to update Allocated amount after Paid Amount is changed

This commit is contained in:
Anuja P 2021-04-23 19:24:53 +05:30
parent c21ce42559
commit dc599e0164

View File

@ -582,7 +582,7 @@ frappe.ui.form.on('Payment Entry', {
} }
if(frm.doc.payment_type == "Receive") if(frm.doc.payment_type == "Receive")
frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount); frm.events.allocate_party_amount_against_ref_docs(frm, frm.doc.paid_amount, 1);
else else
frm.events.set_unallocated_amount(frm); frm.events.set_unallocated_amount(frm);
}, },
@ -606,9 +606,9 @@ frappe.ui.form.on('Payment Entry', {
{fieldtype:"Float", label: __("Less Than Amount"), fieldname:"outstanding_amt_less_than"}, {fieldtype:"Float", label: __("Less Than Amount"), fieldname:"outstanding_amt_less_than"},
{fieldtype:"Section Break"}, {fieldtype:"Section Break"},
{fieldtype:"Link", label:__("Cost Center"), fieldname:"cost_center", options:"Cost Center", {fieldtype:"Link", label:__("Cost Center"), fieldname:"cost_center", options:"Cost Center",
"get_query": function() { "get_query": function() {
return { return {
"filters": {"company": frm.doc.company} "filters": {"company": frm.doc.company}
} }
} }
}, },
@ -743,7 +743,7 @@ frappe.ui.form.on('Payment Entry', {
}); });
}, },
allocate_party_amount_against_ref_docs: function(frm, paid_amount) { allocate_party_amount_against_ref_docs: function(frm, paid_amount, paid_amount_change) {
var total_positive_outstanding_including_order = 0; var total_positive_outstanding_including_order = 0;
var total_negative_outstanding = 0; var total_negative_outstanding = 0;
var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [], var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [],
@ -800,22 +800,18 @@ frappe.ui.form.on('Payment Entry', {
//If allocate payment amount checkbox is unchecked, set zero to allocate amount //If allocate payment amount checkbox is unchecked, set zero to allocate amount
row.allocated_amount = 0; row.allocated_amount = 0;
} else if (frappe.flags.allocate_payment_amount != 0 && !row.allocated_amount) { } else if (frappe.flags.allocate_payment_amount != 0 && (!row.allocated_amount || paid_amount_change)) {
if (row.outstanding_amount > 0 && allocated_positive_outstanding > 0) { if (row.outstanding_amount > 0 && allocated_positive_outstanding > 0) {
if (row.outstanding_amount >= allocated_positive_outstanding) { row.allocated_amount = (row.outstanding_amount >= allocated_positive_outstanding) ?
row.allocated_amount = allocated_positive_outstanding; allocated_positive_outstanding : row.outstanding_amount;
} else {
row.allocated_amount = row.outstanding_amount;
}
allocated_positive_outstanding -= flt(row.allocated_amount); allocated_positive_outstanding -= flt(row.allocated_amount);
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
if (Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) {
row.allocated_amount = -1*allocated_negative_outstanding;
} else {
row.allocated_amount = row.outstanding_amount;
};
} else if (row.outstanding_amount > 0 && allocated_positive_outstanding == 0) {
row.allocated_amount = null;
} else if (row.outstanding_amount < 0 && allocated_negative_outstanding) {
row.allocated_amount = (Math.abs(row.outstanding_amount) >= allocated_negative_outstanding) ?
-1*allocated_negative_outstanding : row.outstanding_amount;
allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount)); allocated_negative_outstanding -= Math.abs(flt(row.allocated_amount));
} }
} }