Skip to content

Commit

Permalink
Merge pull request #192 from ankush/next_release
Browse files Browse the repository at this point in the history
chore: release
  • Loading branch information
ankush authored Jun 27, 2022
2 parents ab262f7 + bed6992 commit ef81a52
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.query_builder import Interval
from frappe.query_builder.functions import Now
from frappe.utils import strip_html
from frappe.utils.data import cstr

Expand All @@ -27,6 +29,13 @@ def _set_title(self):
title = strip_html(title)
self.title = title if len(title) < 100 else title[:100] + "..."

@staticmethod
def clear_old_logs(days=90):
table = frappe.qb.DocType("Ecommerce Integration Log")
frappe.db.delete(
table, filters=((table.modified < (Now() - Interval(days=days)))) & (table.status == "Success")
)


def create_log(
module_def=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ frappe.ui.form.on("Shopify Setting", {
frm.add_custom_button(__('Import Products'), function () {
frappe.set_route('shopify-import-products');
});
frm.add_custom_button(__("View Logs"), () => {
frappe.set_route("List", "Ecommerce Integration Log", {"integration": "Shopify"});
});
}
});

Expand Down
8 changes: 5 additions & 3 deletions ecommerce_integrations/unicommerce/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def request(
body: Optional[JsonDict] = None,
params: Optional[JsonDict] = None,
files: Optional[JsonDict] = None,
log_error=True,
) -> Tuple[JsonDict, bool]:

if headers is None:
Expand All @@ -60,7 +61,8 @@ def request(
response.reason = cstr(response.reason) + cstr(response.text)
response.raise_for_status()
except Exception:
create_unicommerce_log(status="Error", make_new=True)
if log_error:
create_unicommerce_log(status="Error", make_new=True)
return None, False

if method == "GET" and "application/json" not in response.headers.get("content-type"):
Expand All @@ -81,13 +83,13 @@ def request(

return data, status

def get_unicommerce_item(self, sku: str) -> Optional[JsonDict]:
def get_unicommerce_item(self, sku: str, log_error=True) -> Optional[JsonDict]:
"""Get Unicommerce item data for specified SKU code.
ref: https://documentation.unicommerce.com/docs/itemtype-get.html
"""
item, status = self.request(
endpoint="/services/rest/v1/catalog/itemType/get", body={"skuCode": sku}
endpoint="/services/rest/v1/catalog/itemType/get", body={"skuCode": sku}, log_error=log_error
)
if status:
return item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ frappe.ui.form.on("Unicommerce Settings", {
}

frm.add_custom_button(__("View Logs"), () => {
frappe.set_route("List", "Ecommerce Integration Log", "List");
frappe.set_route("List", "Ecommerce Integration Log", {"integration": "Unicommerce"});
});

let sync_buttons = ["Items", "Orders", "Inventory"];
Expand Down
9 changes: 4 additions & 5 deletions ecommerce_integrations/unicommerce/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def sync_new_orders(client: UnicommerceAPIClient = None, force=False):

status = "COMPLETE" if settings.only_sync_completed_orders else None

new_orders = _get_new_orders(
client, from_date=add_to_date(settings.last_order_sync, days=-1), status=status
)
new_orders = _get_new_orders(client, status=status)

if new_orders is None:
return
Expand All @@ -63,12 +61,13 @@ def sync_new_orders(client: UnicommerceAPIClient = None, force=False):


def _get_new_orders(
client: UnicommerceAPIClient, from_date: str, status: Optional[str]
client: UnicommerceAPIClient, status: Optional[str]
) -> Optional[Iterator[UnicommerceOrder]]:

"""Search new sales order from unicommerce."""

uni_orders = client.search_sales_order(from_date=from_date, status=status)
updated_since = 24 * 60 # minutes
uni_orders = client.search_sales_order(updated_since=updated_since, status=status)
configured_channels = {
c.channel_id
for c in frappe.get_all("Unicommerce Channel", filters={"enabled": 1}, fields="channel_id")
Expand Down
2 changes: 1 addition & 1 deletion ecommerce_integrations/unicommerce/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def upload_items_to_unicommerce(
item_data = _build_unicommerce_item(item_code)
sku = item_data.get("skuCode")

item_exists = bool(client.get_unicommerce_item(sku))
item_exists = bool(client.get_unicommerce_item(sku, log_error=False))
_, status = client.create_update_item(item_data, update=item_exists)

if status:
Expand Down

0 comments on commit ef81a52

Please sign in to comment.