mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Handle 'next serial' more gracefully
This commit is contained in:
parent
c31b30bf83
commit
23cc3d9b06
@ -14,6 +14,8 @@ from django.urls import reverse
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Sum
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.db.models import IntegerField
|
||||
from django.db.models.functions import Cast
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@ -329,7 +331,8 @@ class Part(MPTTModel):
|
||||
"""
|
||||
|
||||
parts = Part.objects.filter(tree_id=self.tree_id)
|
||||
stock = StockModels.StockItem.objects.filter(part__in=parts).exclude(serial=None).order_by('-serial')
|
||||
stock = StockModels.StockItem.objects.filter(part__in=parts).exclude(serial=None).annotate(
|
||||
serial_as_int=Cast('serial', output_field=IntegerField())).order_by('-serial_as_int')
|
||||
|
||||
if stock.count() > 0:
|
||||
return stock.first().serial
|
||||
|
@ -391,8 +391,8 @@ class VariantTest(StockTest):
|
||||
with self.assertRaises(ValidationError):
|
||||
item.save()
|
||||
|
||||
# This should pass
|
||||
item.serial = n + 1
|
||||
# This should pass, although not strictly an int field now.
|
||||
item.serial = int(n) + 1
|
||||
item.save()
|
||||
|
||||
# Attempt to create the same serial number but for a variant (should fail!)
|
||||
|
Loading…
Reference in New Issue
Block a user