Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Patch for updating tax withholding category dates #27495

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import frappe

from erpnext.accounts.utils import get_fiscal_year


def execute():
frappe.reload_doc('accounts', 'doctype', 'Tax Withholding Rate')
Expand All @@ -13,12 +11,14 @@ def execute():
tds_category_rates = frappe.get_all('Tax Withholding Rate', fields=['name', 'fiscal_year'])

fiscal_year_map = {}
for rate in tds_category_rates:
if not fiscal_year_map.get(rate.fiscal_year):
fiscal_year_map[rate.fiscal_year] = get_fiscal_year(fiscal_year=rate.fiscal_year)
fiscal_year_details = frappe.get_all('Fiscal Year', fields=['name', 'year_start_date', 'year_end_date'])

from_date = fiscal_year_map.get(rate.fiscal_year)[1]
to_date = fiscal_year_map.get(rate.fiscal_year)[2]
for d in fiscal_year_details:
fiscal_year_map.setdefault(d.name, d)

for rate in tds_category_rates:
from_date = fiscal_year_map.get(rate.fiscal_year).get('year_start_date')
to_date = fiscal_year_map.get(rate.fiscal_year).get('year_end_date')

frappe.db.set_value('Tax Withholding Rate', rate.name, {
'from_date': from_date,
Expand Down
123 changes: 62 additions & 61 deletions erpnext/regional/india/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,11 @@ def set_tax_withholding_category(company):
accounts = [dict(company=company, account=tds_account)]

try:
fiscal_year = get_fiscal_year(today(), verbose=0, company=company)[0]
fiscal_year_details = get_fiscal_year(today(), verbose=0, company=company)
except FiscalYearError:
pass

docs = get_tds_details(accounts, fiscal_year)
docs = get_tds_details(accounts, fiscal_year_details)

for d in docs:
if not frappe.db.exists("Tax Withholding Category", d.get("name")):
Expand All @@ -822,9 +822,10 @@ def set_tax_withholding_category(company):
if accounts:
doc.append("accounts", accounts[0])

if fiscal_year:
if fiscal_year_details:
# if fiscal year don't match with any of the already entered data, append rate row
fy_exist = [k for k in doc.get('rates') if k.get('fiscal_year')==fiscal_year]
fy_exist = [k for k in doc.get('rates') if k.get('from_date') <= fiscal_year_details[1] \
and k.get('to_date') >= fiscal_year_details[2]]
if not fy_exist:
doc.append("rates", d.get('rates')[0])

Expand All @@ -847,149 +848,149 @@ def set_tds_account(docs, company):
}
])

def get_tds_details(accounts, fiscal_year):
def get_tds_details(accounts, fiscal_year_details):
# bootstrap default tax withholding sections
return [
dict(name="TDS - 194C - Company",
category_name="Payment to Contractors (Single / Aggregate)",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
"single_threshold": 30000, "cumulative_threshold": 100000}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 2, "single_threshold": 30000, "cumulative_threshold": 100000}]),
dict(name="TDS - 194C - Individual",
category_name="Payment to Contractors (Single / Aggregate)",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
"single_threshold": 30000, "cumulative_threshold": 100000}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 1, "single_threshold": 30000, "cumulative_threshold": 100000}]),
dict(name="TDS - 194C - No PAN / Invalid PAN",
category_name="Payment to Contractors (Single / Aggregate)",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 30000, "cumulative_threshold": 100000}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 30000, "cumulative_threshold": 100000}]),
dict(name="TDS - 194D - Company",
category_name="Insurance Commission",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 5, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194D - Company Assessee",
category_name="Insurance Commission",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194D - Individual",
category_name="Insurance Commission",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 5, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194D - No PAN / Invalid PAN",
category_name="Insurance Commission",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194DA - Company",
category_name="Non-exempt payments made under a life insurance policy",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
"single_threshold": 100000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 1, "single_threshold": 100000, "cumulative_threshold": 0}]),
dict(name="TDS - 194DA - Individual",
category_name="Non-exempt payments made under a life insurance policy",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 1,
"single_threshold": 100000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 1, "single_threshold": 100000, "cumulative_threshold": 0}]),
dict(name="TDS - 194DA - No PAN / Invalid PAN",
category_name="Non-exempt payments made under a life insurance policy",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 100000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 100000, "cumulative_threshold": 0}]),
dict(name="TDS - 194H - Company",
category_name="Commission / Brokerage",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 5, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194H - Individual",
category_name="Commission / Brokerage",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 5,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 5, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194H - No PAN / Invalid PAN",
category_name="Commission / Brokerage",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 15000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 15000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent - Company",
category_name="Rent",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent - Individual",
category_name="Rent",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent - No PAN / Invalid PAN",
category_name="Rent",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent/Machinery - Company",
category_name="Rent-Plant / Machinery",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 2, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent/Machinery - Individual",
category_name="Rent-Plant / Machinery",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 2,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 2, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194I - Rent/Machinery - No PAN / Invalid PAN",
category_name="Rent-Plant / Machinery",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 180000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 180000, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Professional Fees - Company",
category_name="Professional Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 30000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 30000, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Professional Fees - Individual",
category_name="Professional Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 30000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 30000, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Professional Fees - No PAN / Invalid PAN",
category_name="Professional Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 30000, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 30000, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Director Fees - Company",
category_name="Director Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 0, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 0, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Director Fees - Individual",
category_name="Director Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 0, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 0, "cumulative_threshold": 0}]),
dict(name="TDS - 194J - Director Fees - No PAN / Invalid PAN",
category_name="Director Fees",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 0, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 0, "cumulative_threshold": 0}]),
dict(name="TDS - 194 - Dividends - Company",
category_name="Dividends",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 2500, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 2500, "cumulative_threshold": 0}]),
dict(name="TDS - 194 - Dividends - Individual",
category_name="Dividends",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 10,
"single_threshold": 2500, "cumulative_threshold": 0}]),
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 10, "single_threshold": 2500, "cumulative_threshold": 0}]),
dict(name="TDS - 194 - Dividends - No PAN / Invalid PAN",
category_name="Dividends",
doctype="Tax Withholding Category", accounts=accounts,
rates=[{"fiscal_year": fiscal_year, "tax_withholding_rate": 20,
"single_threshold": 2500, "cumulative_threshold": 0}])
rates=[{"from_date": fiscal_year_details[1], "to_date": fiscal_year_details[2],
"tax_withholding_rate": 20, "single_threshold": 2500, "cumulative_threshold": 0}])
]

def create_gratuity_rule():
Expand Down