Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: metadata import #57

Open
wants to merge 25 commits into
base: main-v13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
839ac10
1st round of changes for metadata import
batonac Jul 19, 2022
262a8c9
finish the metadata sync code
batonac Aug 17, 2022
8cf4a3f
Merge pull request #1 from ParsimonyGit/master
batonac Aug 17, 2022
e370776
increase order retrieval time
batonac Aug 30, 2022
b28c7a3
skip item if qty is 0 (refunded items)
batonac Sep 21, 2022
2b003bd
create custom fields function
batonac Sep 21, 2022
43ba3f5
cleanup
batonac Sep 21, 2022
f6d8512
cleanup
batonac Sep 21, 2022
8859e63
version bump
batonac Sep 21, 2022
0aa5d2f
Merge remote-tracking branch 'upstream/master' into metadata_import
Oct 18, 2022
6075ad0
Merge branch 'ParsimonyGit:master' into metadata_import
batonac Nov 15, 2022
d07aed8
new layout, item field linking
batonac Nov 15, 2022
61e4846
revert link field for now
batonac Nov 16, 2022
3b6dcef
more link revert (for now)
batonac Nov 16, 2022
3aa36aa
fix link field, tweak layouts, custom field updater
batonac Nov 16, 2022
e73abf4
tweak label
batonac Nov 16, 2022
06f0c16
import new options to the Options Import table
batonac Nov 16, 2022
db0549d
item option assignment check
batonac Nov 16, 2022
5d20970
new hours_to_fetch field
batonac Nov 16, 2022
fef54b9
better naming conventions
batonac Dec 9, 2022
7304454
more naming updates
batonac Dec 9, 2022
3897154
Merge remote-tracking branch 'upstream/master' into metadata_import
Dec 27, 2022
b7ace61
Merge branch 'ParsimonyGit:main-v13' into metadata_import
batonac Mar 9, 2023
5f6027e
jslint updates
batonac Mar 9, 2023
cfed056
migrate Item Field Link to Virtual DocType
batonac Mar 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shipstation_integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '0.0.1'
__version__ = '0.0.2'

28 changes: 21 additions & 7 deletions shipstation_integration/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=sss_doc.get("hours_to_fetch", 24)
)

store: "ShipstationStore"
Expand Down Expand Up @@ -201,17 +201,15 @@ 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 < 1:
continue

settings = frappe.get_doc("Shipstation Settings", store.parent)
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"),
Expand All @@ -220,8 +218,24 @@ 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"])
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
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)

if not so.get("items"):
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-07-06 12:17:13.829719",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"label",
"fieldtype",
"fieldname",
"length",
"reqd",
"hidden",
"read_only",
"column_break_8",
"options",
"default",
"fetch_from",
"fetch_if_empty"
],
"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": "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"
},
{
"depends_on": "eval:in_list(['Data', 'Link', 'Dynamic Link', 'Password', 'Select', 'Read Only', 'Attach', 'Attach Image', 'Int'], doc.fieldtype)",
"fieldname": "length",
"fieldtype": "Int",
"label": "Length"
},
{
"fieldname": "column_break_8",
"fieldtype": "Column Break"
},
{
"fieldname": "default",
"fieldtype": "Small Text",
"label": "Default"
},
{
"fieldname": "fetch_from",
"fieldtype": "Small Text",
"label": "Fetch From"
},
{
"default": "0",
"fieldname": "fetch_if_empty",
"fieldtype": "Check",
"label": "Fetch If Empty"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-11-16 14:14:12.504952",
"modified_by": "Administrator",
"module": "Shipstation Integration",
"name": "Shipstation Item Custom Fields",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2022-07-05 14:43:09.827242",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"shipstation_option_name",
"column_break_2",
"sales_order_item_field",
"sales_order_item_field_type"
],
"fields": [
{
"fieldname": "shipstation_option_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "ShipStation Option Name",
"reqd": 1
},
{
"fetch_from": "sales_order_item_field.fieldname",
"fieldname": "sales_order_item_field",
"fieldtype": "Dynamic Link",
"in_list_view": 1,
"label": "Sales Order Item Field",
"options": "sales_order_item_field_type"
},
{
"default": "DocField",
"fieldname": "sales_order_item_field_type",
"fieldtype": "Link",
"hidden": 1,
"label": "Sales Order 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_by": "Administrator",
"module": "Shipstation Integration",
"name": "Shipstation Options Import",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}
Original file line number Diff line number Diff line change
@@ -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
Loading