Skip to content

Commit ef81a52

Browse files
authored
Merge pull request #192 from ankush/next_release
chore: release
2 parents ab262f7 + bed6992 commit ef81a52

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

ecommerce_integrations/ecommerce_integrations/doctype/ecommerce_integration_log/ecommerce_integration_log.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import frappe
77
from frappe import _
88
from frappe.model.document import Document
9+
from frappe.query_builder import Interval
10+
from frappe.query_builder.functions import Now
911
from frappe.utils import strip_html
1012
from frappe.utils.data import cstr
1113

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

32+
@staticmethod
33+
def clear_old_logs(days=90):
34+
table = frappe.qb.DocType("Ecommerce Integration Log")
35+
frappe.db.delete(
36+
table, filters=((table.modified < (Now() - Interval(days=days)))) & (table.status == "Success")
37+
)
38+
3039

3140
def create_log(
3241
module_def=None,

ecommerce_integrations/shopify/doctype/shopify_setting/shopify_setting.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ frappe.ui.form.on("Shopify Setting", {
3131
frm.add_custom_button(__('Import Products'), function () {
3232
frappe.set_route('shopify-import-products');
3333
});
34+
frm.add_custom_button(__("View Logs"), () => {
35+
frappe.set_route("List", "Ecommerce Integration Log", {"integration": "Shopify"});
36+
});
3437
}
3538
});
3639

ecommerce_integrations/unicommerce/api_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def request(
4343
body: Optional[JsonDict] = None,
4444
params: Optional[JsonDict] = None,
4545
files: Optional[JsonDict] = None,
46+
log_error=True,
4647
) -> Tuple[JsonDict, bool]:
4748

4849
if headers is None:
@@ -60,7 +61,8 @@ def request(
6061
response.reason = cstr(response.reason) + cstr(response.text)
6162
response.raise_for_status()
6263
except Exception:
63-
create_unicommerce_log(status="Error", make_new=True)
64+
if log_error:
65+
create_unicommerce_log(status="Error", make_new=True)
6466
return None, False
6567

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

8284
return data, status
8385

84-
def get_unicommerce_item(self, sku: str) -> Optional[JsonDict]:
86+
def get_unicommerce_item(self, sku: str, log_error=True) -> Optional[JsonDict]:
8587
"""Get Unicommerce item data for specified SKU code.
8688
8789
ref: https://documentation.unicommerce.com/docs/itemtype-get.html
8890
"""
8991
item, status = self.request(
90-
endpoint="/services/rest/v1/catalog/itemType/get", body={"skuCode": sku}
92+
endpoint="/services/rest/v1/catalog/itemType/get", body={"skuCode": sku}, log_error=log_error
9193
)
9294
if status:
9395
return item

ecommerce_integrations/unicommerce/doctype/unicommerce_settings/unicommerce_settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ frappe.ui.form.on("Unicommerce Settings", {
88
}
99

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

1414
let sync_buttons = ["Items", "Orders", "Inventory"];

ecommerce_integrations/unicommerce/order.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def sync_new_orders(client: UnicommerceAPIClient = None, force=False):
4848

4949
status = "COMPLETE" if settings.only_sync_completed_orders else None
5050

51-
new_orders = _get_new_orders(
52-
client, from_date=add_to_date(settings.last_order_sync, days=-1), status=status
53-
)
51+
new_orders = _get_new_orders(client, status=status)
5452

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

6462

6563
def _get_new_orders(
66-
client: UnicommerceAPIClient, from_date: str, status: Optional[str]
64+
client: UnicommerceAPIClient, status: Optional[str]
6765
) -> Optional[Iterator[UnicommerceOrder]]:
6866

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

71-
uni_orders = client.search_sales_order(from_date=from_date, status=status)
69+
updated_since = 24 * 60 # minutes
70+
uni_orders = client.search_sales_order(updated_since=updated_since, status=status)
7271
configured_channels = {
7372
c.channel_id
7473
for c in frappe.get_all("Unicommerce Channel", filters={"enabled": 1}, fields="channel_id")

ecommerce_integrations/unicommerce/product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def upload_items_to_unicommerce(
247247
item_data = _build_unicommerce_item(item_code)
248248
sku = item_data.get("skuCode")
249249

250-
item_exists = bool(client.get_unicommerce_item(sku))
250+
item_exists = bool(client.get_unicommerce_item(sku, log_error=False))
251251
_, status = client.create_update_item(item_data, update=item_exists)
252252

253253
if status:

0 commit comments

Comments
 (0)