2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-04 10:31:03 +00:00

Update "date" field for StockItemTestResult (#11586)

* Update "date" field for StockItemTestResult

- Allow editing of date (via admin)

* Mark 'date' and 'user' as read-only unless importing

* Revert API field name

* Fix default value

* Fix migration

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
Oliver
2026-03-31 07:13:12 +11:00
committed by GitHub
parent 5c07ef2847
commit 092c43b49a
4 changed files with 37 additions and 4 deletions

View File

@@ -24,11 +24,11 @@ class DataImportSerializerMixin:
Determine if the serializer is being used for data import, Determine if the serializer is being used for data import,
and if so, adjust the serializer fields accordingly. and if so, adjust the serializer fields accordingly.
""" """
importing = kwargs.pop('importing', False) self._is_importing = kwargs.pop('importing', False)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if importing: if self._is_importing:
# Exclude any fields which are not able to be imported # Exclude any fields which are not able to be imported
importable_field_names = list(self.get_importable_fields().keys()) importable_field_names = list(self.get_importable_fields().keys())
field_names = list(self.fields.keys()) field_names = list(self.fields.keys())

View File

@@ -0,0 +1,22 @@
# Generated by Django 5.2.12 on 2026-03-21 08:00
import InvenTree.helpers
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("stock", "0118_auto_20260205_1218"),
]
operations = [
migrations.AlterField(
model_name="stockitemtestresult",
name="date",
field=models.DateTimeField(
default=InvenTree.helpers.current_time,
verbose_name="Date"
),
),
]

View File

@@ -3101,4 +3101,6 @@ class StockItemTestResult(InvenTree.models.InvenTreeMetadataModel):
help_text=_('The timestamp of the test finish'), help_text=_('The timestamp of the test finish'),
) )
date = models.DateTimeField(auto_now_add=True, editable=False) date = models.DateTimeField(
default=InvenTree.helpers.current_time, verbose_name=_('Date')
)

View File

@@ -220,7 +220,16 @@ class StockItemTestResultSerializer(
'template', 'template',
'template_detail', 'template_detail',
] ]
read_only_fields = ['pk', 'user', 'date'] read_only_fields = ['pk']
def __init__(self, *args, **kwargs):
"""Handle custom initialization for the serializer."""
super().__init__(*args, **kwargs)
if not self._is_importing:
# Unless we are importing data, mark the 'user' and 'date' fields as read-only
self.fields['user'].read_only = True
self.fields['date'].read_only = True
user_detail = enable_filter( user_detail = enable_filter(
UserSerializer(source='user', read_only=True, allow_null=True), UserSerializer(source='user', read_only=True, allow_null=True),