[Feature] Shipment Creation in Stock Allocation Modal (#3024)

* Added order reference to line item options

* Basic working version implemented

* Re-execute fields function in secondary modals

* Added missing argument and parameter

* Added missing parentheses

* Fixed hidden field name for depth > 0
This commit is contained in:
Maksim Stojkovic 2022-05-22 09:34:38 +10:00 committed by GitHub
parent 40153b94a5
commit 0ec067da40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 5 deletions

View File

@ -257,6 +257,7 @@
'#so-lines-table',
{
order: {{ order.pk }},
reference: '{{ order.reference }}',
status: {{ order.status }},
}
);

View File

@ -913,7 +913,7 @@ function getFormFieldElement(name, options) {
el = $(`#id_${field_name}`);
}
if (!el.exists) {
if (!el.exists()) {
console.error(`Could not find form element for field '${name}'`);
}
@ -1568,11 +1568,18 @@ function addSecondaryModal(field, fields, options) {
var url = secondary.api_url || field.api_url;
// If the "fields" attribute is a function, call it with data
if (secondary.fields instanceof Function) {
if (secondary.fields instanceof Function || secondary.fieldsFunction instanceof Function) {
// Extract form values at time of button press
var data = extractFormData(fields, options);
// Backup and execute fields function in sequential executions of modal
if (secondary.fields instanceof Function) {
secondary.fieldsFunction = secondary.fields;
} else if (secondary.fieldsFunction instanceof Function) {
secondary.fields = secondary.fieldsFunction;
}
secondary.fields = secondary.fields(data);
}
@ -2012,7 +2019,7 @@ function constructField(name, parameters, options={}) {
// Hidden inputs are rendered without label / help text / etc
if (parameters.hidden) {
return constructHiddenInput(name, parameters, options);
return constructHiddenInput(field_name, parameters, options);
}
// Are we ending a group?
@ -2361,13 +2368,14 @@ function constructInputOptions(name, classes, type, parameters, options={}) {
// Construct a "hidden" input
function constructHiddenInput(name, parameters) {
function constructHiddenInput(name, parameters, options={}) {
return constructInputOptions(
name,
'hiddeninput',
'hidden',
parameters
parameters,
options
);
}

View File

@ -2593,6 +2593,55 @@ function allocateStockToSalesOrder(order_id, line_items, options={}) {
},
value: options.shipment || null,
auto_fill: true,
secondary: {
method: 'POST',
title: '{% trans "Add Shipment" %}',
fields: function() {
var ref = null;
// TODO: Refactor code for getting next shipment number
inventreeGet(
'{% url "api-so-shipment-list" %}',
{
order: options.order,
},
{
async: false,
success: function(results) {
// "predict" the next reference number
ref = results.length + 1;
var found = false;
while (!found) {
var no_match = true;
for (var ii = 0; ii < results.length; ii++) {
if (ref.toString() == results[ii].reference.toString()) {
no_match = false;
break;
}
}
if (no_match) {
break;
} else {
ref++;
}
}
}
}
);
var fields = salesOrderShipmentFields(options);
fields.reference.value = ref;
fields.reference.prefix = global_settings.SALESORDER_REFERENCE_PREFIX + options.reference;
return fields;
}
}
}
},
preFormContent: html,
@ -3475,6 +3524,8 @@ function loadSalesOrderLineItemTable(table, options={}) {
line_item
],
{
order: options.order,
reference: options.reference,
success: function() {
// Reload this table
$(table).bootstrapTable('refresh');