Skip to content

Commit

Permalink
fix: include template item name while creating variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchez authored Mar 16, 2021
1 parent a6d02f0 commit c9e5feb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions shopify_integration/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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 [],
Expand All @@ -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

Expand Down

0 comments on commit c9e5feb

Please sign in to comment.