Create tax template based on country

This commit is contained in:
Nabin Hait 2016-10-20 15:49:39 +05:30
parent d23835be84
commit 6fb7b162e8

View File

@ -69,55 +69,6 @@ def setup_complete(args=None):
pass
def create_sales_tax(args):
country_wise_tax = get_country_wise_tax(args.get("country"))
if len(country_wise_tax)>0:
for sales_tax, tax_data in country_wise_tax.items():
account = create_account(tax_data, args)
if account:
create_sales_template(sales_tax, account, args)
def create_account(tax_data, args):
try:
account = frappe.get_doc({
"doctype": "Account",
"is_group": 0,
"root_type": "Liability",
"company": args.get("company_name"),
"parent_account": "Duties and Taxes - %s"%(args.get('company_abbr')),
"account_name": tax_data.get('account_name'),
"account_type": "Tax",
"tax_rate": tax_data.get('tax_rate'),
"currency": args.get('currency')
}).insert(ignore_permissions=True)
return account.name
except:
return None
def create_sales_template(sales_tax, account, args):
sales_tax_template = frappe.get_doc({
"doctype": "Sales Taxes and Charges Template",
"title": sales_tax,
"company": args.get("company_name"),
"taxes": [{
"doctype": "Sales Taxes and Charges",
"charge_type": "On Net Total",
"account_head": account,
"description": sales_tax.split("-")[0]
}]
}).insert(ignore_permissions=True)
sales_tax_template.set_missing_values()
sales_tax_template.save()
def get_country_wise_tax(country):
data = {}
with open (os.path.join(os.path.dirname(__file__), "data", "country_wise_tax.json")) as countrywise_tax:
data = json.load(countrywise_tax).get(country)
return data
def create_fiscal_year_and_company(args):
if (args.get('fy_start_date')):
curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))
@ -294,20 +245,34 @@ def get_fy_details(fy_start_date, fy_end_date):
fy = cstr(start_year) + '-' + cstr(start_year + 1)
return fy
def create_taxes(args):
def create_sales_tax(args):
country_wise_tax = get_country_wise_tax(args.get("country"))
if len(country_wise_tax)>0:
for sales_tax, tax_data in country_wise_tax.items():
make_tax_account_and_template(args.get("company_name").strip(),
tax_data.get('account_name'), tax_data.get('tax_rate'), sales_tax)
def get_country_wise_tax(country):
data = {}
with open (os.path.join(os.path.dirname(__file__), "data", "country_wise_tax.json")) as countrywise_tax:
data = json.load(countrywise_tax).get(country)
return data
def create_taxes(args):
for i in xrange(1,6):
if args.get("tax_" + str(i)):
# replace % in case someone also enters the % symbol
tax_rate = cstr(args.get("tax_rate_" + str(i)) or "").replace("%", "")
account_name = args.get("tax_" + str(i))
make_tax_account_and_template(args.get("company_name").strip(), account_name, tax_rate)
def make_tax_account_and_template(company, account_name, tax_rate, template_name=None):
try:
tax_group = frappe.db.get_value("Account", {"company": args.get("company_name"),
"is_group": 1, "account_type": "Tax", "root_type": "Liability"})
if tax_group:
account = make_tax_head(args, i, tax_group, tax_rate)
make_sales_and_purchase_tax_templates(account)
account = make_tax_account(company, account_name, tax_rate)
if account:
make_sales_and_purchase_tax_templates(account, template_name)
except frappe.NameError, e:
if e.args[2][0]==1062:
pass
@ -316,22 +281,38 @@ def create_taxes(args):
except RootNotEditable, e:
pass
def make_tax_head(args, i, tax_group, tax_rate):
def get_tax_account_group(company):
tax_group = frappe.db.get_value("Account",
{"account_name": "Duties and Taxes", "is_group": 1, "company": company})
if not tax_group:
tax_group = frappe.db.get_value("Account", {"is_group": 1, "root_type": "Liability",
"account_type": "Tax", "company": company})
return tax_group
def make_tax_account(company, account_name, tax_rate):
tax_group = get_tax_account_group(company)
if tax_group:
return frappe.get_doc({
"doctype":"Account",
"company": args.get("company_name").strip(),
"company": company,
"parent_account": tax_group,
"account_name": args.get("tax_" + str(i)),
"account_name": account_name,
"is_group": 0,
"report_type": "Balance Sheet",
"root_type": "Liability",
"account_type": "Tax",
"tax_rate": flt(tax_rate) if tax_rate else None
}).insert(ignore_permissions=True)
def make_sales_and_purchase_tax_templates(account):
doc = {
def make_sales_and_purchase_tax_templates(account, template_name=None):
if not template_name:
template_name = account.name
sales_tax_template = {
"doctype": "Sales Taxes and Charges Template",
"title": account.name,
"title": template_name,
"company": account.company,
"taxes": [{
"category": "Valuation and Total",
"charge_type": "On Net Total",
@ -342,11 +323,12 @@ def make_sales_and_purchase_tax_templates(account):
}
# Sales
frappe.get_doc(copy.deepcopy(doc)).insert()
frappe.get_doc(copy.deepcopy(sales_tax_template)).insert(ignore_permissions=True)
# Purchase
doc["doctype"] = "Purchase Taxes and Charges Template"
frappe.get_doc(copy.deepcopy(doc)).insert()
purchase_tax_template = copy.deepcopy(sales_tax_template)
purchase_tax_template["doctype"] = "Purchase Taxes and Charges Template"
frappe.get_doc(purchase_tax_template).insert(ignore_permissions=True)
def create_items(args):
for i in xrange(1,6):