Merge pull request #4316 from nabinhait/advance_fix

[fix] Invoice Outstanding calculation related to advance
This commit is contained in:
Nabin Hait 2015-11-16 15:50:32 +05:30
commit adc93b797a
2 changed files with 24 additions and 22 deletions

View File

@ -398,17 +398,18 @@ class calculate_taxes_and_totals(object):
return
self.doc.round_floats_in(self.doc, ["grand_total", "total_advance", "write_off_amount"])
total_amount_to_pay = flt(self.doc.grand_total - self.doc.total_advance - self.doc.write_off_amount,
self.doc.precision("grand_total"))
if self.doc.party_account_currency == self.doc.currency:
total_amount_to_pay = flt(self.doc.grand_total - self.doc.total_advance
- flt(self.doc.write_off_amount), self.doc.precision("grand_total"))
else:
total_amount_to_pay = flt(self.doc.base_grand_total - self.doc.total_advance
- flt(self.doc.base_write_off_amount), self.doc.precision("grand_total"))
if self.doc.doctype == "Sales Invoice":
self.doc.round_floats_in(self.doc, ["paid_amount"])
outstanding_amount = flt(total_amount_to_pay - self.doc.paid_amount, self.doc.precision("outstanding_amount"))
paid_amount = self.doc.paid_amount \
if self.doc.party_account_currency == self.doc.currency else self.doc.base_paid_amount
self.doc.outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
self.doc.precision("outstanding_amount"))
elif self.doc.doctype == "Purchase Invoice":
outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount"))
if self.doc.party_account_currency == self.doc.currency:
self.doc.outstanding_amount = outstanding_amount
else:
self.doc.outstanding_amount = flt(outstanding_amount * self.doc.conversion_rate,
self.doc.precision("outstanding_amount"))
self.doc.outstanding_amount = flt(total_amount_to_pay, self.doc.precision("outstanding_amount"))

View File

@ -500,9 +500,13 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
if(this.frm.doc.is_return || this.frm.doc.docstatus > 0) return;
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "total_advance", "write_off_amount"]);
var total_amount_to_pay = flt((this.frm.doc.grand_total - this.frm.doc.total_advance
- this.frm.doc.write_off_amount), precision("grand_total"));
if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
var total_amount_to_pay = flt((this.frm.doc.grand_total - this.frm.doc.total_advance
- this.frm.doc.write_off_amount), precision("grand_total"));
else {
var total_amount_to_pay = flt((this.frm.doc.base_grand_total - this.frm.doc.total_advance
- this.frm.doc.base_write_off_amount), precision("base_grand_total"));
}
if(this.frm.doc.doctype == "Sales Invoice") {
frappe.model.round_floats_in(this.frm.doc, ["paid_amount"]);
@ -518,18 +522,15 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
this.frm.refresh_field("paid_amount");
this.frm.refresh_field("base_paid_amount");
var outstanding_amount = flt(total_amount_to_pay - this.frm.doc.paid_amount,
var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ?
this.frm.doc.paid_amount : this.frm.doc.base_paid_amount;
var outstanding_amount = flt(total_amount_to_pay - flt(paid_amount),
precision("outstanding_amount"));
} else if(this.frm.doc.doctype == "Purchase Invoice") {
var outstanding_amount = flt(total_amount_to_pay, precision("outstanding_amount"));
}
if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
this.frm.set_value("outstanding_amount", outstanding_amount);
} else {
this.frm.set_value("outstanding_amount",
flt(outstanding_amount * this.frm.doc.conversion_rate, precision("outstanding_amount")));
}
}
this.frm.set_value("outstanding_amount", outstanding_amount);
}
})