mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 21:45:39 +00:00
Receiving items against a purchase order now makes use of the API forms
- Delete old unused code - Improve serializer validation
This commit is contained in:
@ -1515,6 +1515,7 @@ function initializeChoiceField(field, fields, options) {
|
||||
select.select2({
|
||||
dropdownAutoWidth: false,
|
||||
dropdownParent: $(options.modal),
|
||||
width: '100%',
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -264,13 +264,19 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
// Part thumbnail + description
|
||||
var thumb = thumbnailImage(line_item.part_detail.thumbnail);
|
||||
|
||||
var quantity = (line_item.quantity || 0) - (line_item.received || 0);
|
||||
|
||||
if (quantity < 0) {
|
||||
quantity = 0;
|
||||
}
|
||||
|
||||
// Quantity to Receive
|
||||
var quantity_input = constructField(
|
||||
`items_quantity_${pk}`,
|
||||
{
|
||||
type: 'decimal',
|
||||
min_value: 0,
|
||||
value: opts.quantity || 0,
|
||||
value: quantity,
|
||||
title: '{% trans "Quantity to receive" %}',
|
||||
required: true,
|
||||
},
|
||||
@ -279,6 +285,16 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
}
|
||||
);
|
||||
|
||||
// Construct list of StockItem status codes
|
||||
var choices = [];
|
||||
|
||||
for (var key in stockCodes) {
|
||||
choices.push({
|
||||
value: key,
|
||||
display_name: stockCodes[key].value,
|
||||
});
|
||||
}
|
||||
|
||||
var destination_input = constructField(
|
||||
`items_location_${pk}`,
|
||||
{
|
||||
@ -291,6 +307,20 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
}
|
||||
);
|
||||
|
||||
var status_input = constructField(
|
||||
`items_status_${pk}`,
|
||||
{
|
||||
type: 'choice',
|
||||
label: '{% trans "Stock Status" %}',
|
||||
required: true,
|
||||
choices: choices,
|
||||
value: 10, // OK
|
||||
},
|
||||
{
|
||||
hideLabels: true,
|
||||
}
|
||||
);
|
||||
|
||||
// Button to remove the row
|
||||
var delete_button = `<div class='btn-group float-right' role='group'>`;
|
||||
|
||||
@ -321,7 +351,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
${quantity_input}
|
||||
</td>
|
||||
<td id='status_${pk}'>
|
||||
STATUS
|
||||
${status_input}
|
||||
</td>
|
||||
<td id='desination_${pk}'>
|
||||
${destination_input}
|
||||
@ -349,11 +379,11 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
<tr>
|
||||
<th>{% trans "Part" %}</th>
|
||||
<th>{% trans "Order Code" %}</th>
|
||||
<th>{% trans "On Order" %}</th>
|
||||
<th>{% trans "Ordered" %}</th>
|
||||
<th>{% trans "Received" %}</th>
|
||||
<th style='min-width: 50px;'>{% trans "Receive" %}</th>
|
||||
<th>{% trans "Status" %}</th>
|
||||
<th style='min-width: 350px;'>{% trans "Destination" %}</th>
|
||||
<th style='min-width: 150px;'>{% trans "Status" %}</th>
|
||||
<th style='min-width: 300px;'>{% trans "Destination" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -390,7 +420,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
model: 'stocklocation',
|
||||
required: false,
|
||||
auto_fill: false,
|
||||
value: item.destination,
|
||||
value: item.destination || item.part_detail.default_location,
|
||||
render_description: false,
|
||||
};
|
||||
|
||||
@ -405,10 +435,86 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
|
||||
field_details,
|
||||
opts
|
||||
);
|
||||
|
||||
initializeChoiceField(
|
||||
{
|
||||
name: `items_status_${pk}`,
|
||||
},
|
||||
null,
|
||||
opts
|
||||
);
|
||||
});
|
||||
|
||||
// Add callbacks to remove rows
|
||||
$(opts.modal).find('.button-row-remove').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
$(opts.modal).find(`#receive_row_${pk}`).remove();
|
||||
});
|
||||
},
|
||||
onSubmit: function(fields, opts) {
|
||||
// TODO
|
||||
// Extract data elements from the form
|
||||
var data = {
|
||||
items: [],
|
||||
location: getFormFieldValue('location', {}, opts),
|
||||
};
|
||||
|
||||
var item_pk_values = [];
|
||||
|
||||
line_items.forEach(function(item) {
|
||||
|
||||
var pk = item.pk;
|
||||
|
||||
var quantity = getFormFieldValue(`items_quantity_${pk}`, {}, opts);
|
||||
|
||||
var status = getFormFieldValue(`items_status_${pk}`, {}, opts);
|
||||
|
||||
var location = getFormFieldValue(`items_location_${pk}`, {}, opts);
|
||||
|
||||
if (quantity != null) {
|
||||
data.items.push({
|
||||
line_item: pk,
|
||||
quantity: quantity,
|
||||
status: status,
|
||||
location: location,
|
||||
});
|
||||
|
||||
item_pk_values.push(pk);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Provide list of nested values
|
||||
opts.nested = {
|
||||
'items': item_pk_values,
|
||||
};
|
||||
|
||||
inventreePut(
|
||||
opts.url,
|
||||
data,
|
||||
{
|
||||
method: 'POST',
|
||||
success: function(response) {
|
||||
// Hide the modal
|
||||
$(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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -604,22 +710,24 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
$(table).find('.button-line-receive').click(function() {
|
||||
var pk = $(this).attr('pk');
|
||||
|
||||
launchModalForm(`/order/purchase-order/${options.order}/receive/`, {
|
||||
success: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
},
|
||||
data: {
|
||||
line: pk,
|
||||
},
|
||||
secondary: [
|
||||
{
|
||||
field: 'location',
|
||||
label: '{% trans "New Location" %}',
|
||||
title: '{% trans "Create new stock location" %}',
|
||||
url: '{% url "stock-location-create" %}',
|
||||
},
|
||||
]
|
||||
});
|
||||
var line_item = $(table).bootstrapTable('getRowByUniqueId', pk);
|
||||
|
||||
if (!line_item) {
|
||||
console.log('WARNING: getRowByUniqueId returned null');
|
||||
return;
|
||||
}
|
||||
|
||||
receivePurchaseOrderItems(
|
||||
options.order,
|
||||
[
|
||||
line_item,
|
||||
],
|
||||
{
|
||||
success: function() {
|
||||
$(table).bootstrapTable('refresh');
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -637,11 +745,11 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
},
|
||||
url: '{% url "api-po-line-list" %}',
|
||||
showFooter: true,
|
||||
uniqueId: 'pk',
|
||||
columns: [
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
checkbox: true,
|
||||
visible: true,
|
||||
switchable: false,
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user