From b01fe1c3e2db9f1cd39a8a96c3539dbf50d59bf6 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Tue, 14 Sep 2021 20:42:47 +0530 Subject: [PATCH] fix: TaxJar update - nexus, selective api call --- .../doctype/taxjar_nexus_list/__init__.py | 0 .../taxjar_nexus_list/taxjar_nexus_list.json | 51 +++++++++++++++++++ .../taxjar_nexus_list/taxjar_nexus_list.py | 9 ++++ .../taxjar_settings/taxjar_settings.js | 14 ++++- .../taxjar_settings/taxjar_settings.json | 24 ++++++++- .../taxjar_settings/taxjar_settings.py | 16 +++++- .../taxjar_integration.py | 5 ++ 7 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 erpnext/erpnext_integrations/doctype/taxjar_nexus_list/__init__.py create mode 100644 erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json create mode 100644 erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/__init__.py b/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json b/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json new file mode 100644 index 0000000000..d543403ef9 --- /dev/null +++ b/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json @@ -0,0 +1,51 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-09-11 05:09:53.773838", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "region", + "region_code", + "country", + "country_code" + ], + "fields": [ + { + "fieldname": "region", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Region" + }, + { + "fieldname": "region_code", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Region Code" + }, + { + "fieldname": "country", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Country" + }, + { + "fieldname": "country_code", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Country Code" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-09-14 05:33:06.444710", + "modified_by": "Administrator", + "module": "ERPNext Integrations", + "name": "TaxJar Nexus List", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py b/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py new file mode 100644 index 0000000000..b93be5190f --- /dev/null +++ b/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py @@ -0,0 +1,9 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class TaxJarNexusList(Document): + pass diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js index 62d5709f51..b6a05c42ef 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js @@ -5,5 +5,17 @@ frappe.ui.form.on('TaxJar Settings', { is_sandbox: (frm) => { frm.toggle_reqd("api_key", !frm.doc.is_sandbox); frm.toggle_reqd("sandbox_api_key", frm.doc.is_sandbox); - } + }, + + refresh: (frm) => { + + frm.add_custom_button(__('Update Nexus List'), function(){ + frm.call({ + doc: frm.doc, + method: 'update_nexus_list' + }); + }); + }, + + }); diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json index c0d60f7a31..da8e77f783 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json @@ -16,7 +16,10 @@ "configuration", "tax_account_head", "configuration_cb", - "shipping_account_head" + "shipping_account_head", + "section_break_12", + "nexus_address", + "nexus" ], "fields": [ { @@ -82,11 +85,28 @@ { "fieldname": "cb_keys", "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_12", + "fieldtype": "Section Break", + "label": "Nexus List" + }, + { + "fieldname": "nexus_address", + "fieldtype": "HTML", + "label": "Nexus Address" + }, + { + "fieldname": "nexus", + "fieldtype": "Table", + "label": "Nexus", + "options": "TaxJar Nexus List", + "read_only": 1 } ], "issingle": 1, "links": [], - "modified": "2020-04-30 04:38:03.311089", + "modified": "2021-09-14 01:41:55.871028", "modified_by": "Administrator", "module": "ERPNext Integrations", "name": "TaxJar Settings", diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index 9dd481747e..767e8f24f3 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -4,9 +4,21 @@ from __future__ import unicode_literals -# import frappe +import frappe from frappe.model.document import Document +from erpnext.erpnext_integrations.taxjar_integration import get_client + class TaxJarSettings(Document): - pass + + @frappe.whitelist() + def update_nexus_list(self): + client = get_client() + nexus = client.nexus_regions() + + new_nexus_list = [frappe._dict(address) for address in nexus] + + self.set('nexus',[]) + self.set('nexus',new_nexus_list) + self.save() \ No newline at end of file diff --git a/erpnext/erpnext_integrations/taxjar_integration.py b/erpnext/erpnext_integrations/taxjar_integration.py index 870a4ef54c..eb46d245f8 100644 --- a/erpnext/erpnext_integrations/taxjar_integration.py +++ b/erpnext/erpnext_integrations/taxjar_integration.py @@ -164,6 +164,11 @@ def set_sales_tax(doc, method): setattr(doc, "taxes", [tax for tax in doc.taxes if tax.account_head != TAX_ACCOUNT_HEAD]) return + # check if delivering within a nexus + nexus_list = frappe.get_doc('TaxJar Settings').get("nexus") + if tax_dict["to_state"] not in [nex.region_code for nex in nexus_list]: + return + tax_data = validate_tax_request(tax_dict) if tax_data is not None: if not tax_data.amount_to_collect: