mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 16:04:46 +00:00
[hub] setup publish items flow
This commit is contained in:
@@ -38,8 +38,6 @@ def get_valid_items(search_value=''):
|
|||||||
'item_name': ['like', '%' + search_value + '%']
|
'item_name': ['like', '%' + search_value + '%']
|
||||||
})
|
})
|
||||||
|
|
||||||
print([d.item_name for d in items])
|
|
||||||
|
|
||||||
valid_items = filter(lambda x: x.image and x.description, items)
|
valid_items = filter(lambda x: x.image and x.description, items)
|
||||||
|
|
||||||
def attach_source_type(item):
|
def attach_source_type(item):
|
||||||
@@ -49,6 +47,19 @@ def get_valid_items(search_value=''):
|
|||||||
valid_items = map(lambda x: attach_source_type(x), valid_items)
|
valid_items = map(lambda x: attach_source_type(x), valid_items)
|
||||||
return valid_items
|
return valid_items
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def publish_selected_items(items_to_publish, items_to_unpublish):
|
||||||
|
for item_code in json.loads(items_to_publish):
|
||||||
|
frappe.db.set_value('Item', item_code, 'publish_in_hub', 1)
|
||||||
|
|
||||||
|
for item_code in json.loads(items_to_unpublish):
|
||||||
|
frappe.db.set_value('Item', item_code, 'publish_in_hub', 0)
|
||||||
|
|
||||||
|
hub_settings = frappe.get_doc('Hub Settings')
|
||||||
|
hub_settings.sync()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_item_favourites(start=0, limit=20, fields=["*"], order_by=None):
|
def get_item_favourites(start=0, limit=20, fields=["*"], order_by=None):
|
||||||
doctype = 'Hub Item'
|
doctype = 'Hub Item'
|
||||||
|
|||||||
@@ -576,11 +576,13 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
make_wrapper() {
|
make_wrapper() {
|
||||||
super.make_wrapper();
|
super.make_wrapper();
|
||||||
const title_html = `<b>${__('Select Products to Publish')}</b>`;
|
const title_html = `<b>${__('Select Products to Publish')}</b>`;
|
||||||
const subtitle_html = `<p class="text-muted">
|
const info = `<p class="text-muted">${__("Status decided by the 'Publish in Hub' field in Item.")}</p>`;
|
||||||
${__(`Only products with an image and description can be published.
|
const subtitle_html = `
|
||||||
|
<p class="text-muted">
|
||||||
|
${__(`Only products with an image, description and category can be published.
|
||||||
Please update them if an item in your inventory does not appear.`)}
|
Please update them if an item in your inventory does not appear.`)}
|
||||||
</p>`;
|
</p>`;
|
||||||
const publish_button_html = `<button class="btn btn-primary btn-sm publish-button">
|
const publish_button_html = `<button class="btn btn-primary btn-sm publish-items">
|
||||||
<i class="visible-xs octicon octicon-check"></i>
|
<i class="visible-xs octicon octicon-check"></i>
|
||||||
<span class="hidden-xs">Publish</span>
|
<span class="hidden-xs">Publish</span>
|
||||||
</button>`;
|
</button>`;
|
||||||
@@ -621,6 +623,13 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
this.$wrapper.find('.hub-card').removeClass('active');
|
this.$wrapper.find('.hub-card').removeClass('active');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.$wrapper.find('.publish-items').on('click', () => {
|
||||||
|
this.publish_selected_items()
|
||||||
|
.then(r => {
|
||||||
|
frappe.msgprint('check');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const $search_input = this.$wrapper.find('.hub-search-container input');
|
const $search_input = this.$wrapper.find('.hub-search-container input');
|
||||||
this.search_value = '';
|
this.search_value = '';
|
||||||
|
|
||||||
@@ -662,6 +671,28 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publish_selected_items() {
|
||||||
|
const items_to_publish = [];
|
||||||
|
const items_to_unpublish = [];
|
||||||
|
this.$wrapper.find('.hub-card').map(function () {
|
||||||
|
const active = $(this).hasClass('active');
|
||||||
|
|
||||||
|
if(active) {
|
||||||
|
items_to_publish.push($(this).attr("data-id"));
|
||||||
|
} else {
|
||||||
|
items_to_unpublish.push($(this).attr("data-id"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return frappe.call(
|
||||||
|
'erpnext.hub_node.publish_selected_items',
|
||||||
|
{
|
||||||
|
items_to_publish: items_to_publish,
|
||||||
|
items_to_unpublish: items_to_unpublish
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_item_card_container_html(items, title='') {
|
function get_item_card_container_html(items, title='') {
|
||||||
@@ -680,10 +711,14 @@ function get_item_card_container_html(items, title='') {
|
|||||||
function get_item_card_html(item) {
|
function get_item_card_html(item) {
|
||||||
const item_name = item.item_name || item.name;
|
const item_name = item.item_name || item.name;
|
||||||
const title = strip_html(item_name);
|
const title = strip_html(item_name);
|
||||||
|
|
||||||
const img_url = item.image;
|
const img_url = item.image;
|
||||||
|
|
||||||
const company_name = item.company_name;
|
const company_name = item.company_name;
|
||||||
|
|
||||||
|
const active = item.publish_in_hub;
|
||||||
|
|
||||||
|
const id = item.hub_item_code || item.item_code;
|
||||||
|
|
||||||
// Subtitle
|
// Subtitle
|
||||||
let subtitle = [comment_when(item.creation)];
|
let subtitle = [comment_when(item.creation)];
|
||||||
const rating = get_rating(item);
|
const rating = get_rating(item);
|
||||||
@@ -713,7 +748,7 @@ function get_item_card_html(item) {
|
|||||||
|
|
||||||
const item_html = `
|
const item_html = `
|
||||||
<div class="col-md-3 col-sm-4 col-xs-6">
|
<div class="col-md-3 col-sm-4 col-xs-6">
|
||||||
<div class="hub-card" ${card_route}>
|
<div class="hub-card ${active ? 'active' : ''}" ${card_route} data-id="${id}">
|
||||||
<div class="hub-card-header">
|
<div class="hub-card-header">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<div class="hub-card-title ellipsis bold">${title}</div>
|
<div class="hub-card-title ellipsis bold">${title}</div>
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ class Item(WebsiteGenerator):
|
|||||||
if not self.description:
|
if not self.description:
|
||||||
self.description = self.item_name
|
self.description = self.item_name
|
||||||
|
|
||||||
if self.is_sales_item and not self.get('is_item_from_hub'):
|
# if self.is_sales_item and not self.get('is_item_from_hub'):
|
||||||
self.publish_in_hub = 1
|
# self.publish_in_hub = 1
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
'''set opening stock and item price'''
|
'''set opening stock and item price'''
|
||||||
|
|||||||
Reference in New Issue
Block a user