Hi,
Here in India,We are supposed to round off individual taxes to full rupees.
I have had enough from my accountant and I started to dig into code to see if I can do this.
All tax calculations are done in the controller - taxes_and_totals.
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import json
import frappe
from frappe import _, scrub
from frappe.utils import cint, flt, round_based_on_smallest_currency_fraction
import erpnext
from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
from erpnext.accounts.doctype.pricing_rule.utils import get_applied_pricing_rules
from erpnext.controllers.accounts_controller import (
validate_conversion_rate,
validate_inclusive_tax,
validate_taxes_and_charges,
)
from erpnext.stock.get_item_details import _get_item_tax_template
This file has been truncated. show original
All our transactions are in one currency i.e INR and we dont use “inclusive tax” feature.
Actual calculation of taxes happen in the function “calculate_taxes” in the controller.
def calculate_taxes(self):
# maintain actual tax rate based on idx
actual_tax_dict = dict([[tax.idx, flt(tax.tax_amount, tax.precision("tax_amount"))]
for tax in self.doc.get("taxes") if tax.charge_type == "Actual"])
for n, item in enumerate(self.doc.get("items")):
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
for i, tax in enumerate(self.doc.get("taxes")):
# tax_amount represents the amount of tax for the current step
current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map)
# Adjust divisional loss to the last item
if tax.charge_type == "Actual":
actual_tax_dict[tax.idx] -= current_tax_amount
if n == len(self.doc.get("items")) - 1:
current_tax_amount += actual_tax_dict[tax.idx]
# accumulate tax amount into tax.tax_amount
if tax.charge_type != "Actual" and \
This file has been truncated. show original
I am adding my code at the end of this function and it seems to work fine.
var1 = self.doc.get("taxes")
for i, tax in enumerate(self.doc.get("taxes")):
if i == 0:
tax.tax_amount = flt(tax.tax_amount,0)
tax.total = flt(tax.total,0)
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,0)
tax.base_tax_amount = flt(tax.base_tax_amount,0)
tax.base_total = flt(tax.base_total,0)
tax.base_tax_amount_after_discount_amount = flt(tax.base_tax_amount_after_discount_amount,0)
else:
tax.tax_amount = flt(tax.tax_amount,0)
tax.total = var1[i-1].total + tax.tax_amount
tax.total = flt(tax.total,0)
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,0)
tax.base_tax_amount = flt(tax.base_tax_amount,0)
tax.base_total = flt(tax.base_total,0)
tax.base_tax_amount_after_discount_amount = flt(tax.base_tax_amount_after_discount_amount,0)
Can someone who is interested in rounding off individual tax rounding off test this?
We can add a check box in accounts settings “Round off individual taxes” and if it is ticked we can run this code.
(Your grand total may be wrong, for now please ignore that for now)
2 Likes
i will test it today and tell you what happen , i’m very interested , and i think we should but the check inside the tax itself because there is some countries do it for one tax or to not all the taxes .
It should work for simple case like yours.
But if you want to contribute back, you have to figure out for all the scenarios like inclusive tax, additional discount etc.
it works after saving the document .
i add a function , so when tax amount fraction > .5 would be 1 and if fraction< .5 its .5
how do apply this to a certain tax not all of them just >???