Browse Source

fix: improved on_update method, added validation for tax calculation, sandbox mode checks

develop
Subin Tom 3 years ago
parent
commit
7114659ecc
  1. 6
      erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json
  2. 28
      erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py

6
erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json

@ -6,8 +6,8 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"is_sandbox",
"taxjar_calculate_tax",
"is_sandbox",
"taxjar_create_transactions",
"credentials",
"api_key",
@ -57,6 +57,7 @@
},
{
"default": "0",
"depends_on": "taxjar_calculate_tax",
"fieldname": "is_sandbox",
"fieldtype": "Check",
"label": "Sandbox Mode"
@ -72,6 +73,7 @@
},
{
"default": "0",
"depends_on": "taxjar_calculate_tax",
"fieldname": "taxjar_create_transactions",
"fieldtype": "Check",
"label": "Create TaxJar Transaction"
@ -106,7 +108,7 @@
],
"issingle": 1,
"links": [],
"modified": "2021-09-16 08:54:48.444487",
"modified": "2021-10-06 10:59:13.475442",
"modified_by": "Administrator",
"module": "ERPNext Integrations",
"name": "TaxJar Settings",

28
erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py

@ -21,15 +21,9 @@ class TaxJarSettings(Document):
TAXJAR_CREATE_TRANSACTIONS = frappe.db.get_single_value("TaxJar Settings", "taxjar_create_transactions")
TAXJAR_CALCULATE_TAX = frappe.db.get_single_value("TaxJar Settings", "taxjar_calculate_tax")
TAXJAR_SANDBOX_MODE = frappe.db.get_single_value("TaxJar Settings", "is_sandbox")
fields_hidden = 0
custom_fields = []
for dt in ['Item', 'Sales Invoice Item']:
doc = frappe.db.exists('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'})
custom_fields.append(doc)
fields_hidden = frappe.db.get_value('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'},'hidden')
fields_already_exist = True if custom_fields else False
fields_already_exist = frappe.db.exists('Custom Field', {'dt': ('in', ['Item','Sales Invoice Item']), 'fieldname':'product_tax_category'})
fields_hidden = frappe.get_value('Custom Field', {'dt': ('in', ['Sales Invoice Item'])}, 'hidden')
if (TAXJAR_CREATE_TRANSACTIONS or TAXJAR_CALCULATE_TAX or TAXJAR_SANDBOX_MODE):
if not fields_already_exist:
@ -39,10 +33,13 @@ class TaxJarSettings(Document):
frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False)
elif fields_already_exist and fields_hidden:
toggle_tax_category_fields(hidden='1')
toggle_tax_category_fields(hidden='0')
elif fields_already_exist:
toggle_tax_category_fields(hidden='1')
else:
toggle_tax_category_fields(hidden='0')
def validate(self):
self.calculate_taxes_validation_for_create_transactions()
@frappe.whitelist()
def update_nexus_list(self):
@ -55,9 +52,14 @@ class TaxJarSettings(Document):
self.set('nexus', new_nexus_list)
self.save()
def calculate_taxes_validation_for_create_transactions(self):
if not self.taxjar_calculate_tax and (self.taxjar_create_transactions or self.is_sandbox):
frappe.throw('Before enabling <b>Create Transaction</b> or <b>Sandbox Mode</b>, you need to check the <b>Enable Tax Calculation</b> box')
def toggle_tax_category_fields(hidden):
frappe.set_value('Custom Field',{'dt':'Sales Invoice Item', 'fieldname':'product_tax_category'},'hidden',hidden)
frappe.set_value('Custom Field',{'dt':'Item', 'fieldname':'product_tax_category'},'hidden',hidden)
frappe.set_value('Custom Field', {'dt':'Sales Invoice Item', 'fieldname':'product_tax_category'}, 'hidden', hidden)
frappe.set_value('Custom Field', {'dt':'Item', 'fieldname':'product_tax_category'}, 'hidden', hidden)
def add_product_tax_categories():

Loading…
Cancel
Save