Merge pull request #19815 from Mangesh-Khairnar/publish-item

feat(marketplace): allow user to un-publish item
This commit is contained in:
Deepesh Garg 2019-12-28 17:52:49 +05:30 committed by GitHub
commit b914cf0a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 36 deletions

View File

@ -129,6 +129,7 @@ def update_item(ref_doc, data):
@frappe.whitelist() @frappe.whitelist()
def publish_selected_items(items_to_publish): def publish_selected_items(items_to_publish):
items_to_publish = json.loads(items_to_publish) items_to_publish = json.loads(items_to_publish)
items_to_update = []
if not len(items_to_publish): if not len(items_to_publish):
frappe.throw(_('No items to publish')) frappe.throw(_('No items to publish'))
@ -136,14 +137,24 @@ def publish_selected_items(items_to_publish):
item_code = item.get('item_code') item_code = item.get('item_code')
frappe.db.set_value('Item', item_code, 'publish_in_hub', 1) frappe.db.set_value('Item', item_code, 'publish_in_hub', 1)
frappe.get_doc({ hub_dict = {
'doctype': 'Hub Tracked Item', 'doctype': 'Hub Tracked Item',
'item_code': item_code, 'item_code': item_code,
'published': 1,
'hub_category': item.get('hub_category'), 'hub_category': item.get('hub_category'),
'image_list': item.get('image_list') 'image_list': item.get('image_list')
}).insert(ignore_if_duplicate=True) }
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)
items = map_fields(items_to_publish) 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)
try: try:
item_sync_preprocess(len(items)) item_sync_preprocess(len(items))
@ -151,12 +162,26 @@ def publish_selected_items(items_to_publish):
# TODO: Publish Progress # TODO: Publish Progress
connection = get_hub_connection() connection = get_hub_connection()
connection.insert_many(items) connection.insert_many(new_items)
connection.bulk_update(existing_items)
item_sync_postprocess() item_sync_postprocess()
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_code, hub_item_name):
''' Remove item listing from the marketplace '''
response = call_hub_method('unpublish_item', {
'hub_item_name': hub_item_name
})
if response:
frappe.db.set_value('Item', item_code, 'publish_in_hub', 0)
else:
frappe.throw(_('Unable to update remote activity'))
@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

@ -77,6 +77,38 @@
"translatable": 0, "translatable": 0,
"unique": 0 "unique": 0
}, },
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "published",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Published",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0, "allow_in_quick_entry": 0,
@ -120,7 +152,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-09-10 11:37:35.951019", "modified": "2019-12-10 11:37:35.951019",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Hub Node", "module": "Hub Node",
"name": "Hub Tracked Item", "name": "Hub Tracked Item",

View File

@ -655,3 +655,4 @@ erpnext.patches.v12_0.set_against_blanket_order_in_sales_and_purchase_order
erpnext.patches.v12_0.set_cost_center_in_child_table_of_expense_claim erpnext.patches.v12_0.set_cost_center_in_child_table_of_expense_claim
erpnext.patches.v12_0.set_lead_title_field erpnext.patches.v12_0.set_lead_title_field
erpnext.patches.v12_0.set_permission_einvoicing erpnext.patches.v12_0.set_permission_einvoicing
erpnext.patches.v12_0.set_published_in_hub_tracked_item

View File

@ -0,0 +1,12 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("Hub Node", "doctype", "Hub Tracked Item")
if not frappe.db.a_row_exists("Hub Tracked Item"):
return
frappe.db.sql('''
Update `tabHub Tracked Item`
SET published = 1
''')

View File

