refactor: make tax category
diff --git a/erpnext/setup/setup_wizard/data/country_wise_tax.json b/erpnext/setup/setup_wizard/data/country_wise_tax.json
index 2e2a0ca..5ed8ab9 100644
--- a/erpnext/setup/setup_wizard/data/country_wise_tax.json
+++ b/erpnext/setup/setup_wizard/data/country_wise_tax.json
@@ -481,6 +481,10 @@
},
"Germany": {
+ "tax_categories": [
+ "Umsatzsteuer",
+ "Vorsteuer"
+ ],
"chart_of_accounts": {
"SKR04 mit Kontonummern": {
"sales_tax_templates": [
diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py
index 4a3de95..f4fe18e 100644
--- a/erpnext/setup/setup_wizard/operations/taxes_setup.py
+++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py
@@ -26,7 +26,7 @@
if 'chart_of_accounts' not in country_wise_tax:
country_wise_tax = simple_to_detailed(country_wise_tax)
- from_detailed_data(company_name, country_wise_tax.get('chart_of_accounts'))
+ from_detailed_data(company_name, country_wise_tax)
def simple_to_detailed(templates):
@@ -77,10 +77,16 @@
def from_detailed_data(company_name, data):
"""Create Taxes and Charges Templates from detailed data."""
coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts')
- tax_templates = data.get(coa_name) or data.get('*')
- sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*')
- purchase_tax_templates = tax_templates.get('purchase_tax_templates') or tax_templates.get('*')
- item_tax_templates = tax_templates.get('item_tax_templates') or tax_templates.get('*')
+ coa_data = data.get('chart_of_accounts', {})
+ tax_templates = coa_data.get(coa_name) or coa_data.get('*', {})
+ tax_categories = data.get('tax_categories')
+ sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*', {})
+ purchase_tax_templates = tax_templates.get('purchase_tax_templates') or tax_templates.get('*', {})
+ item_tax_templates = tax_templates.get('item_tax_templates') or tax_templates.get('*', {})
+
+ if tax_categories:
+ for tax_category in tax_categories:
+ make_tax_catgory(tax_category)
if sales_tax_templates:
for template in sales_tax_templates:
@@ -102,9 +108,6 @@
if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}):
return
- if template.get('tax_category'):
- ensure_tax_category_exists(template.get('tax_category'))
-
for tax_row in template.get('taxes'):
account_data = tax_row.get('account_head')
tax_row_defaults = {
@@ -241,8 +244,12 @@
return tax_group_name
-def ensure_tax_category_exists(name):
- if not frappe.db.exists('Tax Category', name):
- doc = frappe.new_doc('Tax Category')
- doc.title = name
- doc.save()
+def make_tax_catgory(tax_category):
+ doctype = 'Tax Category'
+ if isinstance(tax_category, str):
+ tax_category = {'title': tax_category}
+
+ tax_category['doctype'] = doctype
+ if not frappe.db.exists(doctype, tax_category['title']):
+ doc = frappe.get_doc(tax_category)
+ doc.insert(ignore_permissions=True)