2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-07-10 00:50:57 +00:00

fix(backend): import session metadata (#12184)

* add storage for historic import metadata for reporting and display purposes

fixes breakage fromhttps://github.com/inventree/InvenTree/pull/12169

* add api bump

* re-enable test

* fix migration

* ensure session is not overwritten

* fix statusrender without custom key
This commit is contained in:
Matthias Mair
2026-06-18 00:10:32 +02:00
committed by GitHub
parent c262efb25f
commit f602714dc9
11 changed files with 69 additions and 14 deletions
@@ -1,11 +1,14 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 508
INVENTREE_API_VERSION = 509
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v509 -> 2026-06-17 : https://github.com/inventree/InvenTree/pull/12184
- Adds "completed_row_count_history" and "row_count_history" fields to the DataImportSession model, which store the historic count of completed rows and total rows for a data import session.
v508 -> 2026-06-17 : https://github.com/inventree/InvenTree/pull/11982
- An order's "status_custom_key" can be updated via PATCH API endpoint
@@ -0,0 +1,23 @@
# Generated by Django 5.2.15 on 2026-06-17 05:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('importer', '0006_dataimportcolumnmap_lookup_field'),
]
operations = [
migrations.AddField(
model_name='dataimportsession',
name='completed_row_count_history',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Completed Row Count History'),
),
migrations.AddField(
model_name='dataimportsession',
name='row_count_history',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Row Count History'),
),
]
+14
View File
@@ -385,7 +385,13 @@ class DataImportSession(models.Model):
if self.status != DataImportStatusCode.COMPLETE.value:
self.status = DataImportStatusCode.COMPLETE.value
# persist historic count values for reporting purposes
self.completed_row_count_history = self.completed_row_count
self.row_count_history = self.row_count
self.save()
# Clear staging data now that all rows have been imported
self.rows.all().delete()
self.column_mappings.all().delete()
@@ -402,6 +408,14 @@ class DataImportSession(models.Model):
"""Return the number of completed rows for this session."""
return self.rows.filter(complete=True).count()
# Historic values for reporting purposes
completed_row_count_history = models.PositiveIntegerField(
blank=True, null=True, verbose_name=_('Completed Row Count History')
)
row_count_history = models.PositiveIntegerField(
blank=True, null=True, verbose_name=_('Row Count History')
)
def available_fields(self):
"""Returns information on the available fields.
@@ -62,6 +62,8 @@ class DataImportSessionSerializer(InvenTreeModelSerializer):
'field_filters',
'row_count',
'completed_row_count',
'completed_row_count_history',
'row_count_history',
]
read_only_fields = ['pk', 'user', 'status', 'columns']
@@ -220,6 +222,8 @@ class DataImportAcceptRowSerializer(serializers.Serializer):
row.validate(commit=True, request=request)
if session := self.context.get('session', None):
# ensure current state is available
session.refresh_from_db()
session.check_complete()
return rows