fix: Round off final tax amount instead of current tax amount (#25188)
* fix: Round off final tax amount instead of current tax amount * fix: Syntax error * fix: Indentation * fix: Round Off taxes order execution Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
parent
b717420842
commit
b67058869a
@ -291,10 +291,13 @@ class calculate_taxes_and_totals(object):
|
|||||||
# set precision in the last item iteration
|
# set precision in the last item iteration
|
||||||
if n == len(self.doc.get("items")) - 1:
|
if n == len(self.doc.get("items")) - 1:
|
||||||
self.round_off_totals(tax)
|
self.round_off_totals(tax)
|
||||||
|
self._set_in_company_currency(tax,
|
||||||
|
["tax_amount", "tax_amount_after_discount_amount"])
|
||||||
|
|
||||||
|
self.round_off_base_values(tax)
|
||||||
self.set_cumulative_total(i, tax)
|
self.set_cumulative_total(i, tax)
|
||||||
|
|
||||||
self._set_in_company_currency(tax,
|
self._set_in_company_currency(tax, ["total"])
|
||||||
["total", "tax_amount", "tax_amount_after_discount_amount"])
|
|
||||||
|
|
||||||
# adjust Discount Amount loss in last tax iteration
|
# adjust Discount Amount loss in last tax iteration
|
||||||
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
|
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
|
||||||
@ -341,20 +344,11 @@ class calculate_taxes_and_totals(object):
|
|||||||
elif tax.charge_type == "On Item Quantity":
|
elif tax.charge_type == "On Item Quantity":
|
||||||
current_tax_amount = tax_rate * item.qty
|
current_tax_amount = tax_rate * item.qty
|
||||||
|
|
||||||
current_tax_amount = self.get_final_current_tax_amount(tax, current_tax_amount)
|
|
||||||
|
|
||||||
if not self.doc.get("is_consolidated"):
|
if not self.doc.get("is_consolidated"):
|
||||||
self.set_item_wise_tax(item, tax, tax_rate, current_tax_amount)
|
self.set_item_wise_tax(item, tax, tax_rate, current_tax_amount)
|
||||||
|
|
||||||
return current_tax_amount
|
return current_tax_amount
|
||||||
|
|
||||||
def get_final_current_tax_amount(self, tax, current_tax_amount):
|
|
||||||
# Some countries need individual tax components to be rounded
|
|
||||||
# Handeled via regional doctypess
|
|
||||||
if tax.account_head in frappe.flags.round_off_applicable_accounts:
|
|
||||||
current_tax_amount = round(current_tax_amount, 0)
|
|
||||||
return current_tax_amount
|
|
||||||
|
|
||||||
def set_item_wise_tax(self, item, tax, tax_rate, current_tax_amount):
|
def set_item_wise_tax(self, item, tax, tax_rate, current_tax_amount):
|
||||||
# store tax breakup for each item
|
# store tax breakup for each item
|
||||||
key = item.item_code or item.item_name
|
key = item.item_code or item.item_name
|
||||||
@ -365,10 +359,20 @@ class calculate_taxes_and_totals(object):
|
|||||||
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount)]
|
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount)]
|
||||||
|
|
||||||
def round_off_totals(self, tax):
|
def round_off_totals(self, tax):
|
||||||
|
if tax.account_head in frappe.flags.round_off_applicable_accounts:
|
||||||
|
tax.tax_amount = round(tax.tax_amount, 0)
|
||||||
|
tax.tax_amount_after_discount_amount = round(tax.tax_amount_after_discount_amount, 0)
|
||||||
|
|
||||||
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
|
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
|
||||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
|
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
|
||||||
tax.precision("tax_amount"))
|
tax.precision("tax_amount"))
|
||||||
|
|
||||||
|
def round_off_base_values(self, tax):
|
||||||
|
# Round off to nearest integer based on regional settings
|
||||||
|
if tax.account_head in frappe.flags.round_off_applicable_accounts:
|
||||||
|
tax.base_tax_amount = round(tax.base_tax_amount, 0)
|
||||||
|
tax.base_tax_amount_after_discount_amount = round(tax.base_tax_amount_after_discount_amount, 0)
|
||||||
|
|
||||||
def manipulate_grand_total_for_inclusive_tax(self):
|
def manipulate_grand_total_for_inclusive_tax(self):
|
||||||
# if fully inclusive taxes and diff
|
# if fully inclusive taxes and diff
|
||||||
if self.doc.get("taxes") and any([cint(t.included_in_print_rate) for t in self.doc.get("taxes")]):
|
if self.doc.get("taxes") and any([cint(t.included_in_print_rate) for t in self.doc.get("taxes")]):
|
||||||
|
@ -323,12 +323,15 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
// set precision in the last item iteration
|
// set precision in the last item iteration
|
||||||
if (n == me.frm.doc["items"].length - 1) {
|
if (n == me.frm.doc["items"].length - 1) {
|
||||||
me.round_off_totals(tax);
|
me.round_off_totals(tax);
|
||||||
|
me.set_in_company_currency(tax,
|
||||||
|
["tax_amount", "tax_amount_after_discount_amount"]);
|
||||||
|
|
||||||
|
me.round_off_base_values(tax);
|
||||||
|
|
||||||
// in tax.total, accumulate grand total for each item
|
// in tax.total, accumulate grand total for each item
|
||||||
me.set_cumulative_total(i, tax);
|
me.set_cumulative_total(i, tax);
|
||||||
|
|
||||||
me.set_in_company_currency(tax,
|
me.set_in_company_currency(tax, ["total"]);
|
||||||
["total", "tax_amount", "tax_amount_after_discount_amount"]);
|
|
||||||
|
|
||||||
// adjust Discount Amount loss in last tax iteration
|
// adjust Discount Amount loss in last tax iteration
|
||||||
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied
|
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied
|
||||||
@ -393,20 +396,11 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
current_tax_amount = tax_rate * item.qty;
|
current_tax_amount = tax_rate * item.qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_tax_amount = this.get_final_tax_amount(tax, current_tax_amount);
|
|
||||||
this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);
|
this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);
|
||||||
|
|
||||||
return current_tax_amount;
|
return current_tax_amount;
|
||||||
},
|
},
|
||||||
|
|
||||||
get_final_tax_amount: function(tax, current_tax_amount) {
|
|
||||||
if (frappe.flags.round_off_applicable_accounts.includes(tax.account_head)) {
|
|
||||||
current_tax_amount = Math.round(current_tax_amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
return current_tax_amount;
|
|
||||||
},
|
|
||||||
|
|
||||||
set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
|
set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
|
||||||
// store tax breakup for each item
|
// store tax breakup for each item
|
||||||
let tax_detail = tax.item_wise_tax_detail;
|
let tax_detail = tax.item_wise_tax_detail;
|
||||||
@ -420,10 +414,22 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
round_off_totals: function(tax) {
|
round_off_totals: function(tax) {
|
||||||
|
if (frappe.flags.round_off_applicable_accounts.includes(tax.account_head)) {
|
||||||
|
tax.tax_amount= Math.round(tax.tax_amount);
|
||||||
|
tax.tax_amount_after_discount_amount = Math.round(tax.tax_amount_after_discount_amount);
|
||||||
|
}
|
||||||
|
|
||||||
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
|
||||||
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
|
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
round_off_base_values: function(tax) {
|
||||||
|
if (frappe.flags.round_off_applicable_accounts.includes(tax.account_head)) {
|
||||||
|
tax.base_tax_amount= Math.round(tax.base_tax_amount);
|
||||||
|
tax.base_tax_amount_after_discount_amount = Math.round(tax.base_tax_amount_after_discount_amount);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
manipulate_grand_total_for_inclusive_tax: function() {
|
manipulate_grand_total_for_inclusive_tax: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
// if fully inclusive taxes and diff
|
// if fully inclusive taxes and diff
|
||||||
|
Loading…
x
Reference in New Issue
Block a user