@ -3,24 +3,24 @@ function ItemPublishDialog(primary_action, secondary_action) {
title: __('Edit Publishing Details'), title: __('Edit Publishing Details'),
fields: [ fields: [
{ {
"label": "Item Code", label: __('Item Code'),
"fieldname": "item_code", fieldname: 'item_code',
"fieldtype": "Data", fieldtype: 'Data',
"read_only": 1 read_only: 1
}, },
{ {
"label": "Hub Category", label: __('Hub Category'),
"fieldname": "hub_category", fieldname: 'hub_category',
"fieldtype": "Autocomplete", fieldtype: 'Autocomplete',
"options": [], options: [],
"reqd": 1 reqd: 1
}, },
{ {
"label": "Images", label: __('Images'),
"fieldname": "image_list", fieldname: 'image_list',
"fieldtype": "MultiSelect", fieldtype: 'MultiSelect',
"options": [], options: [],
"reqd": 1 reqd: 1
} }
], ],
primary_action_label: primary_action.label || __('Set Details'), primary_action_label: primary_action.label || __('Set Details'),
@ -28,8 +28,7 @@ function ItemPublishDialog(primary_action, secondary_action) {
secondary_action: secondary_action.fn secondary_action: secondary_action.fn
}); });
hub.call('get_categories') hub.call('get_categories').then(categories => {
.then(categories => {
categories = categories.map(d => d.name); categories = categories.map(d => d.name);
dialog.fields_dict.hub_category.set_data(categories); dialog.fields_dict.hub_category.set_data(categories);
}); });
@ -37,6 +36,4 @@ function ItemPublishDialog(primary_action, secondary_action) {
return dialog; return dialog;
} }
export { export { ItemPublishDialog };
ItemPublishDialog
}

View File

@ -58,6 +58,13 @@ export default {
this.search_value = ''; this.search_value = '';
this.get_items(); this.get_items();
}, },
mounted() {
frappe.route.on('change', () => {
if (frappe.get_route_str() === 'marketplace/home') {
this.get_items();
}
})
},
methods: { methods: {
get_items() { get_items() {
hub.call('get_data_for_homepage', frappe.defaults ? { hub.call('get_data_for_homepage', frappe.defaults ? {

View File

@ -161,7 +161,8 @@ export default {
}, },
methods: { methods: {
get_item_details() { get_item_details() {
this.item_received = hub.call('get_item_details', { hub_item_name: this.hub_item_name }) this.item_received = hub
.call('get_item_details', { hub_item_name: this.hub_item_name })
.then(item => { .then(item => {
this.init = false; this.init = false;
this.item = item; this.item = item;
@ -205,9 +206,7 @@ export default {
hub_user: frappe.session.user hub_user: frappe.session.user
}) })
.then(() => { .then(() => {
const saved_items_link = `<b><a href="#marketplace/saved-items">${__( const saved_items_link = `<b><a href="#marketplace/saved-items">${__('Saved')}</a></b>`;
'Saved'
)}</a></b>`;
frappe.show_alert(saved_items_link); frappe.show_alert(saved_items_link);
erpnext.hub.trigger('action:item_save'); erpnext.hub.trigger('action:item_save');
}) })
@ -222,9 +221,7 @@ export default {
hub_user: frappe.session.user hub_user: frappe.session.user
}) })
.then(() => { .then(() => {
const featured_items_link = `<b><a href="#marketplace/featured-items">${__( const featured_items_link = `<b><a href="#marketplace/featured-items">${__('Added to Featured Items')}</a></b>`;
'Added to Featured Items'
)}</a></b>`;
frappe.show_alert(featured_items_link); frappe.show_alert(featured_items_link);
erpnext.hub.trigger('action:item_feature'); erpnext.hub.trigger('action:item_feature');
}) })
@ -340,7 +337,17 @@ export default {
}, },
unpublish_item() { unpublish_item() {
frappe.msgprint(__('This feature is under development...')); frappe.confirm(__(`Unpublish {0}?`, [this.item.item_name]), () => {
frappe
.call('erpnext.hub_node.api.unpublish_item', {
item_code: this.item.item_code,
hub_item_name: this.hub_item_name
})
.then(r => {
frappe.set_route(`marketplace/home`);
frappe.show_alert(__('Item listing removed'));
});
});
} }
} }
}; };