fix: Patch for updating tax withholding category dates (#27489)

This commit is contained in:
Deepesh Garg 2021-09-14 20:28:48 +05:30 committed by GitHub
parent fea51f4082
commit c53b78e712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 68 deletions

View File

@ -3,8 +3,6 @@
import frappe
from erpnext.accounts.utils import get_fiscal_year
def execute():
frappe.reload_doc('accounts', 'doctype', 'Tax Withholding Rate')
@ -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,

View File

@ -758,11 +758,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")):
@ -777,9 +777,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])
@ -802,149 +803,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():