fix: set row_id by default as previous row for On Previous Row Amount and On Previous Row Total

This commit is contained in:
Afshan 2020-06-19 14:36:56 +05:30
parent 7a45c8bc28
commit 6f7652f425

View File

@ -335,6 +335,17 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
var tax_rate = this._get_tax_rate(tax, item_tax_map);
var current_tax_amount = 0.0;
// To set row_id by default as previous row.
if(["On Previous Row Amount", "On Previous Row Total"].includes(tax.charge_type)) {
if (tax.idx == 1) {
frappe.throw(
__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"))
}
if (!tax.row_id) {
tax.row_id = tax.idx - 1;
}
}
if(tax.charge_type == "Actual") {
// distribute the tax amount proportionally to each item row
var actual = flt(tax.tax_amount, precision("tax_amount", tax));
@ -345,11 +356,11 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
current_tax_amount = (tax_rate / 100.0) * item.net_amount;
} else if(tax.charge_type == "On Previous Row Amount") {
current_tax_amount = (tax_rate / 100.0) *
this.frm.doc["taxes"][cint(tax.idx) - 2].tax_amount_for_current_item;
this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item;
} else if(tax.charge_type == "On Previous Row Total") {
current_tax_amount = (tax_rate / 100.0) *
this.frm.doc["taxes"][cint(tax.idx) - 2].grand_total_for_current_item;
this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
}
this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);