mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
[Plugin] Allow custom plugins for running validation routines (#3776)
* Adds new plugin mixin for performing custom validation steps * Adds simple test plugin for custom validation * Run part name and IPN validators checks through loaded plugins * Expose more validation functions to plugins: - SalesOrder reference - PurchaseOrder reference - BuildOrder reference * Remove custom validation of reference fields - For now, this is too complex to consider given the current incrementing-reference implementation - Might revisit this at a later stage. * Custom validation of serial numbers: - Replace "checkIfSerialNumberExists" method with "validate_serial_number" - Pass serial number through to custom plugins - General code / docstring improvements * Update unit tests * Update InvenTree/stock/tests.py Co-authored-by: Matthias Mair <code@mjmair.com> * Adds global setting to specify whether serial numbers must be unique globally - Default is false to preserve behaviour * Improved error message when attempting to create stock item with invalid serial numbers * Add more detail to existing serial error message * Add unit testing for serial number uniqueness * Allow plugins to convert a serial number to an integer (for optimized sorting) * Add placeholder plugin methods for incrementing and decrementing serial numbers * Typo fix * Add improved method for determining the "latest" serial number * Remove calls to getLatestSerialNumber * Update validate_serial_number method - Add option to disable checking for duplicates - Don't pass optional StockItem through to plugins * Refactor serial number extraction methods - Expose the "incrementing" portion to external plugins * Bug fixes * Update unit tests * Fix for get_latest_serial_number * Ensure custom serial integer values are clipped * Adds a plugin for validating and generating hexadecimal serial numbers * Update unit tests * Add stub methods for batch code functionality * remove "hex serials" plugin - Was simply breaking unit tests * Allow custom plugins to generate and validate batch codes - Perform batch code validation when StockItem is saved - Improve display of error message in modal forms * Fix unit tests for stock app * Log message if plugin has a duplicate slug * Unit test fix Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="SERIAL_NUMBER_GLOBALLY_UNIQUE" icon="fa-hashtag" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_BATCH_CODE_TEMPLATE" icon="fa-layer-group" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_ENABLE_EXPIRY" icon="fa-stopwatch" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="STOCK_STALE_DAYS" icon="fa-calendar" %}
|
||||
|
@ -1230,12 +1230,7 @@ function handleNestedErrors(errors, field_name, options={}) {
|
||||
// Find the target (nested) field
|
||||
var target = `${field_name}_${sub_field_name}_${nest_id}`;
|
||||
|
||||
for (var ii = errors.length-1; ii >= 0; ii--) {
|
||||
|
||||
var error_text = errors[ii];
|
||||
|
||||
addFieldErrorMessage(target, error_text, ii, options);
|
||||
}
|
||||
addFieldErrorMessage(target, errors, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1312,13 +1307,7 @@ function handleFormErrors(errors, fields={}, options={}) {
|
||||
first_error_field = field_name;
|
||||
}
|
||||
|
||||
// Add an entry for each returned error message
|
||||
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, field_errors, options);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1341,6 +1330,16 @@ function handleFormErrors(errors, fields={}, options={}) {
|
||||
*/
|
||||
function addFieldErrorMessage(name, error_text, error_idx=0, options={}) {
|
||||
|
||||
// Handle a 'list' of error message recursively
|
||||
if (typeof(error_text) == 'object') {
|
||||
// Iterate backwards through the list
|
||||
for (var ii = error_text.length - 1; ii >= 0; ii--) {
|
||||
addFieldErrorMessage(name, error_text[ii], ii, options);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
field_name = getFieldName(name, options);
|
||||
|
||||
var field_dom = null;
|
||||
|
Reference in New Issue
Block a user