mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 21:16:46 +00:00
Button to submit each row individually
This commit is contained in:
parent
d69b5811b1
commit
1794f65d19
@ -246,6 +246,7 @@ class PurchaseOrderLineItemSerializer(InvenTreeModelSerializer):
|
|||||||
total_price = serializers.FloatField(read_only=True)
|
total_price = serializers.FloatField(read_only=True)
|
||||||
|
|
||||||
part_detail = PartBriefSerializer(source='get_base_part', many=False, read_only=True)
|
part_detail = PartBriefSerializer(source='get_base_part', many=False, read_only=True)
|
||||||
|
|
||||||
supplier_part_detail = SupplierPartSerializer(source='part', many=False, read_only=True)
|
supplier_part_detail = SupplierPartSerializer(source='part', many=False, read_only=True)
|
||||||
|
|
||||||
purchase_price = InvenTreeMoneySerializer(
|
purchase_price = InvenTreeMoneySerializer(
|
||||||
|
@ -1218,29 +1218,26 @@ function handleFormErrors(errors, fields={}, options={}) {
|
|||||||
|
|
||||||
for (var field_name in errors) {
|
for (var field_name in errors) {
|
||||||
|
|
||||||
if (field_name in fields) {
|
var field = fields[field_name] || {};
|
||||||
|
|
||||||
var field = fields[field_name];
|
if ((field.type == 'field') && ('child' in field)) {
|
||||||
|
// This is a "nested" field
|
||||||
|
handleNestedErrors(errors, field_name, options);
|
||||||
|
} else {
|
||||||
|
// This is a "simple" field
|
||||||
|
|
||||||
if ((field.type == 'field') && ('child' in field)) {
|
var field_errors = errors[field_name];
|
||||||
// This is a "nested" field
|
|
||||||
handleNestedErrors(errors, field_name, options);
|
|
||||||
} else {
|
|
||||||
// This is a "simple" field
|
|
||||||
|
|
||||||
var field_errors = errors[field_name];
|
if (field_errors && !first_error_field && isFieldVisible(field_name, options)) {
|
||||||
|
first_error_field = field_name;
|
||||||
|
}
|
||||||
|
|
||||||
if (field_errors && !first_error_field && isFieldVisible(field_name, options)) {
|
// Add an entry for each returned error message
|
||||||
first_error_field = field_name;
|
for (var ii = field_errors.length-1; ii >= 0; ii--) {
|
||||||
}
|
|
||||||
|
|
||||||
// Add an entry for each returned error message
|
var error_text = field_errors[ii];
|
||||||
for (var ii = field_errors.length-1; ii >= 0; ii--) {
|
|
||||||
|
|
||||||
var error_text = field_errors[ii];
|
addFieldErrorMessage(field_name, error_text, ii, options);
|
||||||
|
|
||||||
addFieldErrorMessage(field_name, error_text, ii, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1929,6 +1926,10 @@ function renderModelData(name, model, data, parameters, options) {
|
|||||||
function getFieldName(name, options={}) {
|
function getFieldName(name, options={}) {
|
||||||
var field_name = name;
|
var field_name = name;
|
||||||
|
|
||||||
|
if (options.field_suffix) {
|
||||||
|
field_name += options.field_suffix;
|
||||||
|
}
|
||||||
|
|
||||||
if (options && options.depth) {
|
if (options && options.depth) {
|
||||||
field_name += `_${options.depth}`;
|
field_name += `_${options.depth}`;
|
||||||
}
|
}
|
||||||
|
@ -514,7 +514,7 @@ function orderParts(parts_list, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var quantity_input = constructField(
|
var quantity_input = constructField(
|
||||||
`items_quantity_${pk}`,
|
`quantity_${pk}`,
|
||||||
{
|
{
|
||||||
type: 'decimal',
|
type: 'decimal',
|
||||||
min_value: 0,
|
min_value: 0,
|
||||||
@ -552,7 +552,7 @@ function orderParts(parts_list, options={}) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
var purchase_order_input = constructField(
|
var purchase_order_input = constructField(
|
||||||
`purchase_order_${pk}`,
|
`order_${pk}`,
|
||||||
{
|
{
|
||||||
type: 'related field',
|
type: 'related field',
|
||||||
required: true,
|
required: true,
|
||||||
@ -565,16 +565,6 @@ function orderParts(parts_list, options={}) {
|
|||||||
|
|
||||||
var buttons = `<div class='btn-group float-right' role='group'>`;
|
var buttons = `<div class='btn-group float-right' role='group'>`;
|
||||||
|
|
||||||
buttons += makeIconButton(
|
|
||||||
'fa-layer-group',
|
|
||||||
'button-row-expand',
|
|
||||||
pk,
|
|
||||||
'{% trans "Expand Row" %}',
|
|
||||||
{
|
|
||||||
collapseTarget: `order_row_expand_${pk}`,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
buttons += makeIconButton(
|
buttons += makeIconButton(
|
||||||
'fa-times icon-red',
|
'fa-times icon-red',
|
||||||
@ -584,26 +574,23 @@ function orderParts(parts_list, options={}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Button to add row to purchase order
|
||||||
|
buttons += makeIconButton(
|
||||||
|
'fa-shopping-cart icon-blue',
|
||||||
|
'button-row-add',
|
||||||
|
pk,
|
||||||
|
'{% trans "Add to purchase order" %}',
|
||||||
|
);
|
||||||
|
|
||||||
buttons += `</div>`;
|
buttons += `</div>`;
|
||||||
|
|
||||||
var html = `
|
var html = `
|
||||||
<tr id='order_row_${pk}' class='part-order-row'>
|
<tr id='order_row_${pk}' class='part-order-row'>
|
||||||
<td id='part_${pk}'>${thumb} ${part.full_name}</td>
|
<td id='td_part_${pk}'>${thumb} ${part.full_name}</td>
|
||||||
<td id='supplier_part_${pk}'>${supplier_part_input}</td>
|
<td id='td_supplier_part_${pk}'>${supplier_part_input}</td>
|
||||||
<td id='purchase_order_${pk}'>${purchase_order_input}</td>
|
<td id='td_order_${pk}'>${purchase_order_input}</td>
|
||||||
<td id='quantity_${pk}'>${quantity_input}</td>
|
<td id='td_quantity_${pk}'>${quantity_input}</td>
|
||||||
<td id='actions_${pk}'>${buttons}</td>
|
<td id='td_actions_${pk}'>${buttons}</td>
|
||||||
</tr>`;
|
|
||||||
|
|
||||||
// Add a second row "underneath" the first one, but collapsed
|
|
||||||
// Allows extra data to be added if required, but hidden by default
|
|
||||||
html += `
|
|
||||||
<tr id='order_row_expand_${pk}' class='part-order-row collapse'>
|
|
||||||
<td></td>
|
|
||||||
<td>reference goes here</td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
@ -662,7 +649,7 @@ function orderParts(parts_list, options={}) {
|
|||||||
|
|
||||||
// Configure the "purchase order" field
|
// Configure the "purchase order" field
|
||||||
initializeRelatedField({
|
initializeRelatedField({
|
||||||
name: `purchase_order_${part.pk}`,
|
name: `order_${part.pk}`,
|
||||||
model: 'purchaseorder',
|
model: 'purchaseorder',
|
||||||
api_url: '{% url "api-po-list" %}',
|
api_url: '{% url "api-po-list" %}',
|
||||||
required: true,
|
required: true,
|
||||||
@ -678,6 +665,50 @@ function orderParts(parts_list, options={}) {
|
|||||||
}, null, opts);
|
}, null, opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add callback for "add to purchase order" button
|
||||||
|
$(opts.modal).find('.button-row-add').click(function() {
|
||||||
|
var pk = $(this).attr('pk');
|
||||||
|
|
||||||
|
opts.field_suffix = null;
|
||||||
|
|
||||||
|
// Extract information from the row
|
||||||
|
var data = {
|
||||||
|
quantity: getFormFieldValue(`quantity_${pk}`, {type: 'decimal',}, opts),
|
||||||
|
supplier_part: getFormFieldValue(`supplier_part_${pk}`, {}, opts),
|
||||||
|
order: getFormFieldValue(`order_${pk}`, {}, opts),
|
||||||
|
}
|
||||||
|
|
||||||
|
// $(opts.modal).find(`#order_row_${pk}`).disable();
|
||||||
|
// $(this).disable();
|
||||||
|
|
||||||
|
// Duplicate the form options, to prevent 'field_suffix' override
|
||||||
|
var row_opts = Object.assign(opts);
|
||||||
|
row_opts.field_suffix = `_${pk}`;
|
||||||
|
|
||||||
|
inventreePut(
|
||||||
|
'{% url "api-po-line-list" %}',
|
||||||
|
data,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
success: function(response) {
|
||||||
|
// Remove the row
|
||||||
|
$(opts.modal).find(`#order_row_${pk}`).remove();
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
switch (xhr.status) {
|
||||||
|
case 400:
|
||||||
|
handleFormErrors(xhr.responseJSON, fields, row_opts);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(`Error adding line to purchase order`);
|
||||||
|
showApiError(xhr, options.url);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Add callback for "remove row" button
|
// Add callback for "remove row" button
|
||||||
$(opts.modal).find('.button-row-remove').click(function() {
|
$(opts.modal).find('.button-row-remove').click(function() {
|
||||||
var pk = $(this).attr('pk');
|
var pk = $(this).attr('pk');
|
||||||
@ -710,7 +741,7 @@ function orderParts(parts_list, options={}) {
|
|||||||
createPurchaseOrder({
|
createPurchaseOrder({
|
||||||
onSuccess: function(response) {
|
onSuccess: function(response) {
|
||||||
setRelatedFieldData(
|
setRelatedFieldData(
|
||||||
`purchase_order_${pk}`,
|
`order_${pk}`,
|
||||||
response,
|
response,
|
||||||
opts
|
opts
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user