Skip to content

Commit

Permalink
feat(shopify): sync shopify selling rate (frappe#221)
Browse files Browse the repository at this point in the history
* ci: fix flake8 URL

* feat(shopify): sync shopify selling rate

* fix(test): selling rate field in custom field test
  • Loading branch information
rtdany10 committed Dec 12, 2022
1 parent 7631a85 commit 3ae06a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -26,8 +26,8 @@ repos:
- id: isort
exclude: ".*setup.py$"

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-isort]
Expand Down
1 change: 1 addition & 0 deletions ecommerce_integrations/shopify/constants.py
Expand Up @@ -36,6 +36,7 @@
SUPPLIER_ID_FIELD = "shopify_supplier_id"
ADDRESS_ID_FIELD = "shopify_address_id"
ORDER_ITEM_DISCOUNT_FIELD = "shopify_item_discount"
ITEM_SELLING_RATE_FIELD = "shopify_selling_rate"

# ERPNext already defines the default UOMs from Shopify but names are different
WEIGHT_TO_ERPNEXT_UOM_MAP = {"kg": "Kg", "g": "Gram", "oz": "Ounce", "lb": "Pound"}
Expand Up @@ -20,6 +20,7 @@
ADDRESS_ID_FIELD,
CUSTOMER_ID_FIELD,
FULLFILLMENT_ID_FIELD,
ITEM_SELLING_RATE_FIELD,
ORDER_ID_FIELD,
ORDER_ITEM_DISCOUNT_FIELD,
ORDER_NUMBER_FIELD,
Expand Down Expand Up @@ -113,6 +114,14 @@ def get_integration_to_erpnext_wh_mapping(self) -> Dict[IntegrationWarehouse, ER

def setup_custom_fields():
custom_fields = {
"Item": [
dict(
fieldname=ITEM_SELLING_RATE_FIELD,
label="Shopify Selling Rate",
fieldtype="Currency",
insert_after="standard_rate",
)
],
"Customer": [
dict(
fieldname=CUSTOMER_ID_FIELD,
Expand Down
Expand Up @@ -9,6 +9,7 @@
ADDRESS_ID_FIELD,
CUSTOMER_ID_FIELD,
FULLFILLMENT_ID_FIELD,
ITEM_SELLING_RATE_FIELD,
ORDER_ID_FIELD,
ORDER_ITEM_DISCOUNT_FIELD,
ORDER_NUMBER_FIELD,
Expand Down Expand Up @@ -40,6 +41,7 @@ def test_custom_field_creation(self):
ADDRESS_ID_FIELD,
CUSTOMER_ID_FIELD,
FULLFILLMENT_ID_FIELD,
ITEM_SELLING_RATE_FIELD,
ORDER_ID_FIELD,
ORDER_NUMBER_FIELD,
ORDER_STATUS_FIELD,
Expand Down
19 changes: 13 additions & 6 deletions ecommerce_integrations/shopify/product.py
Expand Up @@ -9,6 +9,7 @@
from ecommerce_integrations.ecommerce_integrations.doctype.ecommerce_item import ecommerce_item
from ecommerce_integrations.shopify.connection import temp_shopify_session
from ecommerce_integrations.shopify.constants import (
ITEM_SELLING_RATE_FIELD,
MODULE_NAME,
SETTING_DOCTYPE,
SHOPIFY_VARIANTS_ATTR_LIST,
Expand Down Expand Up @@ -375,13 +376,17 @@ def upload_erpnext_item(doc, method=None):
update_default_variant_properties(
product,
sku=template_item.item_code,
price=template_item.standard_rate,
price=template_item.get(ITEM_SELLING_RATE_FIELD),
is_stock_item=template_item.is_stock_item,
)
if item.variant_of:
product.options = []
product.variants = []
variant_attributes = {"title": template_item.item_name}
variant_attributes = {
"title": template_item.item_name,
"sku": item.item_code,
"price": item.get(ITEM_SELLING_RATE_FIELD),
}
max_index_range = min(3, len(template_item.attributes))
for i in range(0, max_index_range):
attr = template_item.attributes[i]
Expand Down Expand Up @@ -422,10 +427,12 @@ def upload_erpnext_item(doc, method=None):
product = Product.find(product_id)
if product:
map_erpnext_item_to_shopify(shopify_product=product, erpnext_item=template_item)
update_default_variant_properties(product, is_stock_item=template_item.is_stock_item)

variant_attributes = {}
if item.variant_of:
if not item.variant_of:
update_default_variant_properties(
product, is_stock_item=template_item.is_stock_item, price=item.get(ITEM_SELLING_RATE_FIELD)
)
else:
variant_attributes = {"sku": item.item_code, "price": item.get(ITEM_SELLING_RATE_FIELD)}
product.options = []
max_index_range = min(3, len(template_item.attributes))
for i in range(0, max_index_range):
Expand Down

0 comments on commit 3ae06a6

Please sign in to comment.