mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Build start date (#8915)
* Add 'start_date' to Build model * Add to serializer * Add filtering and ordering * Update BuildOrderTable - Add new column - Add new filtering options * Add sanity check for start_date * Add 'start_date' field to BuildOrder form * Update docs * Bump API version * Tweak unit testing * Display 'start_date' on build page * Refactor UI tests * Fix for 'date' field in forms * Add additional unit tests * Fix helper func * Remove debug msg
This commit is contained in:
@ -1,13 +1,17 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 302
|
||||
INVENTREE_API_VERSION = 303
|
||||
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
|
||||
v303 - 2025-01-20 - https://github.com/inventree/InvenTree/pull/8915
|
||||
- Adds "start_date" field to Build model and API endpoints
|
||||
- Adds additional API filtering and sorting options for Build list
|
||||
|
||||
v302 - 2025-01-18 - https://github.com/inventree/InvenTree/pull/8905
|
||||
- Fix schema definition on the /label/print endpoint
|
||||
|
||||
|
@ -188,6 +188,30 @@ class BuildFilter(rest_filters.FilterSet):
|
||||
label=_('Created after'), field_name='creation_date', lookup_expr='gt'
|
||||
)
|
||||
|
||||
has_start_date = rest_filters.BooleanFilter(
|
||||
label=_('Has start date'), method='filter_has_start_date'
|
||||
)
|
||||
|
||||
def filter_has_start_date(self, queryset, name, value):
|
||||
"""Filter by whether or not the order has a start date."""
|
||||
return queryset.filter(start_date__isnull=not str2bool(value))
|
||||
|
||||
start_date_before = InvenTreeDateFilter(
|
||||
label=_('Start date before'), field_name='start_date', lookup_expr='lt'
|
||||
)
|
||||
|
||||
start_date_after = InvenTreeDateFilter(
|
||||
label=_('Start date after'), field_name='start_date', lookup_expr='gt'
|
||||
)
|
||||
|
||||
has_target_date = rest_filters.BooleanFilter(
|
||||
label=_('Has target date'), method='filter_has_target_date'
|
||||
)
|
||||
|
||||
def filter_has_target_date(self, queryset, name, value):
|
||||
"""Filter by whether or not the order has a target date."""
|
||||
return queryset.filter(target_date__isnull=not str2bool(value))
|
||||
|
||||
target_date_before = InvenTreeDateFilter(
|
||||
label=_('Target date before'), field_name='target_date', lookup_expr='lt'
|
||||
)
|
||||
@ -244,6 +268,7 @@ class BuildList(DataExportViewMixin, BuildMixin, ListCreateAPI):
|
||||
'part__name',
|
||||
'status',
|
||||
'creation_date',
|
||||
'start_date',
|
||||
'target_date',
|
||||
'completion_date',
|
||||
'quantity',
|
||||
|
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.18 on 2025-01-20 02:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('build', '0053_alter_build_part'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='build',
|
||||
name='start_date',
|
||||
field=models.DateField(blank=True, help_text='Scheduled start date for this build order', null=True, verbose_name='Build start date'),
|
||||
),
|
||||
]
|
@ -178,6 +178,12 @@ class Build(
|
||||
if self.has_field_changed('part'):
|
||||
raise ValidationError({'part': _('Build order part cannot be changed')})
|
||||
|
||||
# Target date should be *after* the start date
|
||||
if self.start_date and self.target_date and self.start_date > self.target_date:
|
||||
raise ValidationError({
|
||||
'target_date': _('Target date must be after start date')
|
||||
})
|
||||
|
||||
def report_context(self) -> dict:
|
||||
"""Generate custom report context data."""
|
||||
return {
|
||||
@ -344,6 +350,13 @@ class Build(
|
||||
auto_now_add=True, editable=False, verbose_name=_('Creation Date')
|
||||
)
|
||||
|
||||
start_date = models.DateField(
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name=_('Build start date'),
|
||||
help_text=_('Scheduled start date for this build order'),
|
||||
)
|
||||
|
||||
target_date = models.DateField(
|
||||
null=True,
|
||||
blank=True,
|
||||
|
@ -81,6 +81,7 @@ class BuildSerializer(
|
||||
'reference',
|
||||
'sales_order',
|
||||
'quantity',
|
||||
'start_date',
|
||||
'status',
|
||||
'status_text',
|
||||
'status_custom_key',
|
||||
|
Reference in New Issue
Block a user