From a32a79e90a97a8a5814c9cc7ece26dc598708f3c Mon Sep 17 00:00:00 2001 From: ljain112 Date: Thu, 17 Apr 2025 20:23:48 +0530 Subject: [PATCH] fix: rate based on posting date in Tax Withholding Report --- .../tax_withholding_details.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py index 4cec0fbddcf..0da5fcfc7ef 100644 --- a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py @@ -4,6 +4,7 @@ import frappe from frappe import _ +from frappe.utils import getdate def execute(filters=None): @@ -33,6 +34,7 @@ def execute(filters=None): def validate_filters(filters): """Validate if dates are properly set""" + filters = frappe._dict(filters or {}) if filters.from_date > filters.to_date: frappe.throw(_("From Date must be before To Date")) @@ -68,7 +70,7 @@ def get_result(filters, tds_docs, tds_accounts, tax_category_map, journal_entry_ if not tax_withholding_category: tax_withholding_category = party_map.get(party, {}).get("tax_withholding_category") - rate = tax_rate_map.get(tax_withholding_category) + rate = get_tax_withholding_rates(tax_rate_map.get(tax_withholding_category, []), posting_date) if net_total_map.get((voucher_type, name)): if voucher_type == "Journal Entry" and tax_amount and rate: # back calcalute total amount from rate and tax_amount @@ -439,12 +441,22 @@ def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None): def get_tax_rate_map(filters): rate_map = frappe.get_all( "Tax Withholding Rate", - filters={ - "from_date": ("<=", filters.get("from_date")), - "to_date": (">=", filters.get("to_date")), - }, - fields=["parent", "tax_withholding_rate"], - as_list=1, + filters={"from_date": ("<=", filters.to_date), "to_date": (">=", filters.from_date)}, + fields=["parent", "tax_withholding_rate", "from_date", "to_date"], ) - return frappe._dict(rate_map) + rate_list = frappe._dict() + + for rate in rate_map: + rate_list.setdefault(rate.parent, []).append(frappe._dict(rate)) + + return rate_list + + +def get_tax_withholding_rates(tax_withholding, posting_date): + # returns the row that matches with the fiscal year from posting date + for rate in tax_withholding: + if getdate(rate.from_date) <= getdate(posting_date) <= getdate(rate.to_date): + return rate.tax_withholding_rate + + return 0