diff --git a/round_tax_amount_row_wise/__init__.py b/round_tax_amount_row_wise/__init__.py index bbab024..1276d02 100644 --- a/round_tax_amount_row_wise/__init__.py +++ b/round_tax_amount_row_wise/__init__.py @@ -1 +1 @@ -__version__ = "0.1.4" +__version__ = "0.1.5" diff --git a/round_tax_amount_row_wise/public/js/taxes_and_totals_override.js b/round_tax_amount_row_wise/public/js/taxes_and_totals_override.js index a59ff6a..eb07d34 100644 --- a/round_tax_amount_row_wise/public/js/taxes_and_totals_override.js +++ b/round_tax_amount_row_wise/public/js/taxes_and_totals_override.js @@ -5,7 +5,7 @@ if (erpnext.taxes_and_totals) { erpnext.taxes_and_totals.prototype.get_current_tax_amount = function (item, tax, item_tax_map) { var tax_rate = this._get_tax_rate(tax, item_tax_map); var current_tax_amount = 0.0; - + var current_net_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) { @@ -17,12 +17,16 @@ if (erpnext.taxes_and_totals) { } } if(tax.charge_type == "Actual") { + current_net_amount = item.net_amount // distribute the tax amount proportionally to each item row var actual = flt(tax.tax_amount, precision("tax_amount", tax)); current_tax_amount = this.frm.doc.net_total ? ((item.net_amount / this.frm.doc.net_total) * actual) : 0.0; } else if(tax.charge_type == "On Net Total") { + if (tax.account_head in item_tax_map) { + current_net_amount = item.net_amount + }; if (tax.included_in_print_rate){ var net_amount = item.amount / (1 + tax_rate / 100.0) current_tax_amount = item.amount - net_amount @@ -30,10 +34,12 @@ if (erpnext.taxes_and_totals) { current_tax_amount = (tax_rate / 100.0) * item.net_amount; } } else if(tax.charge_type == "On Previous Row Amount") { + current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item current_tax_amount = (tax_rate / 100.0) * this.frm.doc["taxes"][cint(tax.row_id) - 1].tax_amount_for_current_item; } else if(tax.charge_type == "On Previous Row Total") { + current_net_amount = this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item current_tax_amount = (tax_rate / 100.0) * this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item; } else if (tax.charge_type == "On Item Quantity") { @@ -43,7 +49,16 @@ if (erpnext.taxes_and_totals) { if (!tax.dont_recompute_tax) { this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount); } - return flt(current_tax_amount, precision("tax_amount", tax)) + // return [current_net_amount, flt(current_tax_amount, precision("tax_amount", tax))]; + const erpnext_version = frappe.boot?.versions?.erpnext; + // Ensure that the version checked is formatted as semantic version strings + if (is_version_greater_or_equal(erpnext_version, "15.101")){ + return [current_net_amount, flt(current_tax_amount, precision("tax_amount", tax))]; + + }else { + return flt(current_tax_amount, precision("tax_amount", tax)) + } + }; @@ -67,3 +82,29 @@ if (erpnext.taxes_and_totals) { tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))]; }; } + +function is_version_greater_or_equal(current, target) { + if (!current) return false; + + // If current is an object (some older Frappe configs stored it as object) + if (typeof current === "object" && current.version) { + current = current.version; + } + + // Clean beta/alpha suffix e.g "15.10.1-beta" -> "15.10.1" + current = String(current).split("-")[0]; + target = String(target).split("-")[0]; + + const c = current.split(".").map(Number); + const t = target.split(".").map(Number); + + for (let i = 0; i < Math.max(c.length, t.length); i++) { + const cv = c[i] || 0; + const tv = t[i] || 0; + + if (cv > tv) return true; + if (cv < tv) return false; + } + + return true; // equal +}