2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Merge branch 'inventree:master' into matmair/issue2279

This commit is contained in:
Matthias Mair
2021-12-09 23:56:27 +01:00
committed by GitHub
11 changed files with 437 additions and 58 deletions

View File

@ -38,6 +38,7 @@
*/
/* exported
assignStockToCustomer,
createNewStockItem,
createStockLocation,
duplicateStockItem,
@ -533,13 +534,166 @@ function exportStock(params={}) {
url += `&${key}=${params[key]}`;
}
console.log(url);
location.href = url;
}
});
}
/**
* Assign multiple stock items to a customer
*/
function assignStockToCustomer(items, options={}) {
// Generate HTML content for the form
var html = `
<table class='table table-striped table-condensed' id='stock-assign-table'>
<thead>
<tr>
<th>{% trans "Part" %}</th>
<th>{% trans "Stock Item" %}</th>
<th>{% trans "Location" %}</th>
<th></th>
</tr>
</thead>
<tbody>
`;
for (var idx = 0; idx < items.length; idx++) {
var item = items[idx];
var pk = item.pk;
var part = item.part_detail;
var thumbnail = thumbnailImage(part.thumbnail || part.image);
var status = stockStatusDisplay(item.status, {classes: 'float-right'});
var quantity = '';
if (item.serial && item.quantity == 1) {
quantity = `{% trans "Serial" %}: ${item.serial}`;
} else {
quantity = `{% trans "Quantity" %}: ${item.quantity}`;
}
quantity += status;
var location = locationDetail(item, false);
var buttons = `<div class='btn-group' role='group'>`;
buttons += makeIconButton(
'fa-times icon-red',
'button-stock-item-remove',
pk,
'{% trans "Remove row" %}',
);
buttons += '</div>';
html += `
<tr id='stock_item_${pk}' class='stock-item'row'>
<td id='part_${pk}'>${thumbnail} ${part.full_name}</td>
<td id='stock_${pk}'>
<div id='div_id_items_item_${pk}'>
${quantity}
<div id='errors-items_item_${pk}'></div>
</div>
</td>
<td id='location_${pk}'>${location}</td>
<td id='buttons_${pk}'>${buttons}</td>
</tr>
`;
}
html += `</tbody></table>`;
constructForm('{% url "api-stock-assign" %}', {
method: 'POST',
preFormContent: html,
fields: {
'customer': {
value: options.customer,
filters: {
is_customer: true,
},
},
'notes': {},
},
confirm: true,
confirmMessage: '{% trans "Confirm stock assignment" %}',
title: '{% trans "Assign Stock to Customer" %}',
afterRender: function(fields, opts) {
// Add button callbacks to remove rows
$(opts.modal).find('.button-stock-item-remove').click(function() {
var pk = $(this).attr('pk');
$(opts.modal).find(`#stock_item_${pk}`).remove();
});
},
onSubmit: function(fields, opts) {
// Extract data elements from the form
var data = {
customer: getFormFieldValue('customer', {}, opts),
notes: getFormFieldValue('notes', {}, opts),
items: [],
};
var item_pk_values = [];
items.forEach(function(item) {
var pk = item.pk;
// Does the row exist in the form?
var row = $(opts.modal).find(`#stock_item_${pk}`);
if (row.exists()) {
item_pk_values.push(pk);
data.items.push({
item: pk,
});
}
});
opts.nested = {
'items': item_pk_values,
};
inventreePut(
'{% url "api-stock-assign" %}',
data,
{
method: 'POST',
success: function(response) {
$(opts.modal).modal('hide');
if (options.success) {
options.success(response);
}
},
error: function(xhr) {
switch (xhr.status) {
case 400:
handleFormErrors(xhr.responseJSON, fields, opts);
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr, opts.url);
break;
}
}
}
);
}
});
}
/**
* Perform stock adjustments
*/
@ -777,7 +931,7 @@ function adjustStock(action, items, options={}) {
// Does the row exist in the form?
var row = $(opts.modal).find(`#stock_item_${pk}`);
if (row) {
if (row.exists()) {
item_pk_values.push(pk);
@ -1098,7 +1252,7 @@ function locationDetail(row, showLink=true) {
// StockItem has been assigned to a sales order
text = '{% trans "Assigned to Sales Order" %}';
url = `/order/sales-order/${row.sales_order}/`;
} else if (row.location) {
} else if (row.location && row.location_detail) {
text = row.location_detail.pathstring;
url = `/stock/location/${row.location}/`;
} else {
@ -1721,6 +1875,17 @@ function loadStockTable(table, options) {
stockAdjustment('move');
});
$('#multi-item-assign').click(function() {
var items = $(table).bootstrapTable('getSelections');
assignStockToCustomer(items, {
success: function() {
$(table).bootstrapTable('refresh');
}
});
});
$('#multi-item-order').click(function() {
var selections = $(table).bootstrapTable('getSelections');

View File

@ -50,6 +50,7 @@
<li><a class='dropdown-item' href="#" id='multi-item-stocktake' title='{% trans "Stocktake selected stock items" %}'><span class='fas fa-check-circle'></span> {% trans "Count stock" %}</a></li>
<li><a class='dropdown-item' href='#' id='multi-item-move' title='{% trans "Move selected stock items" %}'><span class='fas fa-exchange-alt'></span> {% trans "Move stock" %}</a></li>
<li><a class='dropdown-item' href='#' id='multi-item-order' title='{% trans "Order selected items" %}'><span class='fas fa-shopping-cart'></span> {% trans "Order stock" %}</a></li>
<li><a class='dropdown-item' href='#' id='multi-item-assign' title='{% trans "Assign to customer" %}'><span class='fas fa-user-tie'></span> {% trans "Assign to customer" %}</a></li>
<li><a class='dropdown-item' href='#' id='multi-item-set-status' title='{% trans "Change status" %}'><span class='fas fa-exclamation-circle'></span> {% trans "Change stock status" %}</a></li>
{% endif %}
{% if roles.stock.delete %}