Skip to content

Commit

Permalink
fix: fetch hsn code from shopify
Browse files Browse the repository at this point in the history
  • Loading branch information
DHINESH00 committed Dec 5, 2024
1 parent 160b119 commit deec150
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"upload_variants_as_items",
"inventory_sync_section",
"warehouse",
"default_item_group",
"update_erpnext_stock_levels_to_shopify",
"inventory_sync_frequency",
"fetch_shopify_locations",
Expand Down Expand Up @@ -387,12 +388,18 @@
"fieldtype": "Link",
"label": "Default Shipping Charges Account",
"options": "Account"
},
{
"fieldname": "default_item_group",
"fieldtype": "Link",
"label": "Default item group",
"options": "Item Group"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-10-24 10:38:49.247431",
"modified": "2024-12-04 19:41:20.719756",
"modified_by": "Administrator",
"module": "shopify",
"name": "Shopify Setting",
Expand Down
21 changes: 21 additions & 0 deletions ecommerce_integrations/shopify/product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

import frappe
import shopify
from frappe import _, msgprint
from frappe.utils import cint, cstr
from frappe.utils.nestedset import get_root_of
Expand Down Expand Up @@ -58,6 +59,8 @@ def sync_product(self):
if not self.is_synced():
shopify_product = Product.find(self.product_id)
product_dict = shopify_product.to_dict()
product_dict = self._update_hsn_sac_code(product_dict)
self._get_item_group(product_dict.get("product_type"))
self._make_item(product_dict)

def _make_item(self, product_dict):
Expand Down Expand Up @@ -137,6 +140,7 @@ def _create_item(self, product_dict, warehouse, has_variant=0, attributes=None,
"weight_uom": WEIGHT_TO_ERPNEXT_UOM_MAP[product_dict.get("weight_unit")],
"weight_per_unit": product_dict.get("weight"),
"default_supplier": self._get_supplier(product_dict),
"gst_hsn_code": product_dict.get("gst_hsn_code"),
}

integration_item_code = product_dict["id"] # shopify product_id
Expand Down Expand Up @@ -174,6 +178,7 @@ def _create_item_variants(self, product_dict, warehouse, attributes):
"item_price": variant.get("price"),
"weight_unit": variant.get("weight_unit"),
"weight": variant.get("weight"),
"gst_hsn_code": product_dict.get("gst_hsn_code"),
}

for i, variant_attr in enumerate(SHOPIFY_VARIANTS_ATTR_LIST):
Expand All @@ -187,6 +192,22 @@ def _create_item_variants(self, product_dict, warehouse, attributes):
)
self._create_item(shopify_item_variant, warehouse, 0, attributes, template_item.name)

def _update_hsn_sac_code(self, product_dict):
try:
for variant in product_dict.get("variants"):
if variant.get("inventory_item_id"):
inventory_item = shopify.InventoryItem.find(variant.get("inventory_item_id"))
if inventory_item.harmonized_system_code:
product_dict["gst_hsn_code"] = inventory_item.harmonized_system_code
break
except Exception:
frappe.log_error(title="_update_hsn_sac_code", message=frappe.get_traceback())
if not (product_dict.get("gst_hsn_code")) and self.setting.default_item_group:
product_dict["gst_hsn_code"] = frappe.db.get_value(
"Item Group", self.setting.default_item_group, "gst_hsn_code"
)
return product_dict

def _get_attribute_value(self, variant_attr_val, attribute):
attribute_value = frappe.db.sql(
"""select attribute_value from `tabItem Attribute Value`
Expand Down

0 comments on commit deec150

Please sign in to comment.