refactor: make tax category
This commit is contained in:
parent
e3557ff131
commit
f259bf48aa
@ -481,6 +481,10 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"Germany": {
|
"Germany": {
|
||||||
|
"tax_categories": [
|
||||||
|
"Umsatzsteuer",
|
||||||
|
"Vorsteuer"
|
||||||
|
],
|
||||||
"chart_of_accounts": {
|
"chart_of_accounts": {
|
||||||
"SKR04 mit Kontonummern": {
|
"SKR04 mit Kontonummern": {
|
||||||
"sales_tax_templates": [
|
"sales_tax_templates": [
|
||||||
|
@ -26,7 +26,7 @@ def setup_taxes_and_charges(company_name: str, country: str):
|
|||||||
if 'chart_of_accounts' not in country_wise_tax:
|
if 'chart_of_accounts' not in country_wise_tax:
|
||||||
country_wise_tax = simple_to_detailed(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):
|
def simple_to_detailed(templates):
|
||||||
@ -77,10 +77,16 @@ def simple_to_detailed(templates):
|
|||||||
def from_detailed_data(company_name, data):
|
def from_detailed_data(company_name, data):
|
||||||
"""Create Taxes and Charges Templates from detailed data."""
|
"""Create Taxes and Charges Templates from detailed data."""
|
||||||
coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts')
|
coa_name = frappe.db.get_value('Company', company_name, 'chart_of_accounts')
|
||||||
tax_templates = data.get(coa_name) or data.get('*')
|
coa_data = data.get('chart_of_accounts', {})
|
||||||
sales_tax_templates = tax_templates.get('sales_tax_templates') or tax_templates.get('*')
|
tax_templates = coa_data.get(coa_name) or coa_data.get('*', {})
|
||||||
purchase_tax_templates = tax_templates.get('purchase_tax_templates') or tax_templates.get('*')
|
tax_categories = data.get('tax_categories')
|
||||||
item_tax_templates = tax_templates.get('item_tax_templates') or tax_templates.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('*', {})
|
||||||
|
|
||||||
|
if tax_categories:
|
||||||
|
for tax_category in tax_categories:
|
||||||
|
make_tax_catgory(tax_category)
|
||||||
|
|
||||||
if sales_tax_templates:
|
if sales_tax_templates:
|
||||||
for template in sales_tax_templates:
|
for template in sales_tax_templates:
|
||||||
@ -102,9 +108,6 @@ def make_taxes_and_charges_template(company_name, doctype, template):
|
|||||||
if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}):
|
if frappe.db.exists(doctype, {'title': template.get('title'), 'company': company_name}):
|
||||||
return
|
return
|
||||||
|
|
||||||
if template.get('tax_category'):
|
|
||||||
ensure_tax_category_exists(template.get('tax_category'))
|
|
||||||
|
|
||||||
for tax_row in template.get('taxes'):
|
for tax_row in template.get('taxes'):
|
||||||
account_data = tax_row.get('account_head')
|
account_data = tax_row.get('account_head')
|
||||||
tax_row_defaults = {
|
tax_row_defaults = {
|
||||||
@ -241,8 +244,12 @@ def get_or_create_tax_group(company_name, root_type):
|
|||||||
return tax_group_name
|
return tax_group_name
|
||||||
|
|
||||||
|
|
||||||
def ensure_tax_category_exists(name):
|
def make_tax_catgory(tax_category):
|
||||||
if not frappe.db.exists('Tax Category', name):
|
doctype = 'Tax Category'
|
||||||
doc = frappe.new_doc('Tax Category')
|
if isinstance(tax_category, str):
|
||||||
doc.title = name
|
tax_category = {'title': tax_category}
|
||||||
doc.save()
|
|
||||||
|
tax_category['doctype'] = doctype
|
||||||
|
if not frappe.db.exists(doctype, tax_category['title']):
|
||||||
|
doc = frappe.get_doc(tax_category)
|
||||||
|
doc.insert(ignore_permissions=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user