From 7f374e7ba5e653e34e583cc61733ca2fe427d2bb Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 30 Apr 2020 17:55:03 +0530 Subject: [PATCH 1/2] fix: pre-process both the existing and new products --- erpnext/hub_node/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 2035174c98..b260417fbf 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -157,8 +157,9 @@ def publish_selected_items(items_to_publish): existing_items = map_fields(items_to_update) try: - item_sync_preprocess(len(items)) - convert_relative_image_urls_to_absolute(items) + item_sync_preprocess(len(new_items+existing_items)) + convert_relative_image_urls_to_absolute(new_items) + convert_relative_image_urls_to_absolute(existing_items) # TODO: Publish Progress connection = get_hub_connection() From 367b644d9eeb3c9d60fed7523a1ca29174f85c56 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Thu, 30 Apr 2020 20:31:12 +0530 Subject: [PATCH 2/2] fix: delete hub tracked item on unpublish --- erpnext/hub_node/api.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index b260417fbf..42f90006f4 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -144,27 +144,17 @@ def publish_selected_items(items_to_publish): 'hub_category': item.get('hub_category'), 'image_list': item.get('image_list') } - if frappe.db.exists('Hub Tracked Item', item_code): - items_to_update.append(item) - hub_tracked_item = frappe.get_doc('Hub Tracked Item', item_code) - hub_tracked_item.update(hub_dict) - hub_tracked_item.save() - else: - frappe.get_doc(hub_dict).insert(ignore_if_duplicate=True) + frappe.get_doc(hub_dict).insert(ignore_if_duplicate=True) - items_to_publish = list(filter(lambda x: x not in items_to_update, items_to_publish)) - new_items = map_fields(items_to_publish) - existing_items = map_fields(items_to_update) + items = map_fields(items_to_publish) try: - item_sync_preprocess(len(new_items+existing_items)) - convert_relative_image_urls_to_absolute(new_items) - convert_relative_image_urls_to_absolute(existing_items) + item_sync_preprocess(len(items)) + convert_relative_image_urls_to_absolute(items) # TODO: Publish Progress connection = get_hub_connection() - connection.insert_many(new_items) - connection.bulk_update(existing_items) + connection.insert_many(items) item_sync_postprocess() except Exception as e: @@ -180,6 +170,7 @@ def unpublish_item(item_code, hub_item_name): if response: frappe.db.set_value('Item', item_code, 'publish_in_hub', 0) + frappe.delete_doc('Hub Tracked Item', item_code) else: frappe.throw(_('Unable to update remote activity'))