diff --git a/india_compliance/hooks.py b/india_compliance/hooks.py index fae92bc51..bc7f36028 100644 --- a/india_compliance/hooks.py +++ b/india_compliance/hooks.py @@ -211,7 +211,6 @@ "validate": "india_compliance.gst_india.overrides.tax_category.validate" }, "Tax Withholding Category": { - "validate": "india_compliance.income_tax_india.overrides.tax_withholding_category.validate", "on_change": "india_compliance.income_tax_india.overrides.tax_withholding_category.on_change", }, "Unreconcile Payment": { diff --git a/india_compliance/income_tax_india/overrides/company.py b/india_compliance/income_tax_india/overrides/company.py index 8aff2f8ac..72d512261 100644 --- a/india_compliance/income_tax_india/overrides/company.py +++ b/india_compliance/income_tax_india/overrides/company.py @@ -41,22 +41,23 @@ def create_or_update_tax_withholding_category(company): categories = get_tds_category_details(accounts) for category_doc in categories: - existing_category_name = frappe.get_value( + existing_category_list = frappe.get_all( "Tax Withholding Category", { "tds_section": category_doc.get("tds_section"), "entity_type": category_doc.get("entity_type"), }, + pluck="name", ) - - if not existing_category_name: + if not existing_category_list: doc = frappe.get_doc(category_doc) doc.insert(ignore_if_duplicate=True, ignore_mandatory=ignore_mandatory) else: - update_existing_tax_withholding_category( - category_doc, existing_category_name, company - ) + for category_name in existing_category_list: + update_existing_tax_withholding_category( + category_doc, category_name, company + ) def update_existing_tax_withholding_category(category_doc, category_name, company): diff --git a/india_compliance/income_tax_india/overrides/tax_withholding_category.py b/india_compliance/income_tax_india/overrides/tax_withholding_category.py index 52b1c25cb..536c5573e 100644 --- a/india_compliance/income_tax_india/overrides/tax_withholding_category.py +++ b/india_compliance/income_tax_india/overrides/tax_withholding_category.py @@ -1,5 +1,4 @@ import frappe -from frappe.utils import get_link_to_form def on_change(doc, method=None): @@ -17,24 +16,3 @@ def _get_tax_withholding_accounts(): return frappe.cache.hget( "tax_withholding_accounts", company, generator=_get_tax_withholding_accounts ) - - -def validate(doc, method=None): - if not (doc.tds_section or doc.entity_type): - return - - existing_doc = frappe.db.exists( - "Tax Withholding Category", - { - "tds_section": doc.tds_section, - "entity_type": doc.entity_type, - "name": ("!=", doc.name), - }, - ) - - if not existing_doc: - return - - frappe.throw( - f'{get_link_to_form("Tax Withholding Category",existing_doc)} already exists for the TDS section - {doc.tds_section} and Entity type - {doc.entity_type}.' - )