resilient-tech/india-compliance

Check for root type if accounts exists or not

Closed this issue · 1 comments

Erpnext checks for duplication using Root Type and Account name.
If account already exists with different root type error can be raised.

https://support.frappe.io/app/hd-ticket/15283

App erpnext already installed

Installing india_compliance...
Updating DocTypes for india_compliance: [========================================] 100%
Setting up Income Tax...
Setting up GST...
Patching Existing Data...
Installation for India Compliance failed due to an error. Please try re-installing the app or report the issue on https://github.com/resilient-tech/india-compliance/issues/new if not resolved.
An error occurred while installing india_compliance: ('Account', 'Input Tax CGST - PBSPL', IntegrityError(1062, "Duplicate entry 'Input Tax CGST - PBSPL' for key 'PRIMARY'"))
Traceback with variables (most recent call last):
  File "apps/frappe/frappe/commands/site.py", line 445, in install_app
    _install_app(app, verbose=context.verbose, force=force)
      context = {'sites': ['uatparamountsteel.frappe.cloud'], 'force': False, 'verbose': False, 'profile': False}
      apps = ('india_compliance',)
      force = True
      _install_app = <function install_app at 0x7f5ad3dc1120>
      filelock = <function filelock at 0x7f5ad3fb2340>
      exit_code = 0
      site = 'uatparamountsteel.frappe.cloud'
      app = 'india_compliance'
      err = DuplicateEntryError('Account', 'Input Tax CGST - PBSPL', IntegrityError(1062, "Duplicate entry 'Input Tax CGST - PBSPL' for key 'PRIMARY'"))
  File "apps/frappe/frappe/installer.py", line 311, in install_app
    frappe.get_attr(after_install)()
      name = 'india_compliance'
      verbose = False
      set_as_patched = True
      force = True
      sync_jobs = <function sync_jobs at 0x7f5ad2d9e840>
      sync_for = <function sync_for at 0x7f5ad2d9f6a0>
      sync_customizations = <function sync_customizations at 0x7f5ad3f4ab60>
      sync_fixtures = <function sync_fixtures at 0x7f5ad2d9f9c0>
      app_hooks = {'accounting_dimension_doctypes': ['Bill of Entry', 'Bill of Entry Item'], 'after_app_install': ['india_compliance.install.after_app_install'], 'after_install': ['india_compliance.install.after_install'], 'after_migrate': ['india_compliance.audit_trail.setup.after_migrate'], 'app_color': ['grey'], 'app_description': ['ERPNext app to simplify compliance with Indian Rules and Regulations'], 'app_email': ['hello@indiacompliance.app'], 'app_icon': ['octicon octicon-file-directory'], 'app_include_js': ['india_compliance.bundle.js'], 'app_license': ['GNU General Public License (v3)'], 'app_name': ['india_compliance'], 'app_publisher': ['Resilient Tech'], 'app_title': ['India Compliance'], 'audit_trail_doctypes': ['Accounts Settings', 'Dunning', 'Invoice Discounting', 'Journal Entry', 'Payment Entry', 'Period Closing Voucher', 'Process Deferred Accounting', 'Purchase Invoice', 'Sales Invoice', 'Asset', 'Asset Capitalization', 'Asset Repair', 'Delivery Note', 'Landed Cost Voucher', 'Purchase R...
      installed_apps = ['frappe', 'erpnext', 'hrms', 'paramount', 'india_compliance']
      app = 'frappe/erpnext'
      required_app = 'erpnext'
      before_install = 'india_compliance.patches.check_version_compatibility.execute'
      out = None
      after_install = 'india_compliance.install.after_install'
  File "apps/india_compliance/india_compliance/install.py", line 73, in after_install
    raise e
  File "apps/india_compliance/india_compliance/install.py", line 62, in after_install
    run_post_install_patches()
  File "apps/india_compliance/india_compliance/install.py", line 86, in run_post_install_patches
    frappe.get_attr(f"india_compliance.patches.post_install.{patch}.execute")()
      patch = 'update_company_fixtures'
  File "apps/india_compliance/india_compliance/patches/post_install/update_company_fixtures.py", line 30, in execute
    make_default_tax_templates(company)
      company_list = ['Paramount Building Solutions Private Limited']
      company = 'Paramount Building Solutions Private Limited'
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
      args = ('Paramount Building Solutions Private Limited',)
      kwargs = {}
      apply_condition = <function whitelist.<locals>.innerfn.<locals>.<lambda> at 0x7f5acf44aa20>
      func = <function make_default_tax_templates at 0x7f5acf44a980>
  File "apps/india_compliance/india_compliance/gst_india/overrides/company.py", line 68, in make_default_tax_templates
    from_detailed_data(company, default_taxes)
      company = 'Paramount Building Solutions Private Limited'
      gst_rate = None
      default_taxes = {'tax_categories': [{'title': 'In-State', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Out-State', 'is_inter_state': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge In-State', 'is_inter_state': 0, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge Out-State', 'is_inter_state': 1, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Registered Composition', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}], 'chart_of_accounts': {'*': {'item_tax_templates': [{'title': 'GST 18%', 'gst_rate': 18, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax IGST', 'tax_rate': 18.0}}, {'tax_type': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_na...
  File "apps/erpnext/erpnext/setup/setup_wizard/operations/taxes_setup.py", line 107, in from_detailed_data
    make_taxes_and_charges_template(company_name, "Purchase Taxes and Charges Template", template)
      company_name = 'Paramount Building Solutions Private Limited'
      data = {'tax_categories': [{'title': 'In-State', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Out-State', 'is_inter_state': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge In-State', 'is_inter_state': 0, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge Out-State', 'is_inter_state': 1, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Registered Composition', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}], 'chart_of_accounts': {'*': {'item_tax_templates': [{'title': 'GST 18%', 'gst_rate': 18, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax IGST', 'tax_rate': 18.0}}, {'tax_type': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_na...
      coa_name = 'India - Chart of Accounts'
      coa_data = {'*': {'item_tax_templates': [{'title': 'GST 18%', 'gst_rate': 18, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax IGST', 'tax_rate': 18.0}}, {'tax_type': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax IGST', 'tax_rate': 18.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax SGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax CGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax IGST RCM', 'tax_rate': 18.0}}]}, {'title': 'GST 5%', 'gst_rate': 5, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 2.5}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 2.5}...
      tax_templates = {'item_tax_templates': [{'title': 'GST 18%', 'gst_rate': 18, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax IGST', 'tax_rate': 18.0}}, {'tax_type': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax IGST', 'tax_rate': 18.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax SGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax CGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax IGST RCM', 'tax_rate': 18.0}}]}, {'title': 'GST 5%', 'gst_rate': 5, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 2.5}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 2.5}}, {'t...
      tax_categories = [{'title': 'In-State', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Out-State', 'is_inter_state': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge In-State', 'is_inter_state': 0, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Reverse Charge Out-State', 'is_inter_state': 1, 'is_reverse_charge': 1, 'gst_state': '', 'doctype': 'Tax Category'}, {'title': 'Registered Composition', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}]
      sales_tax_templates = [{'title': 'Output GST In-state', 'taxes': [{'account_head': 'Output Tax SGST - PBSPL', 'description': 'SGST', 'category': 'Total', 'charge_type': 'On Net Total', 'cost_center': 'Main - PBSPL', 'rate': 9.0, 'doctype': 'Sales Taxes and Charges'}, {'account_head': 'Output Tax CGST - PBSPL', 'description': 'CGST', 'category': 'Total', 'charge_type': 'On Net Total', 'cost_center': 'Main - PBSPL', 'rate': 9.0, 'doctype': 'Sales Taxes and Charges'}], 'tax_category': 'In-State', 'company': 'Paramount Building Solutions Private Limited', 'doctype': 'Sales Taxes and Charges Template'}, {'title': 'Output GST Out-state', 'taxes': [{'account_head': 'Output Tax IGST - PBSPL', 'description': 'IGST', 'category': 'Total', 'charge_type': 'On Net Total', 'cost_center': 'Main - PBSPL', 'rate': 18.0, 'doctype': 'Sales Taxes and Charges'}], 'tax_category': 'Out-State', 'company': 'Paramount Building Solutions Private Limited', 'doctype': 'Sales Taxes and Charges Template'}]
      purchase_tax_templates = [{'title': 'Input GST In-state', 'taxes': [{'account_head': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}, 'description': 'CGST'}, {'account_head': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax'}, 'description': 'SGST'}], 'tax_category': 'In-State', 'company': 'Paramount Building Solutions Private Limited', 'doctype': 'Purchase Taxes and Charges Template'}, {'title': 'Input GST Out-state', 'taxes': [{'account_head': {'account_name': 'Input Tax IGST', 'tax_rate': 18.0, 'root_type': 'Asset', 'account_type': 'Tax'}, 'description': 'IGST'}], 'tax_category': 'Out-State'}, {'title': 'Input GST RCM In-state', 'taxes': [{'account_head': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax'...
      item_tax_templates = [{'title': 'GST 18%', 'gst_rate': 18, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Output Tax IGST', 'tax_rate': 18.0}}, {'tax_type': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax IGST', 'tax_rate': 18.0, 'root_type': 'Asset'}}, {'tax_type': {'account_name': 'Input Tax SGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax CGST RCM', 'tax_rate': 9.0}}, {'tax_type': {'account_name': 'Input Tax IGST RCM', 'tax_rate': 18.0}}]}, {'title': 'GST 5%', 'gst_rate': 5, 'gst_treatment': 'Taxable', 'taxes': [{'tax_type': {'account_name': 'Output Tax SGST', 'tax_rate': 2.5}}, {'tax_type': {'account_name': 'Output Tax CGST', 'tax_rate': 2.5}}, {'tax_type': {'account_nam...
      tax_category = {'title': 'Registered Composition', 'is_inter_state': 0, 'gst_state': '', 'doctype': 'Tax Category'}
      template = {'title': 'Input GST In-state', 'taxes': [{'account_head': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}, 'description': 'CGST'}, {'account_head': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax'}, 'description': 'SGST'}], 'tax_category': 'In-State', 'company': 'Paramount Building Solutions Private Limited', 'doctype': 'Purchase Taxes and Charges Template'}
  File "apps/erpnext/erpnext/setup/setup_wizard/operations/taxes_setup.py", line 151, in make_taxes_and_charges_template
    account = get_or_create_account(company_name, account_data)
      company_name = 'Paramount Building Solutions Private Limited'
      doctype = 'Purchase Taxes and Charges Template'
      template = {'title': 'Input GST In-state', 'taxes': [{'account_head': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}, 'description': 'CGST'}, {'account_head': {'account_name': 'Input Tax SGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax'}, 'description': 'SGST'}], 'tax_category': 'In-State', 'company': 'Paramount Building Solutions Private Limited', 'doctype': 'Purchase Taxes and Charges Template'}
      tax_row = {'account_head': {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}, 'description': 'CGST'}
      account_data = {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}
      tax_row_defaults = {'category': 'Total', 'charge_type': 'On Net Total', 'cost_center': 'Main - PBSPL', 'add_deduct_tax': 'Add', 'description': 'Input Tax CGST @ 9.0', 'rate': 9.0}
  File "apps/erpnext/erpnext/setup/setup_wizard/operations/taxes_setup.py", line 236, in get_or_create_account
    doc.insert(ignore_permissions=True, ignore_mandatory=True)
      company_name = 'Paramount Building Solutions Private Limited'
      account = {'account_name': 'Input Tax CGST', 'tax_rate': 9.0, 'root_type': 'Asset', 'account_type': 'Tax', 'doctype': 'Account', 'company': 'Paramount Building Solutions Private Limited', 'parent_account': 'Tax Assets - PBSPL', 'report_type': 'Balance Sheet', 'is_group': 0}
      default_root_type = 'Liability'
      root_type = 'Asset'
      existing_accounts = []
      tax_group = 'Tax Assets - PBSPL'
      doc = <Account: Input Tax CGST - PBSPL>
  File "apps/frappe/frappe/model/document.py", line 302, in insert
    self.db_insert(ignore_if_duplicate=ignore_if_duplicate)
      self = <Account: Input Tax CGST - PBSPL>
      ignore_permissions = True
      ignore_links = None
      ignore_if_duplicate = False
      ignore_mandatory = True
      set_name = None
      set_child_names = True
  File "apps/frappe/frappe/model/base_document.py", line 577, in db_insert
    raise frappe.DuplicateEntryError(self.doctype, self.name, e)
      self = <Account: Input Tax CGST - PBSPL>
      ignore_if_duplicate = False
      conflict_handler = ''
      d = {'name': 'Input Tax CGST - PBSPL', 'owner': 'Administrator', 'creation': '2024-05-16 13:09:16.219299', 'modified': '2024-05-16 13:09:16.219299', 'modified_by': 'Administrator', 'docstatus': 0, 'idx': 0, 'disabled': 0, 'account_name': 'Input Tax CGST', 'account_number': None, 'is_group': 0, 'company': 'Paramount Building Solutions Private Limited', 'root_type': 'Asset', 'report_type': 'Balance Sheet', 'account_currency': None, 'parent_account': 'Tax Assets - PBSPL', 'account_type': 'Tax', 'tax_rate': 9.0, 'freeze_account': 'No', 'balance_must_be': '', 'lft': 0, 'rgt': 0, 'old_parent': None, 'include_in_gross': 0}
      columns = ['name', 'owner', 'creation', 'modified', 'modified_by', 'docstatus', 'idx', 'disabled', 'account_name', 'account_number', 'is_group', 'company', 'root_type', 'report_type', 'account_currency', 'parent_account', 'account_type', 'tax_rate', 'freeze_account', 'balance_must_be', 'lft', 'rgt', 'old_parent', 'include_in_gross']
frappe.exceptions.DuplicateEntryError: ('Account', 'Input Tax CGST - PBSPL', IntegrityError(1062, "Duplicate entry 'Input Tax CGST - PBSPL' for key 'PRIMARY'")

Instead we can ignore if duplicate?