Improvements

- part_detail defaults to True for BuildSerializer
- Handle invalid parent for BuildOrder
This commit is contained in:
Oliver 2021-07-09 00:49:19 +10:00
parent be6ecd9587
commit bec98d355a
2 changed files with 12 additions and 2 deletions

View File

@ -21,6 +21,7 @@ from django.core.validators import MinValueValidator
from markdownx.models import MarkdownxField
from mptt.models import MPTTModel, TreeForeignKey
from mptt.exceptions import InvalidMove
from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode
from InvenTree.helpers import increment, getSetting, normalize, MakeBarcode
@ -89,11 +90,20 @@ class Build(MPTTModel):
responsible: User (or group) responsible for completing the build
"""
OVERDUE_FILTER = Q(status__in=BuildStatus.ACTIVE_CODES) & ~Q(target_date=None) & Q(target_date__lte=datetime.now().date())
@staticmethod
def get_api_url():
return reverse('api-build-list')
OVERDUE_FILTER = Q(status__in=BuildStatus.ACTIVE_CODES) & ~Q(target_date=None) & Q(target_date__lte=datetime.now().date())
def save(self, *args, **kwargs):
try:
super().save(*args, **kwargs)
except InvalidMove:
raise ValidationError({
'parent': _('Invalid choice for parent build'),
})
class Meta:
verbose_name = _("Build Order")

View File

@ -62,7 +62,7 @@ class BuildSerializer(InvenTreeModelSerializer):
return queryset
def __init__(self, *args, **kwargs):
part_detail = kwargs.pop('part_detail', False)
part_detail = kwargs.pop('part_detail', True)
super().__init__(*args, **kwargs)