Skip to content

Commit

Permalink
fix: bugs introduced in revamp (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchez authored Apr 30, 2021
1 parent 7d3e25e commit d95a021
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions shopify_integration/fulfilments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
16 changes: 10 additions & 6 deletions shopify_integration/orders.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")),
Expand All @@ -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

Expand Down
4 changes: 1 addition & 3 deletions shopify_integration/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
}
Expand All @@ -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) => {
Expand All @@ -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."))
}
Expand Down

0 comments on commit d95a021

Please sign in to comment.