feat(marketplace): unpublish item from hub

This commit is contained in:
Mangesh-Khairnar 2019-11-29 15:52:29 +05:30
parent 370cdc0170
commit 8287c3d05a
2 changed files with 33 additions and 2 deletions

View File

@ -70,7 +70,7 @@ def map_fields(items):
field_mappings = get_field_mappings() field_mappings = get_field_mappings()
table_fields = [d.fieldname for d in frappe.get_meta('Item').get_table_fields()] 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 item in items:
for fieldname in table_fields: for fieldname in table_fields:
@ -147,6 +147,23 @@ def publish_selected_items(items_to_publish):
except Exception as e: except Exception as e:
frappe.log_error(message=e, title='Hub Sync Error') 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() @frappe.whitelist()
def get_unregistered_users(): def get_unregistered_users():
settings = frappe.get_single('Marketplace Settings') settings = frappe.get_single('Marketplace Settings')

View File

@ -300,7 +300,21 @@ export default {
}, },
unpublish_item() { 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'))
})
})
} }
} }
} }