mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add additional test fields (#6149)
* Add new fields for the test results: - Test start timestamp - Test finish timestamp - Test station name * Add is_retest field to the stock_stockitemtestresult items * Remove unnecessary print from migration * Fix test result start/finished date rendering on UI * Remove is_retest field * Rerun pre-commit run --all-files to fix formatting * Fix migrations * Bump API version * Fix API version again
This commit is contained in:
parent
c82713328d
commit
0c661f4f83
@ -16,7 +16,7 @@ repos:
|
||||
- id: check-yaml
|
||||
- id: mixed-line-ending
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.3.0
|
||||
rev: v0.3.3
|
||||
hooks:
|
||||
- id: ruff-format
|
||||
args: [--preview]
|
||||
@ -60,7 +60,7 @@ repos:
|
||||
- "prettier@^2.4.1"
|
||||
- "@trivago/prettier-plugin-sort-imports"
|
||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||
rev: "v9.0.0-beta.1"
|
||||
rev: "v9.0.0-beta.2"
|
||||
hooks:
|
||||
- id: eslint
|
||||
additional_dependencies:
|
||||
|
@ -1,11 +1,14 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 183
|
||||
INVENTREE_API_VERSION = 184
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v184 - 2024-03-17 : https://github.com/inventree/InvenTree/pull/10464
|
||||
- Add additional fields for tests (start/end datetime, test station)
|
||||
|
||||
v183 - 2024-03-14 : https://github.com/inventree/InvenTree/pull/5972
|
||||
- Adds "category_default_location" annotated field to part serializer
|
||||
- Adds "part_detail.category_default_location" annotated field to stock item serializer
|
||||
|
@ -0,0 +1,29 @@
|
||||
# Generated by Django 3.2.23 on 2023-12-18 18:52
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0108_auto_20240219_0252'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='stockitemtestresult',
|
||||
name='finished_datetime',
|
||||
field=models.DateTimeField(blank=True, default=datetime.datetime.now, help_text='The timestamp of the test finish', verbose_name='Finished'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stockitemtestresult',
|
||||
name='started_datetime',
|
||||
field=models.DateTimeField(blank=True, default=datetime.datetime.now, help_text='The timestamp of the test start', verbose_name='Started'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='stockitemtestresult',
|
||||
name='test_station',
|
||||
field=models.CharField(blank=True, help_text='The identifier of the test station where the test was performed', max_length=500, verbose_name='Test station'),
|
||||
),
|
||||
]
|
@ -2363,6 +2363,9 @@ class StockItemTestResult(InvenTree.models.InvenTreeMetadataModel):
|
||||
value: Recorded test output value (optional)
|
||||
attachment: Link to StockItem attachment (optional)
|
||||
notes: Extra user notes related to the test (optional)
|
||||
test_station: the name of the test station where the test was performed
|
||||
started_datetime: Date when the test was started
|
||||
finished_datetime: Date when the test was finished
|
||||
user: User who uploaded the test result
|
||||
date: Date the test result was recorded
|
||||
"""
|
||||
@ -2453,4 +2456,27 @@ class StockItemTestResult(InvenTree.models.InvenTreeMetadataModel):
|
||||
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
test_station = models.CharField(
|
||||
blank=True,
|
||||
max_length=500,
|
||||
verbose_name=_('Test station'),
|
||||
help_text=_('The identifier of the test station where the test was performed'),
|
||||
)
|
||||
|
||||
started_datetime = models.DateTimeField(
|
||||
default=datetime.now,
|
||||
blank=True,
|
||||
verbose_name=_('Started'),
|
||||
help_text=_('The timestamp of the test start'),
|
||||
)
|
||||
|
||||
finished_datetime = models.DateTimeField(
|
||||
default=datetime.now,
|
||||
blank=True,
|
||||
verbose_name=_('Finished'),
|
||||
help_text=_('The timestamp of the test finish'),
|
||||
)
|
||||
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
date = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
|
@ -64,6 +64,9 @@ class StockItemTestResultSerializer(InvenTree.serializers.InvenTreeModelSerializ
|
||||
'value',
|
||||
'attachment',
|
||||
'notes',
|
||||
'test_station',
|
||||
'started_datetime',
|
||||
'finished_datetime',
|
||||
'user',
|
||||
'user_detail',
|
||||
'date',
|
||||
@ -137,7 +140,17 @@ class StockItemTestResultSerializer(InvenTree.serializers.InvenTreeModelSerializ
|
||||
part=stock_item.part, test_name=test_name
|
||||
)
|
||||
|
||||
return super().validate(data)
|
||||
data = super().validate(data)
|
||||
|
||||
started = data.get('started_datetime')
|
||||
finished = data.get('finished_datetime')
|
||||
if started is not None and finished is not None and started > finished:
|
||||
raise ValidationError({
|
||||
'finished_datetime': _(
|
||||
'The test finished time cannot be earlier than the test started time'
|
||||
)
|
||||
})
|
||||
return data
|
||||
|
||||
|
||||
class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
|
@ -2590,6 +2590,9 @@ function constructInput(name, parameters, options={}) {
|
||||
case 'date':
|
||||
func = constructDateInput;
|
||||
break;
|
||||
case 'datetime':
|
||||
func = constructDateTimeInput;
|
||||
break;
|
||||
case 'candy':
|
||||
func = constructCandyInput;
|
||||
break;
|
||||
@ -2860,6 +2863,19 @@ function constructDateInput(name, parameters) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Construct a field for a datetime input
|
||||
*/
|
||||
function constructDateTimeInput(name, parameters) {
|
||||
|
||||
return constructInputOptions(
|
||||
name,
|
||||
'datetimeinput form-control',
|
||||
'datetime',
|
||||
parameters
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct a "candy" field input
|
||||
* No actual field data!
|
||||
|
@ -1367,11 +1367,11 @@ function noResultBadge() {
|
||||
return `<span class='badge badge-right rounded-pill bg-info'>{% trans "NO RESULT" %}</span>`;
|
||||
}
|
||||
|
||||
function formatDate(row) {
|
||||
function formatDate(row, date, options={}) {
|
||||
// Function for formatting date field
|
||||
var html = renderDate(row.date);
|
||||
var html = renderDate(date, options);
|
||||
|
||||
if (row.user_detail) {
|
||||
if (row.user_detail && !options.no_user_detail) {
|
||||
html += `<span class='badge badge-right rounded-pill bg-secondary'>${row.user_detail.username}</span>`;
|
||||
}
|
||||
|
||||
@ -1392,6 +1392,13 @@ function stockItemTestResultFields(options={}) {
|
||||
notes: {
|
||||
icon: 'fa-sticky-note',
|
||||
},
|
||||
test_station: {},
|
||||
started_datetime: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
finished_datetime: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
stock_item: {
|
||||
hidden: true,
|
||||
},
|
||||
@ -1530,7 +1537,30 @@ function loadStockTestResultsTable(table, options) {
|
||||
title: '{% trans "Test Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value, row) {
|
||||
return formatDate(row);
|
||||
return formatDate(row, row.date);
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'test_station',
|
||||
title: '{% trans "Test station" %}',
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
field: 'started_timestamp',
|
||||
title: '{% trans "Test started" %}',
|
||||
sortable: true,
|
||||
visible: false,
|
||||
formatter: function(value, row) {
|
||||
return formatDate(row, row.started_datetime, {showTime: true, no_user_detail: true});
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'finished_timestamp',
|
||||
title: '{% trans "Test finished" %}',
|
||||
sortable: true,
|
||||
visible: false,
|
||||
formatter: function(value, row) {
|
||||
return formatDate(row, row.finished_datetime, {showTime: true, no_user_detail: true});
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -1655,6 +1685,8 @@ function loadStockTestResultsTable(table, options) {
|
||||
fields['stock_item']['value'] = options.stock_item;
|
||||
fields['template']['value'] = templateId;
|
||||
fields['template']['filters']['part'] = options.part;
|
||||
fields['template']['started_datetime']['icon'] = 'fa-calendar-alt';
|
||||
fields['template']['finished_datetime']['icon'] = 'fa-calendar-alt';
|
||||
|
||||
constructForm('{% url "api-stock-test-result-list" %}', {
|
||||
method: 'POST',
|
||||
|
Loading…
x
Reference in New Issue
Block a user