Add search preview for purchase orders and sales orders

This commit is contained in:
Oliver Walters 2022-03-29 23:38:01 +11:00
parent 2a604c244e
commit f724f4a845
2 changed files with 55 additions and 5 deletions

View File

@ -228,14 +228,12 @@ function renderOwner(name, data, parameters={}, options={}) {
// Renderer for "PurchaseOrder" model // Renderer for "PurchaseOrder" model
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function renderPurchaseOrder(name, data, parameters={}, options={}) { function renderPurchaseOrder(name, data, parameters={}, options={}) {
var html = '';
var prefix = global_settings.PURCHASEORDER_REFERENCE_PREFIX; var prefix = global_settings.PURCHASEORDER_REFERENCE_PREFIX;
var html = `<span>${prefix}${data.reference}</span>`;
var thumbnail = null; var thumbnail = null;
html += `<span>${prefix}${data.reference}</span>`;
if (data.supplier_detail) { if (data.supplier_detail) {
thumbnail = data.supplier_detail.thumbnail || data.supplier_detail.image; thumbnail = data.supplier_detail.thumbnail || data.supplier_detail.image;
@ -262,7 +260,18 @@ function renderPurchaseOrder(name, data, parameters={}, options={}) {
// Renderer for "SalesOrder" model // Renderer for "SalesOrder" model
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function renderSalesOrder(name, data, parameters={}, options={}) { function renderSalesOrder(name, data, parameters={}, options={}) {
var html = `<span>${data.reference}</span>`;
var prefix = global_settings.SALESORDER_REFERENCE_PREFIX;
var html = `<span>${prefix}${data.reference}</span>`;
var thumbnail = null;
if (data.customer_detail) {
thumbnail = data.customer_detail.thumbnail || data.customer_detail.image;
html += ' - ' + select2Thumbnail(thumbnail);
html += `<span>${data.customer_detail.name}</span>`;
}
if (data.description) { if (data.description) {
html += ` - <em>${data.description}</em>`; html += ` - <em>${data.description}</em>`;

View File

@ -79,12 +79,19 @@ function updateSearch() {
$('#offcanvas-search').find('#search-pending').show(); $('#offcanvas-search').find('#search-pending').show();
if (user_settings.SEARCH_PREVIEW_SHOW_PARTS) { if (user_settings.SEARCH_PREVIEW_SHOW_PARTS) {
var params = {};
if (user_settings.SEARCH_HIDE_INACTIVE_PARTS) {
params.active = false;
}
// Search for matching parts // Search for matching parts
addSearchQuery( addSearchQuery(
'part', 'part',
'{% trans "Parts" %}', '{% trans "Parts" %}',
'{% url "api-part-list" %}', '{% url "api-part-list" %}',
{}, params,
renderPart, renderPart,
{ {
url: '/part', url: '/part',
@ -150,6 +157,40 @@ function updateSearch() {
} }
); );
} }
if (user_settings.SEARCH_PREVIEW_SHOW_PURCHASE_ORDERS) {
// Search for matching purchase orders
addSearchQuery(
'purchaseorder',
'{% trans "Purchase Orders" %}',
'{% url "api-po-list" %}',
{
supplier_detail: true,
outstanding: true,
},
renderPurchaseOrder,
{
url: '/order/purchase-order',
}
);
}
if (user_settings.SEARCH_PREVIEW_SHOW_SALES_ORDERS) {
// Search for matching sales orders
addSearchQuery(
'salesorder',
'{% trans "Sales Orders" %}',
'{% url "api-so-list" %}',
{
customer_detail: true,
outstanding: true,
},
renderSalesOrder,
{
url: '/order/sales-order',
}
);
}
// Wait until all the pending queries are completed // Wait until all the pending queries are completed
$.when.apply($, searchQueries).done(function() { $.when.apply($, searchQueries).done(function() {