Merge pull request #6002 from nabinhait/pe_fix_101

Payment Entry fix: Unallocated amount in payment entry considering deductions
This commit is contained in:
Nabin Hait 2016-08-05 15:44:44 +05:30 committed by GitHub
commit c49a3425ef
2 changed files with 19 additions and 6 deletions

View File

@ -95,13 +95,13 @@ frappe.ui.form.on('Payment Entry', {
frm.doc.paid_to_account_currency != company_currency && frm.doc.paid_to_account_currency != company_currency &&
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)); frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency); frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency);
frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency && frm.toggle_display("base_received_amount", (frm.doc.paid_to_account_currency != company_currency &&
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)); frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency));
frm.toggle_display("received_amount", frm.toggle_display("received_amount", (frm.doc.payment_type=="Internal Transfer" ||
frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency) frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency))
frm.toggle_display(["base_total_allocated_amount"], frm.toggle_display(["base_total_allocated_amount"],
(frm.doc.paid_amount && frm.doc.received_amount && frm.doc.base_total_allocated_amount && (frm.doc.paid_amount && frm.doc.received_amount && frm.doc.base_total_allocated_amount &&
@ -601,9 +601,17 @@ frappe.ui.form.on('Payment Entry', {
if(frm.doc.party) { if(frm.doc.party) {
var party_amount = frm.doc.payment_type=="Receive" ? var party_amount = frm.doc.payment_type=="Receive" ?
frm.doc.paid_amount : frm.doc.received_amount; frm.doc.paid_amount : frm.doc.received_amount;
var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [],
function(d) { return flt(d.amount) }));
if(frm.doc.total_allocated_amount < party_amount) if(frm.doc.total_allocated_amount < party_amount) {
unallocated_amount = party_amount - frm.doc.total_allocated_amount; if(frm.doc.payment_type == "Receive") {
unallocated_amount = party_amount - (frm.doc.total_allocated_amount - total_deductions);
} else {
unallocated_amount = party_amount - (frm.doc.total_allocated_amount + total_deductions);
}
}
} }
frm.set_value("unallocated_amount", unallocated_amount); frm.set_value("unallocated_amount", unallocated_amount);

View File

@ -247,8 +247,13 @@ class PaymentEntry(AccountsController):
if self.party: if self.party:
party_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount party_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount
total_deductions = sum([flt(d.amount) for d in self.get("deductions")])
if self.total_allocated_amount < party_amount: if self.total_allocated_amount < party_amount:
self.unallocated_amount = party_amount - self.total_allocated_amount if self.payment_type == "Receive":
self.unallocated_amount = party_amount - (self.total_allocated_amount - total_deductions)
else:
self.unallocated_amount = party_amount - (self.total_allocated_amount + total_deductions)
def set_difference_amount(self): def set_difference_amount(self):
base_unallocated_amount = flt(self.unallocated_amount) * (flt(self.source_exchange_rate) base_unallocated_amount = flt(self.unallocated_amount) * (flt(self.source_exchange_rate)