Skip to content

Commit

Permalink
fix: dynamic tax rate for default tax template in setup wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 committed Dec 14, 2023
1 parent 46bc6ec commit 17a2e12
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
33 changes: 30 additions & 3 deletions india_compliance/gst_india/overrides/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def make_company_fixtures(doc, method=None):


def create_company_fixtures(company):
make_default_tax_templates(company)
if not frappe.flags.in_setup_wizard:
# Manual Trigger in Setup Wizard with custom rate
make_default_tax_templates(company)

make_default_customs_accounts(company)
make_default_gst_expense_accounts(company)

Expand Down Expand Up @@ -57,14 +60,38 @@ def make_default_gst_expense_accounts(company):


@frappe.whitelist()
def make_default_tax_templates(company: str):
def make_default_tax_templates(company: str, tax_rate=18):
frappe.has_permission("Company", ptype="write", doc=company, throw=True)

default_taxes = frappe.get_file_json(get_data_file_path("tax_defaults.json"))
default_taxes = get_tax_defaults(tax_rate)
from_detailed_data(company, default_taxes)
update_gst_settings(company)


def get_tax_defaults(tax_rate):
tax_rate = int(tax_rate)
default_taxes = frappe.get_file_json(get_data_file_path("tax_defaults.json"))
if tax_rate == 18:
return default_taxes

return modify_tax_defaults(default_taxes, tax_rate)


def modify_tax_defaults(default_taxes, tax_rate):
# Identifying new_rate based on existing rate
for template_type in ("sales_tax_templates", "purchase_tax_templates"):
template = default_taxes["chart_of_accounts"]["*"][template_type]
for tax in template:
for row in tax.get("taxes"):
rate = (
tax_rate if row["account_head"]["tax_rate"] == 18 else tax_rate / 2
)

row["account_head"]["tax_rate"] = rate

return default_taxes


def update_gst_settings(company):
# Will only add default GST accounts if present
input_account_names = ["Input Tax CGST", "Input Tax SGST", "Input Tax IGST"]
Expand Down
8 changes: 8 additions & 0 deletions india_compliance/public/js/setup_wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ function update_erpnext_slides_settings() {

slide.fields.splice(_index, 0, company_gstin_field);

slide.fields.splice(4, 0, {
fieldname: "default_gst_rate",
fieldtype: "Select",
label: __("Default GST Rate(%)"),
options: [5, 12, 18, 28],
default: 18,
});

slide.fields.push({
fieldname: "enable_audit_trail",
fieldtype: "Check",
Expand Down
19 changes: 19 additions & 0 deletions india_compliance/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from frappe import _

from india_compliance.audit_trail.utils import enable_audit_trail
from india_compliance.gst_india.overrides.company import make_default_tax_templates
from india_compliance.gst_india.overrides.party import validate_pan
from india_compliance.gst_india.utils import guess_gst_category, is_api_enabled
from india_compliance.gst_india.utils.gstin_info import get_gstin_info
Expand Down Expand Up @@ -36,6 +37,17 @@ def get_setup_wizard_stages(params=None):
}
],
},
{
"status": _("Wrapping up"),
"fail_msg": _("Failed to Create Tax Template"),
"tasks": [
{
"fn": setup_tax_template,
"args": params,
"fail_msg": _("Failed to Create Tax Template"),
}
],
},
]

return stages
Expand Down Expand Up @@ -96,3 +108,10 @@ def can_fetch_gstin_info():
return is_api_enabled() and not frappe.get_cached_value(
"GST Settings", None, "sandbox_mode"
)


def setup_tax_template(params):
if not (params.company_name and frappe.db.exists("Company", params.company_name)):
return

make_default_tax_templates(params.company_name, int(params.default_gst_rate))

0 comments on commit 17a2e12

Please sign in to comment.