From c9e5febd8460ad0cd107897eb62250368c1affcd Mon Sep 17 00:00:00 2001 From: Rohan Date: Tue, 16 Mar 2021 14:10:28 +0530 Subject: [PATCH] fix: include template item name while creating variants --- shopify_integration/products.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/shopify_integration/products.py b/shopify_integration/products.py index 6c155e0..a64b62e 100644 --- a/shopify_integration/products.py +++ b/shopify_integration/products.py @@ -157,6 +157,9 @@ def set_new_attribute_values(item_attr, values): def create_item(shopify_item, warehouse, has_variant=False, attributes=None, variant_of=None): + item_title = shopify_item.get("title", "").strip() + item_name = f"{variant_of} - {item_title}" if variant_of else item_title + item_dict = { "doctype": "Item", "shopify_product_id": shopify_item.get("product_id"), @@ -165,10 +168,10 @@ def create_item(shopify_item, warehouse, has_variant=False, attributes=None, var "variant_of": variant_of, "sync_with_shopify": 1, "is_stock_item": 1, - "item_code": cstr(shopify_item.get("item_code")) or shopify_item.get("title", "").strip(), - "item_name": shopify_item.get("title", "").strip(), - "description": shopify_item.get("body_html") or shopify_item.get("title"), - "shopify_description": shopify_item.get("body_html") or shopify_item.get("title"), + "item_code": cstr(shopify_item.get("item_code")) or item_title, + "item_name": item_name, + "description": shopify_item.get("body_html") or item_title, + "shopify_description": shopify_item.get("body_html") or item_title, "item_group": get_item_group(shopify_item.get("product_type")), "has_variants": has_variant, "attributes": attributes or [], @@ -192,6 +195,13 @@ def create_item(shopify_item, warehouse, has_variant=False, attributes=None, var if not item_details: new_item = frappe.get_doc(item_dict) + + # this fails during the `validate_name_with_item_group` call in item.py + # if the item name matches with an existing item group; for such cases, + # appending the item group into the item name + if frappe.db.exists("Item Group", new_item.item_code): + new_item.item_code = f"{new_item.item_code} ({new_item.item_group})" + new_item.insert(ignore_permissions=True, ignore_mandatory=True) item_code = new_item.name