From 839ac10b3ca8bc8ca0a0aa9a7d9d6e41d9dc176a Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Tue, 19 Jul 2022 19:54:28 +0000 Subject: [PATCH 01/20] 1st round of changes for metadata import --- shipstation_integration/orders.py | 18 +- shipstation_integration/setup.py | 2 + .../__init__.py | 0 .../shipstation_item_custom_fields.json | 56 ++++++ .../shipstation_item_custom_fields.py | 8 + .../shipstation_options_import/__init__.py | 0 .../shipstation_options_import.json | 39 ++++ .../shipstation_options_import.py | 8 + .../shipstation_settings.js | 170 +++++++++--------- .../shipstation_settings.json | 35 +++- .../shipstation_settings.py | 6 + 11 files changed, 255 insertions(+), 87 deletions(-) create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/__init__.py create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_options_import/__init__.py create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index cbb1dc9..2849835 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -205,9 +205,7 @@ def create_erpnext_order( item_code = create_item(item, settings=settings, store=store) item_notes = get_item_notes(item) rate = item.unit_price if hasattr(item, "unit_price") else None - so.append( - "items", - { + item_dict = { "item_code": item_code, "qty": item.quantity, "uom": frappe.db.get_single_value("Stock Settings", "stock_uom"), @@ -216,8 +214,18 @@ def create_erpnext_order( "warehouse": store.warehouse, "shipstation_order_item_id": item.order_item_id, "shipstation_item_notes": item_notes, - }, - ) + } + options_import = frappe.get_all("Shipstation Options Import", + filters = dict(parent=store.parent), + fields = ["shipstation_option_name", "sales_order_item_field"]) + if options_import: + for option_import in options_import: + for option in item.options: + if option.name == option_import.shipstation_option_name: + frappe.publish_realtime(event='eval_js', message='console.log("{0}")'.format(option.value), user=frappe.session.user) + item_dict[option_import.sales_order_item_field] = option.value + + so.append("items", item_dict) if not so.get("items"): return diff --git a/shipstation_integration/setup.py b/shipstation_integration/setup.py index 75e3117..cf48594 100644 --- a/shipstation_integration/setup.py +++ b/shipstation_integration/setup.py @@ -297,3 +297,5 @@ def setup_custom_fields(args=None): print("Creating custom fields for Shipstation") create_custom_fields(custom_fields) + +# def update_item_custom_fields(order_item_custom_fields): diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/__init__.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json new file mode 100644 index 0000000..52ae615 --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json @@ -0,0 +1,56 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2022-07-06 12:17:13.829719", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "label", + "fieldtype", + "fieldname", + "options" + ], + "fields": [ + { + "fieldname": "label", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Label", + "reqd": 1 + }, + { + "default": "Data", + "fieldname": "fieldtype", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Type", + "options": "Attach\nAttach Image\nBarcode\nButton\nCheck\nCode\nColor\nColumn Break\nCurrency\nData\nDate\nDatetime\nDuration\nDynamic Link\nFloat\nFold\nGeolocation\nHeading\nHTML\nHTML Editor\nIcon\nImage\nInt\nLink\nLong Text\nMarkdown Editor\nPassword\nPercent\nRead Only\nRating\nSection Break\nSelect\nSmall Text\nTable\nTable MultiSelect\nText\nText Editor\nTime\nSignature", + "reqd": 1 + }, + { + "fieldname": "fieldname", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Name", + "reqd": 1 + }, + { + "fieldname": "options", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Options" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2022-07-06 13:35:36.806145", + "modified_by": "Administrator", + "module": "Shipstation Integration", + "name": "Shipstation Item Custom Fields", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py new file mode 100644 index 0000000..934019f --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, Parsimony LLC and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class ShipstationItemCustomFields(Document): + pass diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/__init__.py b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json new file mode 100644 index 0000000..851e82a --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json @@ -0,0 +1,39 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2022-07-05 14:43:09.827242", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "shipstation_option_name", + "sales_order_item_field" + ], + "fields": [ + { + "fieldname": "shipstation_option_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "ShipStation Option Name", + "reqd": 1 + }, + { + "fieldname": "sales_order_item_field", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Sales Order Item Field", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2022-07-05 14:43:23.617215", + "modified_by": "Administrator", + "module": "Shipstation Integration", + "name": "Shipstation Options Import", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py new file mode 100644 index 0000000..373300f --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, Parsimony LLC and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class ShipstationOptionsImport(Document): + pass diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index b52c35c..806e949 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -2,96 +2,104 @@ // For license information, please see license.txt function company_query(frm, cdt, cdn) { - const row = frm.selected_doc || locals[cdt][cdn]; - return { - filters: { - "company": row.company, - "is_group": 0 - } - }; + const row = frm.selected_doc || locals[cdt][cdn]; + return { + filters: { + "company": row.company, + "is_group": 0 + } + }; } frappe.ui.form.on("Shipstation Settings", { - setup: frm => { - frm.set_query("shipstation_warehouses", { "shipstation_warehouse_id": ["!=", ""] }); - frm.set_query("cost_center", "shipstation_stores", company_query); - frm.set_query("warehouse", "shipstation_stores", company_query); - frm.set_query("tax_account", "shipstation_stores", company_query); - frm.set_query("sales_account", "shipstation_stores", company_query); - frm.set_query("expense_account", "shipstation_stores", company_query); - frm.set_query("shipping_income_account", "shipstation_stores", company_query); - frm.set_query("shipping_expense_account", "shipstation_stores", company_query); - }, + setup: frm => { + frm.set_query("shipstation_warehouses", { "shipstation_warehouse_id": ["!=", ""] }); + frm.set_query("cost_center", "shipstation_stores", company_query); + frm.set_query("warehouse", "shipstation_stores", company_query); + frm.set_query("tax_account", "shipstation_stores", company_query); + frm.set_query("sales_account", "shipstation_stores", company_query); + frm.set_query("expense_account", "shipstation_stores", company_query); + frm.set_query("shipping_income_account", "shipstation_stores", company_query); + frm.set_query("shipping_expense_account", "shipstation_stores", company_query); + }, - after_save: frm => { - frm.trigger("toggle_mandatory_table_fields"); - }, + after_save: frm => { + frm.trigger("toggle_mandatory_table_fields"); + }, - refresh: frm => { - frm.trigger("toggle_mandatory_table_fields"); - if (frm.doc.carrier_data) { - let wrapper = $(frm.fields_dict["carriers_html"].wrapper); - wrapper.html(frappe.render_template("carriers", { "carriers": frm.doc.__onload.carriers })); - } - }, + refresh: frm => { + frm.trigger("toggle_mandatory_table_fields"); + if (frm.doc.carrier_data) { + let wrapper = $(frm.fields_dict["carriers_html"].wrapper); + wrapper.html(frappe.render_template("carriers", { "carriers": frm.doc.__onload.carriers })); + } + }, - update_carriers_and_stores: frm => { - frappe.show_alert("Updating Carriers and Stores") - frm.call({ - doc: frm.doc, - method: "update_carriers_and_stores", - freeze: true - }).done(() => { frm.reload_doc() }) - }, + update_carriers_and_stores: frm => { + frappe.show_alert("Updating Carriers and Stores") + frm.call({ + doc: frm.doc, + method: "update_carriers_and_stores", + freeze: true + }).done(() => { frm.reload_doc() }) + }, - get_items: frm => { - frappe.show_alert("Getting Items"); - frm.call({ - doc: frm.doc, - method: "get_items", - freeze: true - }).done((r) => { frappe.show_alert(r.message) }) - }, + get_items: frm => { + frappe.show_alert("Getting Items"); + frm.call({ + doc: frm.doc, + method: "get_items", + freeze: true + }).done((r) => { frappe.show_alert(r.message) }) + }, - get_orders: frm => { - frappe.show_alert("Getting Orders"); - frm.call({ - doc: frm.doc, - method: "get_orders", - freeze: true - }) - }, + get_orders: frm => { + frappe.show_alert("Getting Orders"); + frm.call({ + doc: frm.doc, + method: "get_orders", + freeze: true + }) + }, - get_shipments: frm => { - frappe.show_alert("Getting Shipments"); - frm.call({ - doc: frm.doc, - method: "get_shipments", - freeze: true - }) - }, + get_shipments: frm => { + frappe.show_alert("Getting Shipments"); + frm.call({ + doc: frm.doc, + method: "get_shipments", + freeze: true + }) + }, - fetch_warehouses: frm => { - frm.call({ - doc: frm.doc, - method: "update_warehouses", - freeze: true - }) - }, + fetch_warehouses: frm => { + frm.call({ + doc: frm.doc, + method: "update_warehouses", + freeze: true + }) + }, - reset_warehouses: frm => { - frm.set_value("shipstation_warehouses", []); - frm.save(); - }, + update_order_item_custom_fields: frm => { + frm.call({ + doc: frm.doc, + method: "update_order_item_custom_fields", + freeze: true + }) + }, - toggle_mandatory_table_fields: frm => { - frm.fields_dict.shipstation_stores.grid.toggle_reqd("company", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("warehouse", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("cost_center", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("shipping_income_account", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("shipping_expense_account", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("tax_account", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("sales_account", !frm.is_new()); - frm.fields_dict.shipstation_stores.grid.toggle_reqd("expense_account", !frm.is_new()); - } -}); + reset_warehouses: frm => { + frm.set_value("shipstation_warehouses", []); + frm.save(); + }, + + toggle_mandatory_table_fields: frm => { + frm.fields_dict.shipstation_stores.grid.toggle_reqd("company", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("warehouse", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("cost_center", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("shipping_income_account", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("shipping_expense_account", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("tax_account", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("sales_account", !frm.is_new()); + frm.fields_dict.shipstation_stores.grid.toggle_reqd("expense_account", !frm.is_new()); + } +}); \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json index 585a553..11a7052 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "Prompt", "creation": "2019-12-10 11:54:44.442858", "doctype": "DocType", @@ -23,6 +24,11 @@ "reset_warehouses", "sb_stores", "shipstation_stores", + "sb_itemmeta", + "order_item_custom_fields", + "update_order_item_custom_fields", + "column_break_20", + "options_import", "sb_carriers", "carrier_data", "carriers_html" @@ -154,10 +160,37 @@ "fieldname": "reset_warehouses", "fieldtype": "Button", "label": "Reset" + }, + { + "fieldname": "sb_itemmeta", + "fieldtype": "Section Break", + "label": "Metadata Import" + }, + { + "fieldname": "column_break_20", + "fieldtype": "Column Break" + }, + { + "fieldname": "order_item_custom_fields", + "fieldtype": "Table", + "label": "Sales Order Item Custom Fields", + "options": "Shipstation Item Custom Fields" + }, + { + "fieldname": "update_order_item_custom_fields", + "fieldtype": "Button", + "label": "Create/Update Custom Fields" + }, + { + "fieldname": "options_import", + "fieldtype": "Table", + "label": "Shipstation Options Import", + "options": "Shipstation Options Import" } ], "hide_toolbar": 1, - "modified": "2021-11-24 05:30:10.617590", + "links": [], + "modified": "2022-07-06 13:38:50.958416", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Settings", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py index d034be5..1844f60 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py @@ -187,3 +187,9 @@ def get_codes(self, carrier, service, package): if pack['name'] == package: _package = pack['code'] return _carrier, _service, _package + + + @frappe.whitelist() + def update_order_item_custom_fields(self): + order_item_custom_fields = self + frappe.publish_realtime(event='eval_js', message='console.log("{0}")'.format(order_item_custom_fields), user=frappe.session.user) From 262a8c968bed0a60daea31cdcac8a0a828a8b47a Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 17 Aug 2022 06:54:50 +0000 Subject: [PATCH 02/20] finish the metadata sync code --- shipstation_integration/orders.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index 2849835..d5590c2 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -222,7 +222,6 @@ def create_erpnext_order( for option_import in options_import: for option in item.options: if option.name == option_import.shipstation_option_name: - frappe.publish_realtime(event='eval_js', message='console.log("{0}")'.format(option.value), user=frappe.session.user) item_dict[option_import.sales_order_item_field] = option.value so.append("items", item_dict) From e3707769fc95db20303bad4d7129895a2353ffbf Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Tue, 30 Aug 2022 15:00:16 +0000 Subject: [PATCH 03/20] increase order retrieval time --- shipstation_integration/orders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index d5590c2..e0e63d7 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -60,7 +60,7 @@ def list_orders( if not last_order_datetime: # Get data for the last day, Shipstation API behaves oddly when it's a shorter period last_order_datetime = datetime.datetime.utcnow() - datetime.timedelta( - hours=24 + hours=72 ) store: "ShipstationStore" From b28c7a3d15814d182a8d9edabff5781e35266795 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 21 Sep 2022 12:57:03 +0000 Subject: [PATCH 04/20] skip item if qty is 0 (refunded items) --- shipstation_integration/orders.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index e0e63d7..9bb5095 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -201,6 +201,9 @@ def create_erpnext_order( order_items = frappe.get_attr(process_order_items_hook[0])(order_items) for item in order_items: + # skip the item if the quantity is 0 (item was refunded) + if item.quantity == 0: + continue settings = frappe.get_doc("Shipstation Settings", store.parent) item_code = create_item(item, settings=settings, store=store) item_notes = get_item_notes(item) From 2b003bdcb1510267c39a634c4fbb7cadb2f50711 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 21 Sep 2022 13:13:26 +0000 Subject: [PATCH 05/20] create custom fields function --- .../shipstation_settings.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py index 1844f60..437b342 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py @@ -188,8 +188,22 @@ def get_codes(self, carrier, service, package): _package = pack['code'] return _carrier, _service, _package - + # create custom fields on the Sales Order Item doctype from the order_item_custom_fields table for storing Shipstation metadata @frappe.whitelist() def update_order_item_custom_fields(self): - order_item_custom_fields = self - frappe.publish_realtime(event='eval_js', message='console.log("{0}")'.format(order_item_custom_fields), user=frappe.session.user) + order_item_custom_fields = self.order_item_custom_fields + insert_after = "Shipstation Item Notes" + for field in order_item_custom_fields: + if not frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": field.fieldname}): + custom_field = frappe.new_doc("Custom Field") + custom_field.update({ + "dt": "Sales Order Item", + "fieldname": field.fieldname, + "label": field.label, + "fieldtype": field.fieldtype, + "options": field.options, + "insert_after": insert_after + }) + custom_field.insert() + if frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": field.fieldname}): + insert_after = field.label From 43ba3f5c02f362c847b5e77830e30eb77477f8ee Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 21 Sep 2022 13:17:21 +0000 Subject: [PATCH 06/20] cleanup --- shipstation_integration/setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shipstation_integration/setup.py b/shipstation_integration/setup.py index cf48594..66fe497 100644 --- a/shipstation_integration/setup.py +++ b/shipstation_integration/setup.py @@ -298,4 +298,3 @@ def setup_custom_fields(args=None): print("Creating custom fields for Shipstation") create_custom_fields(custom_fields) -# def update_item_custom_fields(order_item_custom_fields): From f6d8512882741161da55a4dbd02b8391443476f4 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 21 Sep 2022 13:18:00 +0000 Subject: [PATCH 07/20] cleanup --- shipstation_integration/setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shipstation_integration/setup.py b/shipstation_integration/setup.py index 66fe497..75e3117 100644 --- a/shipstation_integration/setup.py +++ b/shipstation_integration/setup.py @@ -297,4 +297,3 @@ def setup_custom_fields(args=None): print("Creating custom fields for Shipstation") create_custom_fields(custom_fields) - From 8859e6348d471eddd92184f4ccd58038a1643866 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 21 Sep 2022 13:23:24 +0000 Subject: [PATCH 08/20] version bump --- shipstation_integration/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shipstation_integration/__init__.py b/shipstation_integration/__init__.py index 95d1338..4650b23 100644 --- a/shipstation_integration/__init__.py +++ b/shipstation_integration/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -__version__ = '0.0.1' +__version__ = '0.0.2' From d07aed828a0e95af195249641d463bb4d1ede151 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Tue, 15 Nov 2022 22:12:35 +0000 Subject: [PATCH 09/20] new layout, item field linking --- .../shipstation_item_custom_fields.json | 30 +++- .../shipstation_options_import.json | 5 +- .../shipstation_settings.js | 138 +++++++++++++++++- .../shipstation_settings.json | 18 ++- .../shipstation_settings.py | 7 + 5 files changed, 185 insertions(+), 13 deletions(-) diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json index 52ae615..07380d9 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json @@ -9,7 +9,10 @@ "label", "fieldtype", "fieldname", - "options" + "options", + "reqd", + "hidden", + "read_only" ], "fields": [ { @@ -37,15 +40,36 @@ }, { "fieldname": "options", - "fieldtype": "Data", + "fieldtype": "Small Text", "in_list_view": 1, "label": "Options" + }, + { + "default": "0", + "fieldname": "reqd", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Mandatory" + }, + { + "default": "0", + "fieldname": "hidden", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Hidden" + }, + { + "default": "0", + "fieldname": "read_only", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Read Only" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-07-06 13:35:36.806145", + "modified": "2022-11-15 15:02:05.934942", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Item Custom Fields", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json index 851e82a..0ce45ba 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json @@ -19,16 +19,17 @@ }, { "fieldname": "sales_order_item_field", - "fieldtype": "Data", + "fieldtype": "Link", "in_list_view": 1, "label": "Sales Order Item Field", + "options": "DocField", "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-07-05 14:43:23.617215", + "modified": "2022-11-15 16:59:09.731866", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Options Import", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index 806e949..a65d35b 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -21,6 +21,11 @@ frappe.ui.form.on("Shipstation Settings", { frm.set_query("expense_account", "shipstation_stores", company_query); frm.set_query("shipping_income_account", "shipstation_stores", company_query); frm.set_query("shipping_expense_account", "shipstation_stores", company_query); + frm.set_query("sales_order_item_field", "options_import", function() { + return { + query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" + }; + }); }, after_save: frm => { @@ -102,4 +107,135 @@ frappe.ui.form.on("Shipstation Settings", { frm.fields_dict.shipstation_stores.grid.toggle_reqd("sales_account", !frm.is_new()); frm.fields_dict.shipstation_stores.grid.toggle_reqd("expense_account", !frm.is_new()); } -}); \ No newline at end of file + +}); + +// frappe.ui.form.on("Shipstation Options Import", { +// form_render(frm, doctype, docname) { +// // Render a select field for Sales Order Item Field instead of Data Input for better UX +// let field = frm.cur_grid.grid_form.fields_dict.sales_order_item_field; +// $(field.input).hide(); + +// let $field_select = $(``); -// field.$input_wrapper.append($field_select); - -// let row = frappe.get_doc(doctype, docname); -// let curr_value = null; -// if (row.sales_order_item_field) { -// curr_value = row.sales_order_item_field; -// } - -// function update_fieldname_options() { -// $field_select.find("option").remove(); - -// // let link_fieldname = $doctype_select.val(); -// // if (!link_fieldname) return; -// // let link_field = frm.doc.fields.find((df) => df.fieldname === link_fieldname); -// // let link_doctype = link_field.options; -// frappe.model.with_doctype("Sales Order Item", () => { -// let fields = frappe.meta -// .get_docfields(link_doctype, null, { -// fieldtype: ["not in", frappe.model.no_value_type], -// }) -// .map((df) => ({ -// label: `${df.label} (${df.fieldtype})`, -// value: df.fieldname, -// })); -// $field_select.add_options([{ -// label: __("Select Field"), -// value: "", -// selected: true, -// disabled: true, -// }, -// ...fields, -// ]); - -// if (curr_value) { -// $field_select.val(curr_value); -// } -// }); -// } - -// $field_select.on("change", () => { -// let sales_order_item_field = $field_select.val(); -// row.sales_order_item_field = sales_order_item_field; -// frm.dirty(); -// }); - -// if (curr_value) { -// update_fieldname_options(); -// } -// }, - -// // fields_add: (frm) => { -// // frm.trigger("setup_default_views"); -// // }, -// }); - - -// frappe.ui.form.on("Shipstation Options Import", { -// options_import_add: function(frm) { -// var shipstation_option_name = frm.doc.shipstation_option_name || null; -// return frappe.call({ -// method: "frappe.custom.doctype.custom_field.custom_field.get_fields_label", -// args: { doctype: "Sales Order Item", fieldname: shipstation_option_name }, -// callback: function(r) { -// if (r) { -// var field_labels = r.message; -// //set_field_options("sales_order_item_field", field_labels); -// frappe.meta.get_docfield("Shipstation Options Import", "sales_order_item_field", frm.doc.name).options = [""].concat(field_labels); -// frm.refresh_field("sales_order_item_field"); -// console.log(field_labels); -// } -// }, -// }); -// }, - -// shipstation_option_name: function(frm) { -// var shipstation_option_name = frm.doc.shipstation_option_name || null; -// return frappe.call({ -// method: "frappe.custom.doctype.custom_field.custom_field.get_fields_label", -// args: { doctype: "Sales Order Item", fieldname: shipstation_option_name }, -// callback: function(r) { -// if (r) { -// // var field_labels = r.message; -// // console.log(field_labels); -// var field_labels = $.map(r.message, function(v) { -// return v.label; -// }); -// set_field_options("sales_order_item_field", field_labels); - -// if (in_list(field_labels, shipstation_option_name)) { -// frm.set_value("sales_order_item_field", shipstation_option_name); -// } -// frm.refresh_field("sales_order_item_field"); -// } -// }, -// }); -// }, -// }); - -// frappe.ui.form.on("Shipstation Options Import", { -// shipstation_option_name: function(cur_frm, cdt, cdn) { -// doctype = "Sales Order Item" -// let row = frappe.get_doc(cdt, cdn); -// frappe.model.with_doctype(doctype, function() { -// var options = $.map(frappe.get_meta(doctype).fields, -// function(d) { -// if (d.fieldname && frappe.model.no_value_type.indexOf(d.fieldtype) === -1) { -// return d.fieldname; -// } -// return null; -// } -// ); -// // console.log("test options select field" + options); - -// frappe.meta.get_docfield("Shipstation Options Import", "sales_order_item_field", cur_frm.doc.name).options = [""].concat(options); - -// // frappe.model.set_value(cdt, cdn, "sales_order_item_field", options); - -// cur_frm.refresh_field("sales_order_item_field"); - -// }); -// } -// }); \ No newline at end of file +frappe.ui.form.on("Shipstation Options Import", { + sales_order_item_field: (frm, cdt, cdn) => { + const row = locals[cdt][cdn]; + row._ignore_links = true; + var curr_value = row.sales_order_item_field; + if (row.sales_order_item_field) { + frappe.call({ + method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_field_link_type", + args: { + "fieldname": curr_value + }, + callback: r => { + if (r.message) { + frappe.model.set_value(cdt, cdn, "sales_order_item_field_type", r.message); + } + } + }); + } + } +}); \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py index 0215030..f212613 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py @@ -225,25 +225,53 @@ def get_codes(self, carrier, service, package): @frappe.whitelist() def update_order_item_custom_fields(self): order_item_custom_fields = self.order_item_custom_fields - insert_after = "Shipstation Item Notes" + insert_after = "shipstation_item_notes" + item_doctypes = ["Delivery Note Item", "Sales Order Item", "Sales Invoice Item"] for field in order_item_custom_fields: - if not frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": field.fieldname}): - custom_field = frappe.new_doc("Custom Field") - custom_field.update({ - "dt": "Sales Order Item", - "fieldname": field.fieldname, - "label": field.label, - "fieldtype": field.fieldtype, - "options": field.options, - "insert_after": insert_after - }) - custom_field.insert() - if frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": field.fieldname}): - insert_after = field.label - -# @frappe.whitelist() -# @frappe.validate_and_sanitize_search_inputs -# def get_item_fields(doctype, txt, searchfield, start, page_len, filters): -# # return frappe.db.sql("""select fieldname, label from `tabCustom Field` where dt = 'Sales Order Item'""") -# fields = frappe.get_meta("Sales Order Item").fields -# return [[f.fieldname, f.label] for f in fields if f.fieldtype in ["Data", "Text", "Small Text", "Link", "Select"]] \ No newline at end of file + field_def = { + "insert_after": insert_after, + "label": field.label, + "fieldtype": field.fieldtype, + "fieldname": field.fieldname, + "length": field.length, + "reqd": field.reqd, + "hidded": field.hidden, + "read_only": field.read_only, + "options": field.options, + "default": field.default, + "fetch_from": field.fetch_from, + "fetch_if_empty": field.fetch_if_empty + } + for dt in item_doctypes: + if not frappe.db.exists("Custom Field", {"dt": dt, "fieldname": field.fieldname}): + custom_field = frappe.new_doc("Custom Field") + custom_field.dt = dt + custom_field.update(field_def) + custom_field.insert() + else: + custom_field = frappe.get_doc("Custom Field", {"dt": dt, "fieldname": field.fieldname}) + custom_field.update(field_def) + custom_field.save() + if frappe.db.exists("Custom Field", {"dt": dt, "fieldname": field.fieldname}): + insert_after = field.fieldname + frappe.clear_cache(doctype=dt) + frappe.db.updatedb(dt) + + +@frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs +def get_item_fields(doctype, txt, searchfield, start, page_len, filters): + fields = frappe.get_meta("Sales Order Item").fields + fields = [[f.fieldname, f.label] for f in fields if f.fieldtype in ["Data", "Text", "Small Text", "Link", "Select"]] + if txt: + return [f for f in fields if txt.lower() in f[0].lower() or txt.lower() in f[1].lower()] + else: + return fields + +@frappe.whitelist() +def get_item_field_link_type(fieldname): + # check if the field is a custom field + if frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": fieldname}): + return "Custom Field" + else: + return "DocField" \ No newline at end of file From e73abf42ce21435f3da1be283935c5fc7e4baa9a Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 16 Nov 2022 19:52:18 +0000 Subject: [PATCH 13/20] tweak label --- .../doctype/shipstation_settings/shipstation_settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json index 79d691d..d5c402a 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json @@ -189,12 +189,12 @@ "default": "0", "fieldname": "create_custom_fields_for_items", "fieldtype": "Check", - "label": "Define New Custom Fields for Sales Order Items" + "label": "Define Custom Fields for Sales Order Items" } ], "hide_toolbar": 1, "links": [], - "modified": "2022-11-15 15:14:56.590592", + "modified": "2022-11-16 14:52:10.348383", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Settings", From 06f0c168c9edd0b0819345f974ff1e4f9c5dc15b Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 16 Nov 2022 20:06:15 +0000 Subject: [PATCH 14/20] import new options to the Options Import table --- shipstation_integration/orders.py | 16 +++++++++++----- .../shipstation_options_import.json | 8 +++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index 05909a9..e927377 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -222,11 +222,17 @@ def create_erpnext_order( options_import = frappe.get_all("Shipstation Options Import", filters=dict(parent=store.parent), fields=["shipstation_option_name", "sales_order_item_field"]) - if options_import: - for option_import in options_import: - for option in item.options: - if option.name == option_import.shipstation_option_name: - item_dict[option_import.sales_order_item_field] = option.value + for option in item.options: + # check to see if the option is in the Options Import table + option_import = next((x for x in options_import if x.shipstation_option_name == option.name), None) + if option_import: + item_dict[option_import.sales_order_item_field] = option.value + else: + # if the option name is not in the Options Import table, add it + settings.append("options_import", { + "shipstation_option_name": option.name + }) + settings.save() so.append("items", item_dict) diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json index 9bee210..807dd31 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json @@ -25,8 +25,7 @@ "fieldtype": "Dynamic Link", "in_list_view": 1, "label": "Sales Order Item Field", - "options": "sales_order_item_field_type", - "reqd": 1 + "options": "sales_order_item_field_type" }, { "default": "DocField", @@ -34,8 +33,7 @@ "fieldtype": "Link", "hidden": 1, "label": "Sales Order Item Field Type", - "options": "DocType", - "reqd": 1 + "options": "DocType" }, { "fieldname": "column_break_2", @@ -45,7 +43,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-11-16 14:13:11.357163", + "modified": "2022-11-16 14:53:03.519031", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Options Import", From db0549da890da3dd8c2a32eca98ed1d9db5b832b Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 16 Nov 2022 20:28:01 +0000 Subject: [PATCH 15/20] item option assignment check --- shipstation_integration/orders.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index e927377..a912ca9 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -226,7 +226,8 @@ def create_erpnext_order( # check to see if the option is in the Options Import table option_import = next((x for x in options_import if x.shipstation_option_name == option.name), None) if option_import: - item_dict[option_import.sales_order_item_field] = option.value + if option_import.sales_order_item_field: + item_dict[option_import.sales_order_item_field] = option.value else: # if the option name is not in the Options Import table, add it settings.append("options_import", { From 5d20970da36d1939917e05c615fe0b84328eaf46 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Wed, 16 Nov 2022 20:39:07 +0000 Subject: [PATCH 16/20] new hours_to_fetch field --- shipstation_integration/orders.py | 2 +- .../shipstation_settings.json | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index a912ca9..6b90d9a 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -60,7 +60,7 @@ def list_orders( if not last_order_datetime: # Get data for the last day, Shipstation API behaves oddly when it's a shorter period last_order_datetime = datetime.datetime.utcnow() - datetime.timedelta( - hours=72 + hours=sss_doc.get("hours_to_fetch", 24) ) store: "ShipstationStore" diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json index d5c402a..0b61537 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json @@ -17,6 +17,8 @@ "get_shipments", "update_carriers_and_stores", "sb_filters", + "hours_to_fetch", + "column_break_13", "since_date", "sb_warehouses", "shipstation_warehouses", @@ -190,11 +192,22 @@ "fieldname": "create_custom_fields_for_items", "fieldtype": "Check", "label": "Define Custom Fields for Sales Order Items" + }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break" + }, + { + "default": "24", + "description": "How many hours should we look back for orders on the initial sync? This should be no less than 24.", + "fieldname": "hours_to_fetch", + "fieldtype": "Int", + "label": "Order Age" } ], "hide_toolbar": 1, "links": [], - "modified": "2022-11-16 14:52:10.348383", + "modified": "2022-11-16 15:37:28.019670", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Settings", From fef54b98ef7e30737b55d0d240eec890f5d56943 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Fri, 9 Dec 2022 17:09:32 +0000 Subject: [PATCH 17/20] better naming conventions --- .../__init__.py | 0 .../shipstation_item_custom_field.json} | 2 +- .../shipstation_item_custom_field.py} | 2 +- .../__init__.py | 0 .../shipstation_option.json} | 26 +++++++++---------- .../shipstation_option.py} | 2 +- .../shipstation_settings.js | 14 +++++----- .../shipstation_settings.json | 22 ++++++++-------- 8 files changed, 34 insertions(+), 34 deletions(-) rename shipstation_integration/shipstation_integration/doctype/{shipstation_item_custom_fields => shipstation_item_custom_field}/__init__.py (100%) rename shipstation_integration/shipstation_integration/doctype/{shipstation_item_custom_fields/shipstation_item_custom_fields.json => shipstation_item_custom_field/shipstation_item_custom_field.json} (98%) rename shipstation_integration/shipstation_integration/doctype/{shipstation_item_custom_fields/shipstation_item_custom_fields.py => shipstation_item_custom_field/shipstation_item_custom_field.py} (79%) rename shipstation_integration/shipstation_integration/doctype/{shipstation_options_import => shipstation_option}/__init__.py (100%) rename shipstation_integration/shipstation_integration/doctype/{shipstation_options_import/shipstation_options_import.json => shipstation_option/shipstation_option.json} (71%) rename shipstation_integration/shipstation_integration/doctype/{shipstation_options_import/shipstation_options_import.py => shipstation_option/shipstation_option.py} (80%) diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/__init__.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/__init__.py similarity index 100% rename from shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/__init__.py rename to shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/__init__.py diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.json similarity index 98% rename from shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json rename to shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.json index c441096..f660ef7 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.json @@ -103,7 +103,7 @@ "modified": "2022-11-16 14:14:12.504952", "modified_by": "Administrator", "module": "Shipstation Integration", - "name": "Shipstation Item Custom Fields", + "name": "Shipstation Item Custom Field", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.py similarity index 79% rename from shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py rename to shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.py index 934019f..9d514a4 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_fields/shipstation_item_custom_fields.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_custom_field/shipstation_item_custom_field.py @@ -4,5 +4,5 @@ # import frappe from frappe.model.document import Document -class ShipstationItemCustomFields(Document): +class ShipstationItemCustomField(Document): pass diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/__init__.py b/shipstation_integration/shipstation_integration/doctype/shipstation_option/__init__.py similarity index 100% rename from shipstation_integration/shipstation_integration/doctype/shipstation_options_import/__init__.py rename to shipstation_integration/shipstation_integration/doctype/shipstation_option/__init__.py diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json similarity index 71% rename from shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json rename to shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json index 807dd31..7ba2fd2 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json @@ -8,8 +8,8 @@ "field_order": [ "shipstation_option_name", "column_break_2", - "sales_order_item_field", - "sales_order_item_field_type" + "item_field", + "item_field_type" ], "fields": [ { @@ -19,34 +19,34 @@ "label": "ShipStation Option Name", "reqd": 1 }, + { + "fieldname": "column_break_2", + "fieldtype": "Column Break" + }, { "fetch_from": "sales_order_item_field.fieldname", - "fieldname": "sales_order_item_field", + "fieldname": "item_field", "fieldtype": "Dynamic Link", "in_list_view": 1, - "label": "Sales Order Item Field", - "options": "sales_order_item_field_type" + "label": "Item Field", + "options": "item_field_type" }, { "default": "DocField", - "fieldname": "sales_order_item_field_type", + "fieldname": "item_field_type", "fieldtype": "Link", "hidden": 1, - "label": "Sales Order Item Field Type", + "label": "Item Field Type", "options": "DocType" - }, - { - "fieldname": "column_break_2", - "fieldtype": "Column Break" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-11-16 14:53:03.519031", + "modified": "2022-12-09 12:03:30.963416", "modified_by": "Administrator", "module": "Shipstation Integration", - "name": "Shipstation Options Import", + "name": "Shipstation Option", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.py similarity index 80% rename from shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py rename to shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.py index 373300f..bee002d 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_options_import/shipstation_options_import.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.py @@ -4,5 +4,5 @@ # import frappe from frappe.model.document import Document -class ShipstationOptionsImport(Document): +class ShipstationOption(Document): pass diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index a5af55b..a6c1d12 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -21,12 +21,12 @@ frappe.ui.form.on("Shipstation Settings", { frm.set_query("expense_account", "shipstation_stores", company_query); frm.set_query("shipping_income_account", "shipstation_stores", company_query); frm.set_query("shipping_expense_account", "shipstation_stores", company_query); - frm.set_query("sales_order_item_field", "options_import", function() { + frm.set_query("item_field", "options_import", function() { return { query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" }; }); - frappe.meta.get_docfield("Shipstation Options Import", "sales_order_item_field", frm.docname).ignore_link_validation = true; + frappe.meta.get_docfield("Shipstation Option", "item_field", frm.docname).ignore_link_validation = true; }, after_save: frm => { @@ -111,12 +111,12 @@ frappe.ui.form.on("Shipstation Settings", { }); -frappe.ui.form.on("Shipstation Options Import", { - sales_order_item_field: (frm, cdt, cdn) => { +frappe.ui.form.on("Shipstation Option", { + item_field: (frm, cdt, cdn) => { const row = locals[cdt][cdn]; row._ignore_links = true; - var curr_value = row.sales_order_item_field; - if (row.sales_order_item_field) { + var curr_value = row.item_field; + if (row.item_field) { frappe.call({ method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_field_link_type", args: { @@ -124,7 +124,7 @@ frappe.ui.form.on("Shipstation Options Import", { }, callback: r => { if (r.message) { - frappe.model.set_value(cdt, cdn, "sales_order_item_field_type", r.message); + frappe.model.set_value(cdt, cdn, "item_field_type", r.message); } } }); diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json index 0b61537..b63bfc5 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json @@ -29,7 +29,7 @@ "sb_itemmeta", "options_import", "create_custom_fields_for_items", - "order_item_custom_fields", + "item_custom_fields", "update_order_item_custom_fields", "sb_carriers", "carrier_data", @@ -168,13 +168,6 @@ "fieldtype": "Section Break", "label": "Metadata Import" }, - { - "depends_on": "eval:doc.create_custom_fields_for_items", - "fieldname": "order_item_custom_fields", - "fieldtype": "Table", - "label": "Sales Order Item Custom Fields", - "options": "Shipstation Item Custom Fields" - }, { "depends_on": "eval:doc.create_custom_fields_for_items", "fieldname": "update_order_item_custom_fields", @@ -185,13 +178,13 @@ "fieldname": "options_import", "fieldtype": "Table", "label": "Shipstation Options Import", - "options": "Shipstation Options Import" + "options": "Shipstation Option" }, { "default": "0", "fieldname": "create_custom_fields_for_items", "fieldtype": "Check", - "label": "Define Custom Fields for Sales Order Items" + "label": "Define Custom Fields for Items" }, { "fieldname": "column_break_13", @@ -203,11 +196,18 @@ "fieldname": "hours_to_fetch", "fieldtype": "Int", "label": "Order Age" + }, + { + "depends_on": "eval:doc.create_custom_fields_for_items", + "fieldname": "item_custom_fields", + "fieldtype": "Table", + "label": "Item Custom Fields", + "options": "Shipstation Item Custom Field" } ], "hide_toolbar": 1, "links": [], - "modified": "2022-11-16 15:37:28.019670", + "modified": "2022-12-09 12:09:17.363713", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Settings", From 730445493a5fb0f6615181ccb164331a3b0f5a8c Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Fri, 9 Dec 2022 22:33:07 +0000 Subject: [PATCH 18/20] more naming updates --- shipstation_integration/orders.py | 8 ++--- .../shipstation_option.json | 15 ++++----- .../shipstation_settings.js | 21 +++++++++++- .../shipstation_settings.json | 4 +-- .../shipstation_settings.py | 33 ++++++++++++++++--- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/shipstation_integration/orders.py b/shipstation_integration/orders.py index 6b90d9a..d852dc8 100644 --- a/shipstation_integration/orders.py +++ b/shipstation_integration/orders.py @@ -219,15 +219,15 @@ def create_erpnext_order( "shipstation_order_item_id": item.order_item_id, "shipstation_item_notes": item_notes, } - options_import = frappe.get_all("Shipstation Options Import", + options_import = frappe.get_all("Shipstation Option", filters=dict(parent=store.parent), - fields=["shipstation_option_name", "sales_order_item_field"]) + fields=["shipstation_option_name", "item_field"]) for option in item.options: # check to see if the option is in the Options Import table option_import = next((x for x in options_import if x.shipstation_option_name == option.name), None) if option_import: - if option_import.sales_order_item_field: - item_dict[option_import.sales_order_item_field] = option.value + if option_import.item_field: + item_dict[option_import.item_field] = option.value else: # if the option name is not in the Options Import table, add it settings.append("options_import", { diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json index 7ba2fd2..dc6b496 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json @@ -7,7 +7,7 @@ "engine": "InnoDB", "field_order": [ "shipstation_option_name", - "column_break_2", + "column_break", "item_field", "item_field_type" ], @@ -20,11 +20,7 @@ "reqd": 1 }, { - "fieldname": "column_break_2", - "fieldtype": "Column Break" - }, - { - "fetch_from": "sales_order_item_field.fieldname", + "fetch_from": "item_field.fieldname", "fieldname": "item_field", "fieldtype": "Dynamic Link", "in_list_view": 1, @@ -35,15 +31,18 @@ "default": "DocField", "fieldname": "item_field_type", "fieldtype": "Link", - "hidden": 1, "label": "Item Field Type", "options": "DocType" + }, + { + "fieldname": "column_break", + "fieldtype": "Column Break" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-12-09 12:03:30.963416", + "modified": "2022-12-09 17:26:44.554178", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Option", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index a6c1d12..9f536d3 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -26,6 +26,7 @@ frappe.ui.form.on("Shipstation Settings", { query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" }; }); + // workaround for link validation on the item_field field frappe.meta.get_docfield("Shipstation Option", "item_field", frm.docname).ignore_link_validation = true; }, @@ -114,7 +115,6 @@ frappe.ui.form.on("Shipstation Settings", { frappe.ui.form.on("Shipstation Option", { item_field: (frm, cdt, cdn) => { const row = locals[cdt][cdn]; - row._ignore_links = true; var curr_value = row.item_field; if (row.item_field) { frappe.call({ @@ -130,4 +130,23 @@ frappe.ui.form.on("Shipstation Option", { }); } } +}); + +frappe.ui.form.on("Shipstation Item Custom Field", { + before_item_custom_fields_remove: (frm, cdt, cdn) => { + var deleted_row = frappe.get_doc(cdt, cdn); + if (deleted_row.item_field) { + frappe.call({ + method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.remove_item_field", + args: { + "fieldname": deleted_row.item_field + }, + callback: r => { + if (r.message.status === 'Alert') { + frappe.show_alert({ message: r.message.message, indicator: 'orange' }); + } + } + }); + } + } }); \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json index b63bfc5..6d58fa8 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.json @@ -177,7 +177,7 @@ { "fieldname": "options_import", "fieldtype": "Table", - "label": "Shipstation Options Import", + "label": "Shipstation Options", "options": "Shipstation Option" }, { @@ -207,7 +207,7 @@ ], "hide_toolbar": 1, "links": [], - "modified": "2022-12-09 12:09:17.363713", + "modified": "2022-12-09 16:13:16.647066", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Settings", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py index f212613..2cc1843 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py @@ -52,6 +52,9 @@ def after_insert(self): self.update_carriers_and_stores() self.update_warehouses() + def on_update(self): + self.update_item_custom_fields() + @frappe.whitelist() def get_orders(self): list_orders(self) @@ -221,13 +224,14 @@ def get_codes(self, carrier, service, package): return _carrier, _service, _package - # create custom fields on the Sales Order Item doctype from the order_item_custom_fields table for storing Shipstation metadata + # create custom fields on the Sales Order Item doctype from the item_custom_fields table (for storing Shipstation metadata) @frappe.whitelist() - def update_order_item_custom_fields(self): - order_item_custom_fields = self.order_item_custom_fields + def update_item_custom_fields(self): + # first, create any new custom fields + item_custom_fields = self.item_custom_fields insert_after = "shipstation_item_notes" item_doctypes = ["Delivery Note Item", "Sales Order Item", "Sales Invoice Item"] - for field in order_item_custom_fields: + for field in item_custom_fields: field_def = { "insert_after": insert_after, "label": field.label, @@ -256,6 +260,18 @@ def update_order_item_custom_fields(self): insert_after = field.fieldname frappe.clear_cache(doctype=dt) frappe.db.updatedb(dt) + # delete any remove custom fields + removed_item_custom_fields = frappe.flags.removed_item_custom_fields or [] + if removed_item_custom_fields: + # make sure that the removed field is not in the item_custom_fields variable + removed_item_custom_fields = [field for field in removed_item_custom_fields if not field in [f.fieldname for f in item_custom_fields]] + for field in removed_item_custom_fields: + for dt in item_doctypes: + if frappe.db.exists("Custom Field", {"dt": dt, "fieldname": field}): + frappe.delete_doc("Custom Field", {"dt": dt, "fieldname": field}) + frappe.clear_cache(doctype=dt) + frappe.db.updatedb(dt) + @frappe.whitelist() @@ -274,4 +290,11 @@ def get_item_field_link_type(fieldname): if frappe.db.exists("Custom Field", {"dt": "Sales Order Item", "fieldname": fieldname}): return "Custom Field" else: - return "DocField" \ No newline at end of file + return "DocField" + +@frappe.whitelist() +def remove_item_field(fieldname): + frappe.flags.removed_item_custom_fields = frappe.flags.removed_item_custom_fields or [] + if fieldname not in frappe.flags.removed_item_custom_fields: + frappe.flags.removed_item_custom_fields.append(fieldname) + return {'status': 'Alert', 'message': 'Item field ' + fieldname + ' will be deleted on save.'} \ No newline at end of file From 5f6027e0c3a2ea200f707ac16632e3275edc11b4 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Thu, 9 Mar 2023 15:04:16 +0000 Subject: [PATCH 19/20] jslint updates --- .../shipstation_settings/shipstation_settings.js | 14 ++++++-------- .../templates/pages/__pycache__/__init__.py | 0 2 files changed, 6 insertions(+), 8 deletions(-) create mode 100644 shipstation_integration/templates/pages/__pycache__/__init__.py diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index 9f536d3..73ee6a2 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -21,11 +21,9 @@ frappe.ui.form.on("Shipstation Settings", { frm.set_query("expense_account", "shipstation_stores", company_query); frm.set_query("shipping_income_account", "shipstation_stores", company_query); frm.set_query("shipping_expense_account", "shipstation_stores", company_query); - frm.set_query("item_field", "options_import", function() { - return { - query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" - }; - }); + frm.set_query("item_field", "options_import", () => ({ + query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" + })); // workaround for link validation on the item_field field frappe.meta.get_docfield("Shipstation Option", "item_field", frm.docname).ignore_link_validation = true; }, @@ -37,7 +35,7 @@ frappe.ui.form.on("Shipstation Settings", { refresh: frm => { frm.trigger("toggle_mandatory_table_fields"); if (frm.doc.carrier_data) { - let wrapper = $(frm.fields_dict["carriers_html"].wrapper); + const wrapper = $(frm.fields_dict.carriers_html.wrapper); wrapper.html(frappe.render_template("carriers", { "carriers": frm.doc.__onload.carriers })); } }, @@ -115,7 +113,7 @@ frappe.ui.form.on("Shipstation Settings", { frappe.ui.form.on("Shipstation Option", { item_field: (frm, cdt, cdn) => { const row = locals[cdt][cdn]; - var curr_value = row.item_field; + const curr_value = row.item_field; if (row.item_field) { frappe.call({ method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_field_link_type", @@ -134,7 +132,7 @@ frappe.ui.form.on("Shipstation Option", { frappe.ui.form.on("Shipstation Item Custom Field", { before_item_custom_fields_remove: (frm, cdt, cdn) => { - var deleted_row = frappe.get_doc(cdt, cdn); + const deleted_row = frappe.get_doc(cdt, cdn); if (deleted_row.item_field) { frappe.call({ method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.remove_item_field", diff --git a/shipstation_integration/templates/pages/__pycache__/__init__.py b/shipstation_integration/templates/pages/__pycache__/__init__.py new file mode 100644 index 0000000..e69de29 From cfed0569a630594638ae9bdddb5df976268b38f9 Mon Sep 17 00:00:00 2001 From: Avunu LLC Date: Thu, 9 Mar 2023 19:15:14 +0000 Subject: [PATCH 20/20] migrate Item Field Link to Virtual DocType --- .../shipstation_item_field/__init__.py | 0 .../shipstation_item_field.js | 8 ++++ .../shipstation_item_field.json | 43 +++++++++++++++++++ .../shipstation_item_field.py | 24 +++++++++++ .../test_shipstation_item_field.py | 8 ++++ .../shipstation_option.json | 25 ++++------- .../shipstation_settings.js | 22 +--------- .../shipstation_settings.py | 14 +++--- 8 files changed, 98 insertions(+), 46 deletions(-) create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_field/__init__.py create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.js create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.json create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.py create mode 100644 shipstation_integration/shipstation_integration/doctype/shipstation_item_field/test_shipstation_item_field.py diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/__init__.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.js b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.js new file mode 100644 index 0000000..40b906e --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Parsimony LLC and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Shipstation Item Field', { + // refresh: function(frm) { + + // } +}); diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.json b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.json new file mode 100644 index 0000000..b6412ca --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.json @@ -0,0 +1,43 @@ +{ + "actions": [], + "autoname": "format:{fieldname}", + "creation": "2023-03-09 10:18:10.691994", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "fieldname", + "label" + ], + "fields": [ + { + "fieldname": "fieldname", + "fieldtype": "Data", + "label": "Field Name", + "unique": 1 + }, + { + "fieldname": "label", + "fieldtype": "Data", + "label": "Label" + } + ], + "in_create": 1, + "is_virtual": 1, + "links": [], + "modified": "2023-03-09 12:00:57.772150", + "modified_by": "Administrator", + "module": "Shipstation Integration", + "name": "Shipstation Item Field", + "owner": "Administrator", + "permissions": [ + { + "read": 1, + "role": "System Manager" + } + ], + "read_only": 1, + "search_fields": "fieldname,label", + "sort_field": "fieldname", + "sort_order": "DESC", + "title_field": "label" +} \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.py new file mode 100644 index 0000000..1f3491d --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/shipstation_item_field.py @@ -0,0 +1,24 @@ +# Copyright (c) 2023, Parsimony LLC and contributors +# For license information, please see license.txt + +import frappe +import json +from frappe.model.document import Document + + +class ShipstationItemField(Document): + + def get_list(self, args): + return get_item_fields() + +def get_item_fields(search_text=None): + field_list = [ + {"name": f.fieldname, "fieldname": f.fieldname, "label": f.label} + for f in frappe.get_meta("Sales Order Item").fields + if f.fieldtype in ["Data", "Text", "Small Text", "Link", "Select"] + ] + if search_text: + field_list = [ + f for f in field_list if search_text.lower() in f["fieldname"].lower() or search_text.lower() in f["label"].lower() + ] + return field_list \ No newline at end of file diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/test_shipstation_item_field.py b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/test_shipstation_item_field.py new file mode 100644 index 0000000..4a053d9 --- /dev/null +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_item_field/test_shipstation_item_field.py @@ -0,0 +1,8 @@ +# Copyright (c) 2023, Parsimony LLC and Contributors +# See license.txt + +# import frappe +import unittest + +class TestShipstationItemField(unittest.TestCase): + pass diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json index dc6b496..d23597b 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_option/shipstation_option.json @@ -8,8 +8,7 @@ "field_order": [ "shipstation_option_name", "column_break", - "item_field", - "item_field_type" + "item_field" ], "fields": [ { @@ -20,29 +19,21 @@ "reqd": 1 }, { - "fetch_from": "item_field.fieldname", - "fieldname": "item_field", - "fieldtype": "Dynamic Link", - "in_list_view": 1, - "label": "Item Field", - "options": "item_field_type" + "fieldname": "column_break", + "fieldtype": "Column Break" }, { - "default": "DocField", - "fieldname": "item_field_type", + "fieldname": "item_field", "fieldtype": "Link", - "label": "Item Field Type", - "options": "DocType" - }, - { - "fieldname": "column_break", - "fieldtype": "Column Break" + "in_list_view": 1, + "label": "Item Field", + "options": "Shipstation Item Field" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-12-09 17:26:44.554178", + "modified": "2023-03-09 12:03:49.961605", "modified_by": "Administrator", "module": "Shipstation Integration", "name": "Shipstation Option", diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js index 73ee6a2..9c79a17 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.js @@ -22,7 +22,7 @@ frappe.ui.form.on("Shipstation Settings", { frm.set_query("shipping_income_account", "shipstation_stores", company_query); frm.set_query("shipping_expense_account", "shipstation_stores", company_query); frm.set_query("item_field", "options_import", () => ({ - query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_fields" + query: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.item_fields_query" })); // workaround for link validation on the item_field field frappe.meta.get_docfield("Shipstation Option", "item_field", frm.docname).ignore_link_validation = true; @@ -110,26 +110,6 @@ frappe.ui.form.on("Shipstation Settings", { }); -frappe.ui.form.on("Shipstation Option", { - item_field: (frm, cdt, cdn) => { - const row = locals[cdt][cdn]; - const curr_value = row.item_field; - if (row.item_field) { - frappe.call({ - method: "shipstation_integration.shipstation_integration.doctype.shipstation_settings.shipstation_settings.get_item_field_link_type", - args: { - "fieldname": curr_value - }, - callback: r => { - if (r.message) { - frappe.model.set_value(cdt, cdn, "item_field_type", r.message); - } - } - }); - } - } -}); - frappe.ui.form.on("Shipstation Item Custom Field", { before_item_custom_fields_remove: (frm, cdt, cdn) => { const deleted_row = frappe.get_doc(cdt, cdn); diff --git a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py index 2cc1843..20fed5b 100644 --- a/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py +++ b/shipstation_integration/shipstation_integration/doctype/shipstation_settings/shipstation_settings.py @@ -17,6 +17,7 @@ from shipstation_integration.orders import list_orders from shipstation_integration.shipments import list_shipments from shipstation_integration.utils import get_marketplace +from shipstation_integration.shipstation_integration.doctype.shipstation_item_field.shipstation_item_field import get_item_fields class ShipstationSettings(Document): @@ -272,17 +273,14 @@ def update_item_custom_fields(self): frappe.clear_cache(doctype=dt) frappe.db.updatedb(dt) - + @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs -def get_item_fields(doctype, txt, searchfield, start, page_len, filters): - fields = frappe.get_meta("Sales Order Item").fields - fields = [[f.fieldname, f.label] for f in fields if f.fieldtype in ["Data", "Text", "Small Text", "Link", "Select"]] - if txt: - return [f for f in fields if txt.lower() in f[0].lower() or txt.lower() in f[1].lower()] - else: - return fields +def item_fields_query(doctype, txt, searchfield, start, page_len, filters): + field_list = [[f['fieldname'], f['label']] for f in get_item_fields(txt)] + return field_list + @frappe.whitelist() def get_item_field_link_type(fieldname):