From 4abceddacc71c3fe3cca34803ed1add00748abb8 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Tue, 14 Sep 2021 20:42:47 +0530 Subject: [PATCH 01/24] fix: TaxJar update - nexus, selective api call (cherry picked from commit b01fe1c3e2db9f1cd39a8a96c3539dbf50d59bf6) --- .../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 000000000000..e69de29bb2d1 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 000000000000..d543403ef9b3 --- /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 000000000000..b93be5190fd7 --- /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 62d5709f51f4..b6a05c42efb0 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 c0d60f7a317b..da8e77f78339 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 9dd481747ec7..767e8f24f3f7 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 870a4ef54cc4..eb46d245f828 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: From 52df24cfecfdb97306dc0a9d7f2ef0a4d7e7763d Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Tue, 14 Sep 2021 22:04:57 +0530 Subject: [PATCH 02/24] fix: sales_tax attribute in api call before submit (cherry picked from commit 3bb60a439a54350765d82c017bfa061cf41004e0) --- erpnext/erpnext_integrations/taxjar_integration.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/erpnext_integrations/taxjar_integration.py b/erpnext/erpnext_integrations/taxjar_integration.py index eb46d245f828..29fd81cab739 100644 --- a/erpnext/erpnext_integrations/taxjar_integration.py +++ b/erpnext/erpnext_integrations/taxjar_integration.py @@ -103,7 +103,7 @@ def get_tax_data(doc): shipping = sum([tax.tax_amount for tax in doc.taxes if tax.account_head == SHIP_ACCOUNT_HEAD]) - line_items = [get_line_item_dict(item) for item in doc.items] + line_items = [get_line_item_dict(item,doc.docstatus) for item in doc.items] if from_shipping_state not in SUPPORTED_STATE_CODES: from_shipping_state = get_state_code(from_address, 'Company') @@ -139,14 +139,21 @@ def get_state_code(address, location): return state_code -def get_line_item_dict(item): - return dict( +def get_line_item_dict(item, docstatus): + tax_dict = dict( id = item.get('idx'), quantity = item.get('qty'), unit_price = item.get('rate'), product_tax_code = item.get('product_tax_category') ) + if docstatus == 1: + tax_dict.update({ + 'sales_tax':item.get('tax_collectable') + }) + + return tax_dict + def set_sales_tax(doc, method): if not TAXJAR_CALCULATE_TAX: return From 0481678095f32c3a90c443a7a9a0ee50fa3fe886 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Thu, 16 Sep 2021 14:41:38 +0530 Subject: [PATCH 03/24] Update erpnext/erpnext_integrations/taxjar_integration.py Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> (cherry picked from commit 0e527311b959fcb0d980ebebff671c75ca997f28) --- erpnext/erpnext_integrations/taxjar_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/erpnext_integrations/taxjar_integration.py b/erpnext/erpnext_integrations/taxjar_integration.py index 29fd81cab739..90ee8a8d9aff 100644 --- a/erpnext/erpnext_integrations/taxjar_integration.py +++ b/erpnext/erpnext_integrations/taxjar_integration.py @@ -103,7 +103,7 @@ def get_tax_data(doc): shipping = sum([tax.tax_amount for tax in doc.taxes if tax.account_head == SHIP_ACCOUNT_HEAD]) - line_items = [get_line_item_dict(item,doc.docstatus) for item in doc.items] + line_items = [get_line_item_dict(item, doc.docstatus) for item in doc.items] if from_shipping_state not in SUPPORTED_STATE_CODES: from_shipping_state = get_state_code(from_address, 'Company') From 78c5b875459f2776f956359948a974158abd56a6 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Thu, 16 Sep 2021 14:41:48 +0530 Subject: [PATCH 04/24] Update erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> (cherry picked from commit 486d7c3a39fb77f23de49d650b91c05758c7fbd7) --- .../doctype/taxjar_settings/taxjar_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index 767e8f24f3f7..c6d714b09701 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -19,6 +19,6 @@ def update_nexus_list(self): new_nexus_list = [frappe._dict(address) for address in nexus] - self.set('nexus',[]) - self.set('nexus',new_nexus_list) + self.set('nexus', []) + self.set('nexus', new_nexus_list) self.save() \ No newline at end of file From 50216a991c9d8d3b4eb914278626f47afc875365 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Thu, 16 Sep 2021 14:42:06 +0530 Subject: [PATCH 05/24] Update erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> (cherry picked from commit 435a5e4fa318801c7b6e0f84c37a5894ed4c2043) --- .../doctype/taxjar_settings/taxjar_settings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js index b6a05c42efb0..d49598932fef 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.js @@ -8,8 +8,7 @@ frappe.ui.form.on('TaxJar Settings', { }, refresh: (frm) => { - - frm.add_custom_button(__('Update Nexus List'), function(){ + frm.add_custom_button(__('Update Nexus List'), function() { frm.call({ doc: frm.doc, method: 'update_nexus_list' From 91b11f63a6581300b20847b3c0fa86c64908b003 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Thu, 16 Sep 2021 14:42:15 +0530 Subject: [PATCH 06/24] Update erpnext/erpnext_integrations/taxjar_integration.py Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> (cherry picked from commit 11bd42467e5346c1d286c2fd9ec4b1d032b32d85) --- erpnext/erpnext_integrations/taxjar_integration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/erpnext_integrations/taxjar_integration.py b/erpnext/erpnext_integrations/taxjar_integration.py index 90ee8a8d9aff..bd09557f78ed 100644 --- a/erpnext/erpnext_integrations/taxjar_integration.py +++ b/erpnext/erpnext_integrations/taxjar_integration.py @@ -172,8 +172,7 @@ def set_sales_tax(doc, method): 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]: + if not frappe.db.get_value('TaxJar Nexus List', {'region_code': tax_dict["to_state"]}) return tax_data = validate_tax_request(tax_dict) From d5c32be2225c01d71dd65f5c43e7b2522943d262 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Fri, 17 Sep 2021 00:10:41 +0530 Subject: [PATCH 07/24] fix: Renamed child table doctype, delete taxes for non nexus state (cherry picked from commit 5c18654113d58363aa52dde30be3b65621747363) --- .../__init__.py | 0 .../taxjar_nexus.json} | 2 +- .../taxjar_nexus.py} | 2 +- .../doctype/taxjar_settings/taxjar_settings.json | 4 ++-- .../erpnext_integrations/taxjar_integration.py | 16 +++++++++++++--- 5 files changed, 17 insertions(+), 7 deletions(-) rename erpnext/erpnext_integrations/doctype/{taxjar_nexus_list => taxjar_nexus}/__init__.py (100%) rename erpnext/erpnext_integrations/doctype/{taxjar_nexus_list/taxjar_nexus_list.json => taxjar_nexus/taxjar_nexus.json} (96%) rename erpnext/erpnext_integrations/doctype/{taxjar_nexus_list/taxjar_nexus_list.py => taxjar_nexus/taxjar_nexus.py} (85%) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/__init__.py b/erpnext/erpnext_integrations/doctype/taxjar_nexus/__init__.py similarity index 100% rename from erpnext/erpnext_integrations/doctype/taxjar_nexus_list/__init__.py rename to erpnext/erpnext_integrations/doctype/taxjar_nexus/__init__.py diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json b/erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.json similarity index 96% rename from erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json rename to erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.json index d543403ef9b3..d4d4a512b580 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.json +++ b/erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.json @@ -42,7 +42,7 @@ "modified": "2021-09-14 05:33:06.444710", "modified_by": "Administrator", "module": "ERPNext Integrations", - "name": "TaxJar Nexus List", + "name": "TaxJar Nexus", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py b/erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.py similarity index 85% rename from erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py rename to erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.py index b93be5190fd7..c24aa8ca7d44 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_nexus_list/taxjar_nexus_list.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_nexus/taxjar_nexus.py @@ -5,5 +5,5 @@ from frappe.model.document import Document -class TaxJarNexusList(Document): +class TaxJarNexus(Document): pass diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json index da8e77f78339..ccbac2c18a74 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json @@ -100,13 +100,13 @@ "fieldname": "nexus", "fieldtype": "Table", "label": "Nexus", - "options": "TaxJar Nexus List", + "options": "TaxJar Nexus", "read_only": 1 } ], "issingle": 1, "links": [], - "modified": "2021-09-14 01:41:55.871028", + "modified": "2021-09-16 08:54:48.444487", "modified_by": "Administrator", "module": "ERPNext Integrations", "name": "TaxJar Settings", diff --git a/erpnext/erpnext_integrations/taxjar_integration.py b/erpnext/erpnext_integrations/taxjar_integration.py index bd09557f78ed..2a7243c2430e 100644 --- a/erpnext/erpnext_integrations/taxjar_integration.py +++ b/erpnext/erpnext_integrations/taxjar_integration.py @@ -4,7 +4,7 @@ import taxjar from frappe import _ from frappe.contacts.doctype.address.address import get_company_address -from frappe.utils import cint +from frappe.utils import cint, flt from erpnext import get_default_company @@ -172,8 +172,7 @@ def set_sales_tax(doc, method): return # check if delivering within a nexus - if not frappe.db.get_value('TaxJar Nexus List', {'region_code': tax_dict["to_state"]}) - return + check_for_nexus(doc, tax_dict) tax_data = validate_tax_request(tax_dict) if tax_data is not None: @@ -202,6 +201,17 @@ def set_sales_tax(doc, method): doc.run_method("calculate_taxes_and_totals") +def check_for_nexus(doc, tax_dict): + if not frappe.db.get_value('TaxJar Nexus', {'region_code': tax_dict["to_state"]}): + for item in doc.get("items"): + item.tax_collectable = flt(0) + item.taxable_amount = flt(0) + + for tax in doc.taxes: + if tax.account_head == TAX_ACCOUNT_HEAD: + doc.taxes.remove(tax) + return + def check_sales_tax_exemption(doc): # if the party is exempt from sales tax, then set all tax account heads to zero sales_tax_exempted = hasattr(doc, "exempt_from_sales_tax") and doc.exempt_from_sales_tax \ From 71e6ffd96e4ff82bddd4f6d65342f8154d3c755b Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Mon, 27 Sep 2021 12:51:54 +0530 Subject: [PATCH 08/24] fix: updated patch, add fields only if fields are checked (cherry picked from commit 54754f4eb8a615d92d52d1322dad41ccfe9e8556) # Conflicts: # erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py --- .../taxjar_settings/taxjar_settings.py | 58 ++++++++++++++++++- .../custom_fields_for_taxjar_integration.py | 14 ++++- erpnext/regional/united_states/setup.py | 40 ------------- 3 files changed, 68 insertions(+), 44 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index c6d714b09701..2ee3350e0381 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -4,14 +4,30 @@ from __future__ import unicode_literals +import json +import os + import frappe +from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.model.document import Document +from frappe.permissions import add_permission, update_permission_property from erpnext.erpnext_integrations.taxjar_integration import get_client class TaxJarSettings(Document): + def on_update(self): + 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") + + if TAXJAR_CREATE_TRANSACTIONS or TAXJAR_CALCULATE_TAX or TAXJAR_SANDBOX_MODE: + add_product_tax_categories() + make_custom_fields() + add_permissions() + frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False) + @frappe.whitelist() def update_nexus_list(self): client = get_client() @@ -21,4 +37,44 @@ def update_nexus_list(self): self.set('nexus', []) self.set('nexus', new_nexus_list) - self.save() \ No newline at end of file + self.save() + +def add_product_tax_categories(): + with open(os.path.join(os.path.dirname(__file__), 'product_tax_category_data.json'), 'r') as f: + tax_categories = json.loads(f.read()) + create_tax_categories(tax_categories['categories']) + +def create_tax_categories(data): + for d in data: + tax_category = frappe.new_doc('Product Tax Category') + tax_category.description = d.get("description") + tax_category.product_tax_code = d.get("product_tax_code") + tax_category.category_name = d.get("name") + try: + tax_category.db_insert() + except frappe.DuplicateEntryError: + pass + +def make_custom_fields(update=True): + custom_fields = { + 'Sales Invoice Item': [ + dict(fieldname='product_tax_category', fieldtype='Link', insert_after='description', options='Product Tax Category', + label='Product Tax Category', fetch_from='item_code.product_tax_category'), + dict(fieldname='tax_collectable', fieldtype='Currency', insert_after='net_amount', + label='Tax Collectable', read_only=1), + dict(fieldname='taxable_amount', fieldtype='Currency', insert_after='tax_collectable', + label='Taxable Amount', read_only=1) + ], + 'Item': [ + dict(fieldname='product_tax_category', fieldtype='Link', insert_after='item_group', options='Product Tax Category', + label='Product Tax Category') + ] + } + create_custom_fields(custom_fields, update=update) + +def add_permissions(): + doctype = "Product Tax Category" + for role in ('Accounts Manager', 'Accounts User', 'System Manager','Item Manager', 'Stock Manager'): + add_permission(doctype, role, 0) + update_permission_property(doctype, role, 0, 'write', 1) + update_permission_property(doctype, role, 0, 'create', 1) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 43a9aeb6fe64..29c7f08f437a 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -3,12 +3,16 @@ import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields -from erpnext.regional.united_states.setup import add_permissions +from erpnext.erpnext_integrations.doctype.taxjar_settings.taxjar_settings import add_permissions def execute(): + 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") company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name']) - if not company: + + if not company or (not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE): return frappe.reload_doc("regional", "doctype", "product_tax_category") @@ -29,4 +33,8 @@ def execute(): } create_custom_fields(custom_fields, update=True) add_permissions() - frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=True) \ No newline at end of file +<<<<<<< HEAD + frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=True) +======= + frappe.enqueue('erpnext.erpnext_integrations.doctype.taxjar_settings.taxjar_settings.add_product_tax_categories', now=True) +>>>>>>> 54754f4eb8 (fix: updated patch, add fields only if fields are checked) diff --git a/erpnext/regional/united_states/setup.py b/erpnext/regional/united_states/setup.py index 25982b81227e..f7b921a491bf 100644 --- a/erpnext/regional/united_states/setup.py +++ b/erpnext/regional/united_states/setup.py @@ -16,30 +16,9 @@ def setup(company=None, patch=True): setup_company_independent_fixtures(patch=patch) def setup_company_independent_fixtures(company=None, patch=True): - add_product_tax_categories() make_custom_fields() - add_permissions() - frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False) add_print_formats() -# Product Tax categories imported from taxjar api -def add_product_tax_categories(): - with open(os.path.join(os.path.dirname(__file__), 'product_tax_category_data.json'), 'r') as f: - tax_categories = json.loads(f.read()) - create_tax_categories(tax_categories['categories']) - -def create_tax_categories(data): - for d in data: - tax_category = frappe.new_doc('Product Tax Category') - tax_category.description = d.get("description") - tax_category.product_tax_code = d.get("product_tax_code") - tax_category.category_name = d.get("name") - try: - tax_category.db_insert() - except frappe.DuplicateEntryError: - pass - - def make_custom_fields(update=True): custom_fields = { 'Supplier': [ @@ -61,29 +40,10 @@ def make_custom_fields(update=True): 'Quotation': [ dict(fieldname='exempt_from_sales_tax', fieldtype='Check', insert_after='taxes_and_charges', label='Is customer exempted from sales tax?') - ], - 'Sales Invoice Item': [ - dict(fieldname='product_tax_category', fieldtype='Link', insert_after='description', options='Product Tax Category', - label='Product Tax Category', fetch_from='item_code.product_tax_category'), - dict(fieldname='tax_collectable', fieldtype='Currency', insert_after='net_amount', - label='Tax Collectable', read_only=1), - dict(fieldname='taxable_amount', fieldtype='Currency', insert_after='tax_collectable', - label='Taxable Amount', read_only=1) - ], - 'Item': [ - dict(fieldname='product_tax_category', fieldtype='Link', insert_after='item_group', options='Product Tax Category', - label='Product Tax Category') ] } create_custom_fields(custom_fields, update=update) -def add_permissions(): - doctype = "Product Tax Category" - for role in ('Accounts Manager', 'Accounts User', 'System Manager','Item Manager', 'Stock Manager'): - add_permission(doctype, role, 0) - update_permission_property(doctype, role, 0, 'write', 1) - update_permission_property(doctype, role, 0, 'create', 1) - def add_print_formats(): frappe.reload_doc("regional", "print_format", "irs_1099_form") frappe.db.set_value("Print Format", "IRS 1099 Form", "disabled", 0) From c7c07f081b1699f18497df097aad6be3a23fc732 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Tue, 28 Sep 2021 13:54:01 +0530 Subject: [PATCH 09/24] fix: patch fix, fields disabling (cherry picked from commit 0a28fed679a6ce22a9d88d45ca3f05ea7cdb68d9) --- .../taxjar_settings/taxjar_settings.py | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index 2ee3350e0381..408278342bd5 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -21,12 +21,28 @@ def on_update(self): 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 - if TAXJAR_CREATE_TRANSACTIONS or TAXJAR_CALCULATE_TAX or TAXJAR_SANDBOX_MODE: - add_product_tax_categories() - make_custom_fields() - add_permissions() - frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False) + custom_fields = [] + for dt in ['Item', 'Sales Invoice Item']: + doc = frappe.get_doc('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'}) + custom_fields.append(doc) + fields_hidden = doc.get('hidden') if doc else 0 + fields_already_exist = True if custom_fields else False + + + if (TAXJAR_CREATE_TRANSACTIONS or TAXJAR_CALCULATE_TAX or TAXJAR_SANDBOX_MODE): + if not fields_already_exist: + add_product_tax_categories() + make_custom_fields() + add_permissions() + frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False) + + elif fields_already_exist and fields_hidden: + toggle_tax_category_fields('1') + + elif not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE: + toggle_tax_category_fields('0') @frappe.whitelist() def update_nexus_list(self): @@ -39,6 +55,11 @@ def update_nexus_list(self): self.set('nexus', new_nexus_list) self.save() +def toggle_tax_category_fields(toggle): + frappe.set_value('Custom Field',{'document':'Sales Invoice Item', 'fieldname':'product_tax_category'},'hidden',toggle) + frappe.set_value('Custom Field',{'document':'Item', 'fieldname':'product_tax_category'},'hidden',toggle) + + def add_product_tax_categories(): with open(os.path.join(os.path.dirname(__file__), 'product_tax_category_data.json'), 'r') as f: tax_categories = json.loads(f.read()) From 81e5ab5c511f3e393afe99daa541945a115fb865 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Wed, 29 Sep 2021 11:11:55 +0530 Subject: [PATCH 10/24] fix: using db.exists and get_value instead of get_doc (cherry picked from commit 8675ca5bdd838460d56be8eadf6790cadc605ba3) --- .../doctype/taxjar_settings/taxjar_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index 408278342bd5..dd83c174aa96 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -25,9 +25,9 @@ def on_update(self): custom_fields = [] for dt in ['Item', 'Sales Invoice Item']: - doc = frappe.get_doc('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'}) + doc = frappe.db.exists('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'}) custom_fields.append(doc) - fields_hidden = doc.get('hidden') if doc else 0 + fields_hidden = frappe.db.get_value('Custom Field', {'dt': dt, 'fieldname':'product_tax_category'},'hidden') fields_already_exist = True if custom_fields else False From 7b846cea04c0a7d10a0c4c6219bdd33c969c702f Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Wed, 29 Sep 2021 11:26:04 +0530 Subject: [PATCH 11/24] fix: dt instead of document in set_value query (cherry picked from commit d3bb920e715a49ee47e52eef1b53d40dc573d877) --- .../doctype/taxjar_settings/taxjar_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index dd83c174aa96..e03a2ac51319 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -56,8 +56,8 @@ def update_nexus_list(self): self.save() def toggle_tax_category_fields(toggle): - frappe.set_value('Custom Field',{'document':'Sales Invoice Item', 'fieldname':'product_tax_category'},'hidden',toggle) - frappe.set_value('Custom Field',{'document':'Item', 'fieldname':'product_tax_category'},'hidden',toggle) + frappe.set_value('Custom Field',{'dt':'Sales Invoice Item', 'fieldname':'product_tax_category'},'hidden',toggle) + frappe.set_value('Custom Field',{'dt':'Item', 'fieldname':'product_tax_category'},'hidden',toggle) def add_product_tax_categories(): From 1c36329ab4ad1b5bdfb6fb89ee887a8a0be8e93c Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Wed, 29 Sep 2021 13:34:50 +0530 Subject: [PATCH 12/24] minor fixes (cherry picked from commit 254b20bc093805a6642e6ddedcd8917a535d42b1) --- .../taxjar_settings/taxjar_settings.py | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index e03a2ac51319..725a61a3963b 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -39,10 +39,10 @@ def on_update(self): frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=False) elif fields_already_exist and fields_hidden: - toggle_tax_category_fields('1') + toggle_tax_category_fields(hidden='1') - elif not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE: - toggle_tax_category_fields('0') + else: + toggle_tax_category_fields(hidden='0') @frappe.whitelist() def update_nexus_list(self): @@ -55,9 +55,9 @@ def update_nexus_list(self): self.set('nexus', new_nexus_list) self.save() -def toggle_tax_category_fields(toggle): - frappe.set_value('Custom Field',{'dt':'Sales Invoice Item', 'fieldname':'product_tax_category'},'hidden',toggle) - frappe.set_value('Custom Field',{'dt':'Item', 'fieldname':'product_tax_category'},'hidden',toggle) +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) def add_product_tax_categories(): @@ -67,14 +67,12 @@ def add_product_tax_categories(): def create_tax_categories(data): for d in data: - tax_category = frappe.new_doc('Product Tax Category') - tax_category.description = d.get("description") - tax_category.product_tax_code = d.get("product_tax_code") - tax_category.category_name = d.get("name") - try: + if not frappe.db.exists('Product Tax Category',{'product_tax_code':d.get('product_tax_code')}): + tax_category = frappe.new_doc('Product Tax Category') + tax_category.description = d.get("description") + tax_category.product_tax_code = d.get("product_tax_code") + tax_category.category_name = d.get("name") tax_category.db_insert() - except frappe.DuplicateEntryError: - pass def make_custom_fields(update=True): custom_fields = { From 6198687c8ae01c570fa92c25ed1a24cfc8de0993 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Wed, 6 Oct 2021 21:31:19 +0530 Subject: [PATCH 13/24] fix: improved on_update method, added validation for tax calculation, sandbox mode checks (cherry picked from commit 7114659eccfa13c50ba6ce8d7fb2ad74838169d5) --- .../taxjar_settings/taxjar_settings.json | 6 ++-- .../taxjar_settings/taxjar_settings.py | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json index ccbac2c18a74..2d17f2ed8321 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.json +++ b/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", diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index 725a61a3963b..d11655230995 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -21,15 +21,9 @@ def on_update(self): 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 @@ def on_update(self): 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 @@ def update_nexus_list(self): 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 Create Transaction or Sandbox Mode, you need to check the Enable Tax Calculation 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(): From 35d56c44ecd9ceba148bb3e9808e2e0b319da055 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Wed, 6 Oct 2021 21:35:04 +0530 Subject: [PATCH 14/24] fix: linters fix (cherry picked from commit 3ece05a9f7976a031efcb441defa77d51c351145) --- .../doctype/taxjar_settings/taxjar_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py index d11655230995..f430a9e9baef 100644 --- a/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py +++ b/erpnext/erpnext_integrations/doctype/taxjar_settings/taxjar_settings.py @@ -54,7 +54,7 @@ def update_nexus_list(self): 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 Create Transaction or Sandbox Mode, you need to check the Enable Tax Calculation box') + frappe.throw(frappe._('Before enabling Create Transaction or Sandbox Mode, you need to check the Enable Tax Calculation box')) def toggle_tax_category_fields(hidden): From d8a38e6c47de1d8f984260faaf9ba8b53d3fb3d4 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Thu, 7 Oct 2021 12:20:56 +0530 Subject: [PATCH 15/24] fix: patch fix added reload_doctype (cherry picked from commit eaa3614155838df0ddcdb11f3154a9cb94f86b11) --- .../patches/v13_0/custom_fields_for_taxjar_integration.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 29c7f08f437a..7bbc15be8038 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -7,6 +7,9 @@ def execute(): + + frappe.reload_doctype("Taxjar Settings") + 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") @@ -15,7 +18,7 @@ def execute(): if not company or (not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE): return - frappe.reload_doc("regional", "doctype", "product_tax_category") + frappe.reload_doctype("Product Tax Category") custom_fields = { 'Sales Invoice Item': [ From ebd5a00fbbfbe695667fc77ccd618cbc6895532a Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Mon, 11 Oct 2021 10:20:23 +0530 Subject: [PATCH 16/24] fix: patch fixes- force reload doc, check for company (cherry picked from commit 1b25e69af4f4069c5e8df713bc852aee06b8acb8) --- .../v13_0/custom_fields_for_taxjar_integration.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 7bbc15be8038..efa57cce1519 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -8,14 +8,17 @@ def execute(): - frappe.reload_doctype("Taxjar Settings") + company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name']) + if not company: + return + + frappe.reload_doctype("Taxjar Settings", force=True) 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") - company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name']) - if not company or (not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE): + if (not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE): return frappe.reload_doctype("Product Tax Category") From 036b653aa0d433b6f5d2aed8d9ef305f963d5491 Mon Sep 17 00:00:00 2001 From: Subin Tom Date: Mon, 11 Oct 2021 11:11:01 +0530 Subject: [PATCH 17/24] fix: 'Taxjar' type fix (cherry picked from commit ea2038489fd6b225154eb0d11bf9ce5eb5983e14) --- erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index efa57cce1519..fbca66070cef 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -12,7 +12,7 @@ def execute(): if not company: return - frappe.reload_doctype("Taxjar Settings", force=True) + frappe.reload_doctype("TaxJar Settings", force=True) 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") From 557dc5eed51a70d2446912fce3475eaaf577439f Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Tue, 12 Oct 2021 13:04:25 +0530 Subject: [PATCH 18/24] fix: Update pacthes.txt (cherry picked from commit 5d4c919c5ce8ce0c112e368fb94b1fb862ea3c78) --- .../patches/v13_0/custom_fields_for_taxjar_integration.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index fbca66070cef..9c63fdd2d96b 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -7,13 +7,14 @@ def execute(): + frappe.reload_doctype("TaxJar Settings", force=True) + frappe.reload_doctype("Product Tax Category", force=True) company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name']) if not company: return - frappe.reload_doctype("TaxJar Settings", force=True) - + 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") @@ -21,8 +22,6 @@ def execute(): if (not TAXJAR_CREATE_TRANSACTIONS and not TAXJAR_CALCULATE_TAX and not TAXJAR_SANDBOX_MODE): return - frappe.reload_doctype("Product Tax Category") - custom_fields = { 'Sales Invoice Item': [ dict(fieldname='product_tax_category', fieldtype='Link', insert_after='description', options='Product Tax Category', From 7af724b36ae301bdb821ae25a42a7a9e003b7631 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 13 Oct 2021 13:24:19 +0530 Subject: [PATCH 19/24] fix: Patch (cherry picked from commit 2d19e2d54b3d03f70996ac104508a14b21bc2911) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 6 ++++++ .../patches/v13_0/custom_fields_for_taxjar_integration.py | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 42aa8c62ef3a..2d2d617365d9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -306,6 +306,12 @@ erpnext.patches.v13_0.add_custom_field_for_south_africa #2 erpnext.patches.v13_0.rename_discharge_ordered_date_in_ip_record erpnext.patches.v13_0.migrate_stripe_api erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries +<<<<<<< HEAD +======= +erpnext.patches.v13_0.einvoicing_deprecation_warning +execute:frappe.reload_doc("erpnext_integrations", "doctype", "TaxJar Settings") +execute:frappe.reload_doc("erpnext_integrations", "doctype", "Product Tax Category") +>>>>>>> 2d19e2d54b (fix: Patch) erpnext.patches.v13_0.custom_fields_for_taxjar_integration erpnext.patches.v13_0.set_operation_time_based_on_operating_cost erpnext.patches.v13_0.validate_options_for_data_field diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 9c63fdd2d96b..035c17ca8ffa 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -7,14 +7,10 @@ def execute(): - frappe.reload_doctype("TaxJar Settings", force=True) - frappe.reload_doctype("Product Tax Category", force=True) - company = frappe.get_all('Company', filters = {'country': 'United States'}, fields=['name']) if not company: return - 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") From 67adfb8ccfac81d327ebb4afa1f30e119a1ef07f Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 13 Oct 2021 13:40:53 +0530 Subject: [PATCH 20/24] fix: Move product tax category folder to taxjar settings (cherry picked from commit bd8cfb2e3079012f4e9c0732f3d14db93917bd31) --- .../doctype/taxjar_settings}/product_tax_category_data.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename erpnext/{regional/united_states => erpnext_integrations/doctype/taxjar_settings}/product_tax_category_data.json (100%) diff --git a/erpnext/regional/united_states/product_tax_category_data.json b/erpnext/erpnext_integrations/doctype/taxjar_settings/product_tax_category_data.json similarity index 100% rename from erpnext/regional/united_states/product_tax_category_data.json rename to erpnext/erpnext_integrations/doctype/taxjar_settings/product_tax_category_data.json From c578406ef7f393054c6b45eab25477552293ccbf Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Thu, 14 Oct 2021 13:15:39 +0530 Subject: [PATCH 21/24] Update custom_fields_for_taxjar_integration.py --- .../patches/v13_0/custom_fields_for_taxjar_integration.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 035c17ca8ffa..4f7a88aaa112 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -34,8 +34,5 @@ def execute(): } create_custom_fields(custom_fields, update=True) add_permissions() -<<<<<<< HEAD - frappe.enqueue('erpnext.regional.united_states.setup.add_product_tax_categories', now=True) -======= + frappe.enqueue('erpnext.erpnext_integrations.doctype.taxjar_settings.taxjar_settings.add_product_tax_categories', now=True) ->>>>>>> 54754f4eb8 (fix: updated patch, add fields only if fields are checked) From 4d27dba4e91ee89f4b7ef0c498f8809361469e3a Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Tue, 19 Oct 2021 11:41:29 +0530 Subject: [PATCH 22/24] fix: conflicts --- erpnext/patches.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 648fc3cffbd7..e21b7c09b216 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -306,12 +306,9 @@ erpnext.patches.v13_0.add_custom_field_for_south_africa #2 erpnext.patches.v13_0.rename_discharge_ordered_date_in_ip_record erpnext.patches.v13_0.migrate_stripe_api erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries -<<<<<<< HEAD -======= erpnext.patches.v13_0.einvoicing_deprecation_warning execute:frappe.reload_doc("erpnext_integrations", "doctype", "TaxJar Settings") execute:frappe.reload_doc("erpnext_integrations", "doctype", "Product Tax Category") ->>>>>>> 2d19e2d54b (fix: Patch) erpnext.patches.v13_0.custom_fields_for_taxjar_integration erpnext.patches.v13_0.set_operation_time_based_on_operating_cost erpnext.patches.v13_0.validate_options_for_data_field From c4663e933327f9eb109dc1f69893ea6daf6d4c62 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Tue, 19 Oct 2021 12:48:31 +0530 Subject: [PATCH 23/24] fix: linter issues removed extra line --- erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py index 4f7a88aaa112..e136d64bb56e 100644 --- a/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py +++ b/erpnext/patches/v13_0/custom_fields_for_taxjar_integration.py @@ -34,5 +34,4 @@ def execute(): } create_custom_fields(custom_fields, update=True) add_permissions() - frappe.enqueue('erpnext.erpnext_integrations.doctype.taxjar_settings.taxjar_settings.add_product_tax_categories', now=True) From 227477804dff629238f7e8c48711d6e05d73d8f4 Mon Sep 17 00:00:00 2001 From: Subin Tom <36098155+nemesis189@users.noreply.github.com> Date: Tue, 19 Oct 2021 13:03:23 +0530 Subject: [PATCH 24/24] fix: patch fix einvoicing deprecation patch removed --- erpnext/patches.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e21b7c09b216..41d14bd74029 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -306,7 +306,6 @@ erpnext.patches.v13_0.add_custom_field_for_south_africa #2 erpnext.patches.v13_0.rename_discharge_ordered_date_in_ip_record erpnext.patches.v13_0.migrate_stripe_api erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries -erpnext.patches.v13_0.einvoicing_deprecation_warning execute:frappe.reload_doc("erpnext_integrations", "doctype", "TaxJar Settings") execute:frappe.reload_doc("erpnext_integrations", "doctype", "Product Tax Category") erpnext.patches.v13_0.custom_fields_for_taxjar_integration