Skip to content

Commit

Permalink
feat: create Shipment for shipstation shipments (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
MyuddinKhatri authored Sep 29, 2022
1 parent 0d6d271 commit f0b73da
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 69 deletions.
3 changes: 2 additions & 1 deletion shipstation_integration/patches.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
shipstation_integration.patches.set_enable_checks_in_shipstation_store
shipstation_integration.patches.update_shipstation_warehouses
shipstation_integration.patches.update_shipstation_warehouses
shipstation_integration.patches.delete_delivery_note_shipment_custom_fields
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import frappe


def execute():
delivery_note_custom_fields = [
'Delivery Note-shipment_details',
'Delivery Note-sb_shipment',
'Delivery Note-carrier',
'Delivery Note-tracking_number',
'Delivery Note-cb_shipment',
'Delivery Note-carrier_service'
]
for custom_field in delivery_note_custom_fields:
frappe.delete_doc_if_exists("Custom Field", custom_field)
121 changes: 84 additions & 37 deletions shipstation_integration/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import frappe
from frappe import _
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from frappe.custom.doctype.property_setter.property_setter import make_property_setter


def get_setup_stages(args=None):
Expand Down Expand Up @@ -244,46 +245,46 @@ def setup_custom_fields(args=None):
label="Shipstation Shipment ID",
insert_after="shipstation_order_id",
translatable=False,
),
dict(
fieldtype="Section Break",
fieldname="sb_shipment",
collapsible=True,
label="Shipment Details",
insert_after="has_pii",
),
dict(
fieldtype="Data",
fieldname="carrier",
read_only=True,
label="Carrier",
insert_after="sb_shipment",
translatable=False,
),
dict(
fieldtype="Data",
fieldname="tracking_number",
read_only=True,
label="Tracking Number",
insert_after="carrier",
translatable=False,
),
dict(
fieldtype="Column Break",
fieldname="cb_shipment",
insert_after="tracking_number",
),
dict(
fieldtype="Data",
fieldname="carrier_service",
read_only=True,
label="Carrier Service",
insert_after="cb_shipment",
translatable=False,
),
)
]
)

shipment_fields = [
dict(
fieldtype="Data",
fieldname="shipstation_store_name",
read_only=True,
label="Shipstation Store",
insert_after="shipment_amount",
translatable=False,
),
dict(
fieldtype="Data",
fieldname="shipstation_order_id",
read_only=True,
label="Shipstation Order ID",
insert_after="shipstation_store_name",
in_standard_filter=True,
translatable=False,
),
dict(
fieldtype="Data",
fieldname="marketplace",
read_only=True,
label="Marketplace",
insert_after="awb_number",
translatable=False,
),
dict(
fieldtype="Data",
fieldname="marketplace_order_id",
read_only=True,
label="Marketplace Order ID",
insert_after="marketplace",
translatable=False,
)
]

custom_fields = {
"Item": item_fields,
"Warehouse": warehouse_fields,
Expand All @@ -293,7 +294,53 @@ def setup_custom_fields(args=None):
"Sales Invoice Item": common_custom_sales_item_fields,
"Delivery Note": delivery_note_fields,
"Delivery Note Item": common_custom_sales_item_fields,
"Shipment": shipment_fields,
}

print("Creating custom fields for Shipstation")
create_custom_fields(custom_fields)

property_setters = [
dict(
doctype="Shipment Parcel",
fieldname="length",
property="label",
property_type="Text",
value="Length (Inch)",
),
dict(
doctype="Shipment Parcel",
fieldname="width",
property="label",
property_type="Text",
value="Width (Inch)",
),
dict(
doctype="Shipment Parcel",
fieldname="height",
property="label",
property_type="Text",
value="Height (Inch)",
),
dict(
doctype="Shipment Parcel",
fieldname="weight",
property="label",
property_type="Text",
value="Weight (Ounce)",
)
]

print("Creating property setters for Shipstation")
for property_setter in property_setters:
if not frappe.db.exists(
"Property Setter",
dict(
doc_type=property_setter.get("doctype"),
field_name=property_setter.get("fieldname"),
property=property_setter.get("property"),
property_type=property_setter.get("property_type"),
value=property_setter.get("value"),
),
):
make_property_setter(**property_setter)
Loading

0 comments on commit f0b73da

Please sign in to comment.