mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Further improvements
- Add callback for when a select2 form field is updated - Adjust selected quantity based on returned data - auto_fill the stock_item field
This commit is contained in:
parent
f7b6c68237
commit
92568748cf
@ -1426,6 +1426,11 @@ function initializeRelatedField(field, fields, options) {
|
||||
data = item.element.instance;
|
||||
}
|
||||
|
||||
// Run optional callback function
|
||||
if (field.onSelect && data) {
|
||||
field.onSelect(data, field, options);
|
||||
}
|
||||
|
||||
if (!data.pk) {
|
||||
return field.placeholder || '';
|
||||
}
|
||||
|
@ -1661,7 +1661,23 @@ function loadSalesOrderLineItemTable(table, options={}) {
|
||||
in_stock: true,
|
||||
part: line_item.part,
|
||||
exclude_so_allocation: options.order,
|
||||
}
|
||||
},
|
||||
auto_fill: true,
|
||||
onSelect: function(data, field, opts) {
|
||||
// Quantity available from this stock item
|
||||
|
||||
if (!("quantity" in data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate the available quantity
|
||||
var available = Math.max((data.quantity || 0) - (data.allocated || 0), 0);
|
||||
|
||||
// Maximum amount that we need
|
||||
var desired = Math.min(available, remaining);
|
||||
|
||||
updateFieldValue('quantity', desired, {}, opts);
|
||||
}
|
||||
},
|
||||
quantity: {
|
||||
value: remaining,
|
||||
@ -1760,7 +1776,7 @@ function loadSalesOrderLineItemTable(table, options={}) {
|
||||
showFooter: true,
|
||||
uniqueId: 'pk',
|
||||
detailView: show_detail,
|
||||
detailViewByClick: show_detail,
|
||||
detailViewByClick: false,
|
||||
detailFilter: function(index, row) {
|
||||
if (pending) {
|
||||
// Order is pending
|
||||
|
Loading…
Reference in New Issue
Block a user