diff --git a/shopify_integration/fulfilments.py b/shopify_integration/fulfilments.py index 62dca03..c8ae22c 100644 --- a/shopify_integration/fulfilments.py +++ b/shopify_integration/fulfilments.py @@ -127,7 +127,8 @@ def update_fulfillment_items( fulfillment_items: List["LineItem"] ): for dn_item in dn_items: + # TODO: figure out a better way to add items without setting valuation rate to zero + dn_item.allow_zero_valuation_rate = True for item in fulfillment_items: if get_item_code(item) == dn_item.item_code: - # TODO: figure out a better way to add items without setting valuation rate to zero - dn_item.update({"qty": item.attributes.get("quantity"), "allow_zero_valuation_rate": 1}) + dn_item.qty = item.attributes.get("quantity") diff --git a/shopify_integration/orders.py b/shopify_integration/orders.py index 641387b..a99bf94 100644 --- a/shopify_integration/orders.py +++ b/shopify_integration/orders.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING, List import frappe -from frappe.utils import flt, nowdate +from frappe.utils import flt, getdate, nowdate from shopify_integration.shopify_integration.doctype.shopify_log.shopify_log import make_shopify_log from shopify_integration.utils import get_shopify_document, get_tax_account_head @@ -98,12 +98,12 @@ def create_sales_order(shop_name: str, shopify_order: "Order"): "shopify_order_id": shopify_order.id, "shopify_order_number": shopify_order.attributes.get("order_number"), "customer": customer or shopify_settings.default_customer, - "transaction_date": shopify_order.attributes.get("created_at"), - "delivery_date": shopify_order.attributes.get("created_at"), + "transaction_date": getdate(shopify_order.attributes.get("created_at")), + "delivery_date": getdate(shopify_order.attributes.get("created_at")), "company": shopify_settings.company, "selling_price_list": shopify_settings.price_list, "ignore_pricing_rule": 1, - "items": get_order_items(shopify_order.attributes.get("line_items"), shopify_settings.warehouse), + "items": get_order_items(shopify_order.attributes.get("line_items", []), shopify_settings), "taxes": get_order_taxes(shopify_order, shopify_settings), "apply_discount_on": "Grand Total", "discount_amount": flt(shopify_order.attributes.get("total_discounts")), @@ -116,21 +116,25 @@ def create_sales_order(shop_name: str, shopify_order: "Order"): return sales_order -def get_order_items(shopify_order_items: List["LineItem"], warehouse: str): +def get_order_items(shopify_order_items: List["LineItem"], shopify_settings: "ShopifySettings"): from shopify_integration.products import get_item_code items = [] for shopify_item in shopify_order_items: item_code = get_item_code(shopify_item) + item_group = frappe.db.get_value("Item", item_code, "item_group") or \ + shopify_settings.item_group + items.append({ "item_code": item_code, "item_name": shopify_item.attributes.get("name"), + "item_group": item_group, "rate": shopify_item.attributes.get("price"), "delivery_date": nowdate(), "qty": shopify_item.attributes.get("quantity"), "stock_uom": shopify_item.attributes.get("uom") or "Nos", "conversion_factor": 1, - "warehouse": warehouse + "warehouse": shopify_settings.warehouse }) return items diff --git a/shopify_integration/products.py b/shopify_integration/products.py index 39ee2d4..27f906f 100644 --- a/shopify_integration/products.py +++ b/shopify_integration/products.py @@ -350,7 +350,7 @@ def create_item( 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) + new_item.insert(ignore_permissions=True) # once the defaults have been generated, set the item supplier from Shopify supplier = get_supplier(shopify_settings, shopify_item) @@ -560,7 +560,6 @@ def is_item_exists( return False item: "Item" = frappe.get_doc("Item", name) - item.flags.ignore_mandatory = True if not variant_of and not item.shopify_product_id: item.shopify_product_id = shopify_item.get("shopify_product_id") @@ -600,7 +599,6 @@ def is_item_exists( if parent: variant: "Item" = frappe.get_doc("Item", parent[0]) - variant.flags.ignore_mandatory = True variant.shopify_product_id = shopify_item.get("shopify_product_id") variant.shopify_variant_id = shopify_item.get("shopify_variant_id") diff --git a/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.js b/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.js index 4c90318..3bc8440 100644 --- a/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.js +++ b/shopify_integration/shopify_integration/doctype/shopify_settings/shopify_settings.js @@ -57,6 +57,7 @@ frappe.ui.form.on("Shopify Settings", { callback: function (r) { if (!r.exc) { frappe.msgprint(__("Product sync has been queued. This may take a few minutes.")); + frm.reload_doc(); } else { frappe.msgprint(__("Something went wrong while trying to sync products. Please check the latest Shopify logs.")) } @@ -73,7 +74,7 @@ frappe.ui.form.on("Shopify Settings", { "label": __("Payout Start Date"), "description": __("Defaults to the 'Last Sync Datetime' field"), "default": frm.doc.last_sync_datetime, - "reqd": 1, + "reqd": 1 } ], (values) => { @@ -86,6 +87,7 @@ frappe.ui.form.on("Shopify Settings", { callback: function (r) { if (!r.exc) { frappe.msgprint(__("Payout sync has been queued. This may take a few minutes.")); + frm.reload_doc(); } else { frappe.msgprint(__("Something went wrong while trying to sync payouts. Please check the latest Shopify logs.")) }