From 7a45c8bc28b286e73c349d82a268758b2c0f75f5 Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 19 Jun 2020 12:37:50 +0530 Subject: [PATCH 1/4] fix: replaced "row_id" to "idx" as "row_id" was not available in variable "tax", also replaced "-1" by "-2" as "idx" starts with 0 rather than 1 --- erpnext/public/js/controllers/taxes_and_totals.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index dbe48ec6544..a6eb901fa72 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -345,11 +345,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.row_id) - 1].tax_amount_for_current_item; + this.frm.doc["taxes"][cint(tax.idx) - 2].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.row_id) - 1].grand_total_for_current_item; + this.frm.doc["taxes"][cint(tax.idx) - 2].grand_total_for_current_item; } this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount); From 6f7652f425e2e58f7059d43c9bf7373af67cac3a Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 19 Jun 2020 14:36:56 +0530 Subject: [PATCH 2/4] fix: set row_id by default as previous row for On Previous Row Amount and On Previous Row Total --- erpnext/public/js/controllers/taxes_and_totals.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index a6eb901fa72..6b8dc2804f3 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -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); From 0fe14ce94e1cace40c0a7186ad6a6a837d89143c Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 19 Jun 2020 15:10:15 +0530 Subject: [PATCH 3/4] style: formate according to Codacy/PR Quality Review --- erpnext/public/js/controllers/taxes_and_totals.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 6b8dc2804f3..a449bdcca67 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -337,9 +337,9 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ // 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.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; From aca2ca59828932a33ee1e4f029b28564f44cf648 Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 19 Jun 2020 16:22:41 +0530 Subject: [PATCH 4/4] style: formate according to Codacy/PR Quality Review --- erpnext/public/js/controllers/taxes_and_totals.js | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index a449bdcca67..b72ceb21139 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -345,7 +345,6 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ 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));