Merge pull request #19815 from Mangesh-Khairnar/publish-item
feat(marketplace): allow user to un-publish item
This commit is contained in:
commit
b914cf0a9d
@ -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:
|
||||
@ -129,6 +129,7 @@ def update_item(ref_doc, data):
|
||||
@frappe.whitelist()
|
||||
def publish_selected_items(items_to_publish):
|
||||
items_to_publish = json.loads(items_to_publish)
|
||||
items_to_update = []
|
||||
if not len(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')
|
||||
frappe.db.set_value('Item', item_code, 'publish_in_hub', 1)
|
||||
|
||||
frappe.get_doc({
|
||||
hub_dict = {
|
||||
'doctype': 'Hub Tracked Item',
|
||||
'item_code': item_code,
|
||||
'published': 1,
|
||||
'hub_category': item.get('hub_category'),
|
||||
'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:
|
||||
item_sync_preprocess(len(items))
|
||||
@ -151,12 +162,26 @@ def publish_selected_items(items_to_publish):
|
||||
|
||||
# TODO: Publish Progress
|
||||
connection = get_hub_connection()
|
||||
connection.insert_many(items)
|
||||
connection.insert_many(new_items)
|
||||
connection.bulk_update(existing_items)
|
||||
|
||||
item_sync_postprocess()
|
||||
except Exception as e:
|
||||
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()
|
||||
def get_unregistered_users():
|
||||
settings = frappe.get_single('Marketplace Settings')
|
||||
|
@ -77,6 +77,38 @@
|
||||
"translatable": 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_in_quick_entry": 0,
|
||||
@ -120,7 +152,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-09-10 11:37:35.951019",
|
||||
"modified": "2019-12-10 11:37:35.951019",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Hub Node",
|
||||
"name": "Hub Tracked Item",
|
||||
|
@ -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_lead_title_field
|
||||
erpnext.patches.v12_0.set_permission_einvoicing
|
||||
erpnext.patches.v12_0.set_published_in_hub_tracked_item
|
12
erpnext/patches/v12_0/set_published_in_hub_tracked_item.py
Normal file
12
erpnext/patches/v12_0/set_published_in_hub_tracked_item.py
Normal 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
|
||||
''')
|
@ -3,24 +3,24 @@ function ItemPublishDialog(primary_action, secondary_action) {
|
||||
title: __('Edit Publishing Details'),
|
||||
fields: [
|
||||
{
|
||||
"label": "Item Code",
|
||||
"fieldname": "item_code",
|
||||
"fieldtype": "Data",
|
||||
"read_only": 1
|
||||
label: __('Item Code'),
|
||||
fieldname: 'item_code',
|
||||
fieldtype: 'Data',
|
||||
read_only: 1
|
||||
},
|
||||
{
|
||||
"label": "Hub Category",
|
||||
"fieldname": "hub_category",
|
||||
"fieldtype": "Autocomplete",
|
||||
"options": [],
|
||||
"reqd": 1
|
||||
label: __('Hub Category'),
|
||||
fieldname: 'hub_category',
|
||||
fieldtype: 'Autocomplete',
|
||||
options: [],
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
"label": "Images",
|
||||
"fieldname": "image_list",
|
||||
"fieldtype": "MultiSelect",
|
||||
"options": [],
|
||||
"reqd": 1
|
||||
label: __('Images'),
|
||||
fieldname: 'image_list',
|
||||
fieldtype: 'MultiSelect',
|
||||
options: [],
|
||||
reqd: 1
|
||||
}
|
||||
],
|
||||
primary_action_label: primary_action.label || __('Set Details'),
|
||||
@ -28,15 +28,12 @@ function ItemPublishDialog(primary_action, secondary_action) {
|
||||
secondary_action: secondary_action.fn
|
||||
});
|
||||
|
||||
hub.call('get_categories')
|
||||
.then(categories => {
|
||||
categories = categories.map(d => d.name);
|
||||
dialog.fields_dict.hub_category.set_data(categories);
|
||||
});
|
||||
hub.call('get_categories').then(categories => {
|
||||
categories = categories.map(d => d.name);
|
||||
dialog.fields_dict.hub_category.set_data(categories);
|
||||
});
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
export {
|
||||
ItemPublishDialog
|
||||
}
|
||||
export { ItemPublishDialog };
|
||||
|
@ -58,6 +58,13 @@ export default {
|
||||
this.search_value = '';
|
||||
this.get_items();
|
||||
},
|
||||
mounted() {
|
||||
frappe.route.on('change', () => {
|
||||
if (frappe.get_route_str() === 'marketplace/home') {
|
||||
this.get_items();
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
get_items() {
|
||||
hub.call('get_data_for_homepage', frappe.defaults ? {
|
||||
|
@ -161,7 +161,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
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 => {
|
||||
this.init = false;
|
||||
this.item = item;
|
||||
@ -205,9 +206,7 @@ export default {
|
||||
hub_user: frappe.session.user
|
||||
})
|
||||
.then(() => {
|
||||
const saved_items_link = `<b><a href="#marketplace/saved-items">${__(
|
||||
'Saved'
|
||||
)}</a></b>`;
|
||||
const saved_items_link = `<b><a href="#marketplace/saved-items">${__('Saved')}</a></b>`;
|
||||
frappe.show_alert(saved_items_link);
|
||||
erpnext.hub.trigger('action:item_save');
|
||||
})
|
||||
@ -222,9 +221,7 @@ export default {
|
||||
hub_user: frappe.session.user
|
||||
})
|
||||
.then(() => {
|
||||
const featured_items_link = `<b><a href="#marketplace/featured-items">${__(
|
||||
'Added to Featured Items'
|
||||
)}</a></b>`;
|
||||
const featured_items_link = `<b><a href="#marketplace/featured-items">${__('Added to Featured Items')}</a></b>`;
|
||||
frappe.show_alert(featured_items_link);
|
||||
erpnext.hub.trigger('action:item_feature');
|
||||
})
|
||||
@ -340,7 +337,17 @@ export default {
|
||||
},
|
||||
|
||||
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'));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user