[Feature] Countrywise sales tax template

This commit is contained in:
Rohit Waghchaure 2016-09-23 20:43:23 +05:30 committed by Nabin Hait
parent bc0783b527
commit d23835be84
3 changed files with 1478 additions and 40 deletions

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _ from frappe import _
from frappe.utils import flt
from frappe.model.document import Document from frappe.model.document import Document
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
@ -11,6 +12,11 @@ class SalesTaxesandChargesTemplate(Document):
def validate(self): def validate(self):
valdiate_taxes_and_charges_template(self) valdiate_taxes_and_charges_template(self)
def set_missing_values(self):
for data in self.taxes:
if data.charge_type == 'On Net Total' and flt(data.rate) == 0.0:
data.rate = frappe.db.get_value('Account', data.account_head, 'tax_rate')
def valdiate_taxes_and_charges_template(doc): def valdiate_taxes_and_charges_template(doc):
# default should not be disabled # default should not be disabled
# if not doc.is_default and not frappe.get_all(doc.doctype, filters={"is_default": 1}): # if not doc.is_default and not frappe.get_all(doc.doctype, filters={"is_default": 1}):

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe, copy import frappe, copy
import os
import json
from frappe.utils import cstr, flt, getdate from frappe.utils import cstr, flt, getdate
from frappe import _ from frappe import _
from frappe.utils.file_manager import save_file from frappe.utils.file_manager import save_file
@ -22,6 +24,7 @@ def setup_complete(args=None):
create_price_lists(args) create_price_lists(args)
create_fiscal_year_and_company(args) create_fiscal_year_and_company(args)
create_sales_tax(args)
create_users(args) create_users(args)
set_defaults(args) set_defaults(args)
create_territories() create_territories()
@ -66,6 +69,55 @@ def setup_complete(args=None):
pass 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): def create_fiscal_year_and_company(args):
if (args.get('fy_start_date')): if (args.get('fy_start_date')):
curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date')) curr_fiscal_year = get_fy_details(args.get('fy_start_date'), args.get('fy_end_date'))