frappe / frappe/ecommerce_integrations

When Syncing from Shopify, drop ship is not correctly checked

Open
#352 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
206
Forks
275
Avg merge
54m
Merged PRs (30d)
1

Description

# Issue

In the Shopify integration, when an order is placed, even if the item is set to be drop shipped and has a default supplier, the `delivered_by_supplier` field will not be checked. And this flag cannot be changed after the order is submitted, which is extremely problematic for our fulfillment team.

For example:

Here are two items:

Here is one that has the drop ship flag set and has a default supplier:
![Image](https://github.com/user-attachments/assets/f5b141f1-03ec-4826-a727-e7c91ba2a7de)
And an item that does not have the flag set and has no supplier:
![Image](https://github.com/user-attachments/assets/3a0d2ea7-e327-4fab-b4f1-bf775c724946)

We place an order in a shopify store for these two items:
![Image](https://github.com/user-attachments/assets/8a1975cb-5b6e-4bd0-8483-d4cae50535d6)

The order is correctly synced to ERP:
![Image](https://github.com/user-attachments/assets/def51566-213e-4a5b-9060-205b3f3bdd75)

Except that the boiler item does not have the dropship flag set, but does have a supplier set:
![Image](https://github.com/user-attachments/assets/198a8f42-786d-49a3-84fa-5b2163354280)

# Solution

The solution is relatively simple. In the `get_order_items()` method in ecommerce_integrations, we simply check for the flag and include it in the created item:

```Python
def get_order_items(order_items, setting, delivery_date, taxes_inclusive):
   items = []
   all_product_exists = True
   product_not_exists = []

   for shopify_item in order_items:
       if not shopify_item.get("product_exists"):
           all_product_exists = False
           product_not_exists.append(
               {"title": shopify_item.get("title"), ORDER_ID_FIELD: shopify_item.get("id")}
           )
           continue

       if all_product_exists:
           item_code = get_item_code(shopify_item)
           erp_item = frappe.get_doc('Item', item_code)
           suppliers = erp_item.get("supplier_items")
           drop_shipped = erp_item.get("delivered_by_supplier") and len(suppliers) > 0
           items.append(
               {
                   "item_code": item_code,
                   "item_name": shopify_item.get("name"),
                   "rate": _get_item_price(shopify_item, taxes_inclusive),
                   "delivery_date": delivery_date,
                   "qty": shopify_item.get("quantity"),
                   "stock_uom": shopify_item.get("uom") or "Nos",
                   "warehouse": setting.warehouse,
                   "delivered_by_supplier": 1 if drop_shipped else 0, # If the flag is true, we set to 1 otherwise, 0
                   "supplier": suppliers[0] if drop_shipped else "",      # If the flag is true, set to the name of the supplier, otherwise blank
                   ORDER_ITEM_DISCOUNT_FIELD: (
                       _get_total_discount(shopify_item) / cint(shopify_item.get("quantity"))
                   ),
               }
           )
       else:
           items = []

   return items

```

I have tested this solution in our testbed and it appears to work as intended. I have not verified that unit tests still pass. Please consider working with me on this issue because it would really streamline the way our ERP processes work.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.