Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exclude: 'node_modules|.git'
default_stages: [commit]
default_stages: [pre-commit]
fail_fast: false


Expand Down
37 changes: 13 additions & 24 deletions ecommerce_integrations/shopify/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def migrate_from_old_connector(payload=None, request_id=None):
status="Queued",
method="ecommerce_integrations.shopify.utils.migrate_from_old_connector",
)

frappe.enqueue(
method=_migrate_items_to_ecommerce_item,
queue="long",
Expand All @@ -51,12 +50,6 @@ def ensure_old_connector_is_disabled():


def _migrate_items_to_ecommerce_item(log):
shopify_fields = ["shopify_product_id", "shopify_variant_id"]

for field in shopify_fields:
if not frappe.db.exists({"doctype": "Custom Field", "fieldname": field}):
return

items = _get_items_to_migrate()

try:
Expand All @@ -76,30 +69,26 @@ def _get_items_to_migrate() -> list[_dict]:
"""get all list of items that have shopify fields but do not have associated ecommerce item."""

old_data = frappe.db.sql(
"""SELECT item.name as erpnext_item_code, shopify_product_id, shopify_variant_id, item.variant_of, item.has_variants
FROM tabItem item
LEFT JOIN `tabEcommerce Item` ei on ei.erpnext_item_code = item.name
WHERE ei.erpnext_item_code IS NULL AND shopify_product_id IS NOT NULL""",
"""
SELECT item.name AS erpnext_item_code
FROM tabItem item
WHERE item.name NOT IN (
SELECT ei.erpnext_item_code FROM `tabEcommerce Item` ei
)
""",
as_dict=True,
)

return old_data or []


def _create_ecommerce_items(items: list[_dict]) -> None:
from ecommerce_integrations.shopify.product import upload_erpnext_item

for item in items:
if not all((item.erpnext_item_code, item.shopify_product_id, item.shopify_variant_id)):
if not item.erpnext_item_code:
continue

ecommerce_item = frappe.get_doc(
{
"doctype": "Ecommerce Item",
"integration": MODULE_NAME,
"erpnext_item_code": item.erpnext_item_code,
"integration_item_code": item.shopify_product_id,
"variant_id": item.shopify_variant_id,
"variant_of": item.variant_of,
"has_variants": item.has_variants,
}
)
ecommerce_item.save()
doc = frappe.get_doc("Item", item.erpnext_item_code)

upload_erpnext_item(doc)