From 8287c3d05a67065c1e494d3679fc2e9c6ab13cb0 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Fri, 29 Nov 2019 15:52:29 +0530 Subject: [PATCH] feat(marketplace): unpublish item from hub --- erpnext/hub_node/api.py | 19 ++++++++++++++++++- erpnext/public/js/hub/pages/Item.vue | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 0d01c67650..b0b00b2b46 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -70,7 +70,7 @@ def map_fields(items): field_mappings = get_field_mappings() table_fields = [d.fieldname for d in frappe.get_meta('Item').get_table_fields()] - hub_seller_name = frappe.db.get_value('Marketplace Settings' , 'Marketplace Settings', 'hub_seller_name') + hub_seller_name = frappe.db.get_value('Marketplace Settings', 'Marketplace Settings', 'hub_seller_name') for item in items: for fieldname in table_fields: @@ -147,6 +147,23 @@ def publish_selected_items(items_to_publish): except Exception as e: frappe.log_error(message=e, title='Hub Sync Error') +@frappe.whitelist() +def unpublish_item(item): + ''' Remove item listing from the marketplace ''' + item = json.loads(item) + + item_code = item.get('item_code') + frappe.db.set_value('Item', item_code, 'publish_in_hub', 0) + + item = map_fields([item])[0] + + try: + connection = get_hub_connection() + connection.set_value('Hub Item', item.get('name'), 'published', 0) + + except Exception as e: + frappe.log_error(message=e, title='Hub Sync Error') + @frappe.whitelist() def get_unregistered_users(): settings = frappe.get_single('Marketplace Settings') diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue index 841d0046db..285f696926 100644 --- a/erpnext/public/js/hub/pages/Item.vue +++ b/erpnext/public/js/hub/pages/Item.vue @@ -300,7 +300,21 @@ export default { }, unpublish_item() { - frappe.msgprint(__('This feature is under development...')); + let me = this; + frappe.confirm(__(`Unpublish ${this.item.item_name}?`), function () { + frappe.call( + 'erpnext.hub_node.api.unpublish_item', + { + item: me.item + } + ) + .then((r) => { + frappe.set_route(`marketplace/home`); + frappe.show_alert(__('Item listing removed')) + + }) + + }) } } }