def test_order(self):
        # Create Customer
        with open(
                os.path.join(os.path.dirname(__file__), "test_data",
                             "shopify_customer.json")) as shopify_customer:
            shopify_customer = json.load(shopify_customer)
        create_customer(shopify_customer.get("customer"),
                        self.shopify_settings)

        # Create Item
        with open(
                os.path.join(os.path.dirname(__file__), "test_data",
                             "shopify_item.json")) as shopify_item:
            shopify_item = json.load(shopify_item)
        make_item("_Test Warehouse - _TC", shopify_item.get("product"))

        # Create Order
        with open(
                os.path.join(os.path.dirname(__file__), "test_data",
                             "shopify_order.json")) as shopify_order:
            shopify_order = json.load(shopify_order)

        create_order(shopify_order.get("order"),
                     self.shopify_settings,
                     False,
                     company="_Test Company")

        sales_order = frappe.get_doc(
            "Sales Order",
            {"shopify_order_id": cstr(shopify_order.get("order").get("id"))})

        self.assertEqual(cstr(shopify_order.get("order").get("id")),
                         sales_order.shopify_order_id)

        # Check for customer
        shopify_order_customer_id = cstr(
            shopify_order.get("order").get("customer").get("id"))
        sales_order_customer_id = frappe.get_value("Customer",
                                                   sales_order.customer,
                                                   "shopify_customer_id")

        self.assertEqual(shopify_order_customer_id, sales_order_customer_id)

        # Check sales invoice
        sales_invoice = frappe.get_doc(
            "Sales Invoice",
            {"shopify_order_id": sales_order.shopify_order_id})
        self.assertEqual(sales_invoice.rounded_total,
                         sales_order.rounded_total)

        # Check delivery note
        delivery_note_count = frappe.db.sql(
            """select count(*) from `tabDelivery Note`
			where shopify_order_id = %s""",
            sales_order.shopify_order_id,
        )[0][0]

        self.assertEqual(delivery_note_count,
                         len(shopify_order.get("order").get("fulfillments")))
def validate_customer(order, shopify_settings):
    customer_id = order.get("customer", {}).get("id")
    if customer_id:
        if not frappe.db.get_value(
                "Customer", {"shopify_customer_id": customer_id}, "name"):
            create_customer(order.get("customer"), shopify_settings)
def validate_customer(order, shopify_settings):
	customer_id = order.get("customer", {}).get("id")
	if customer_id:
		if not frappe.db.get_value("Customer", {"shopify_customer_id": customer_id}, "name"):
			create_customer(order.get("customer"), shopify_settings)