Merge pull request #21528 from Mangesh-Khairnar/marketplace-fixes

fix: pre-process both the existing and new products
This commit is contained in:
Mangesh-Khairnar 2020-04-30 22:54:57 +05:30 committed by GitHub
commit ec0103453c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -144,17 +144,9 @@ 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(items))
@ -162,8 +154,7 @@ def publish_selected_items(items_to_publish):
# 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:
@ -179,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'))