2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-23 17:37:38 +00:00

[bug] Remove 'project_code' from optional fields (#10646)

* Remove 'project_code' from optional fields

- enable_filter overrides field options
- Field does not auto-describe as a related field any more
- Breaks front-end forms

* Unit tests

* Include fix for currency

- Ref: https://github.com/inventree/InvenTree/pull/10645

* Cleanup import

* Adjust unit tests
This commit is contained in:
Oliver
2025-10-21 21:06:59 +11:00
committed by GitHub
parent f8fd9f5f07
commit 19dfb51969
3 changed files with 45 additions and 17 deletions

View File

@@ -33,7 +33,6 @@ from generic.states.fields import InvenTreeCustomStatusSerializerMixin
from InvenTree.mixins import DataImportExportSerializerMixin from InvenTree.mixins import DataImportExportSerializerMixin
from InvenTree.serializers import ( from InvenTree.serializers import (
FilterableCharField, FilterableCharField,
FilterableIntegerField,
FilterableSerializerMixin, FilterableSerializerMixin,
InvenTreeDecimalField, InvenTreeDecimalField,
InvenTreeModelSerializer, InvenTreeModelSerializer,
@@ -164,17 +163,6 @@ class BuildSerializer(
filter_name='project_code_detail', filter_name='project_code_detail',
) )
project_code = enable_filter(
FilterableIntegerField(
allow_null=True,
required=False,
label=_('Project Code'),
help_text=_('Project code for this build order'),
),
True,
filter_name='project_code_detail',
)
@staticmethod @staticmethod
def annotate_queryset(queryset): def annotate_queryset(queryset):
"""Add custom annotations to the BuildSerializer queryset, performing database queries as efficiently as possible. """Add custom annotations to the BuildSerializer queryset, performing database queries as efficiently as possible.

View File

@@ -1086,6 +1086,51 @@ class BuildListTest(BuildAPITest):
url = reverse('api-build-list') url = reverse('api-build-list')
def test_api_options(self):
"""Test OPTIONS endpoint for the Build list API."""
data = self.options(self.url, expected_code=200).data
self.assertEqual(data['name'], 'Build List')
actions = data['actions']['POST']
for field_name in [
'pk',
'title',
'part',
'part_detail',
'project_code',
'project_code_detail',
'quantity',
]:
self.assertIn(field_name, actions)
# Specific checks for certain fields
for field_name in ['part', 'project_code', 'take_from']:
field = actions[field_name]
self.assertEqual(field['type'], 'related field')
for key in ['model', 'api_url', 'pk_field']:
self.assertIn(key, field)
def test_detail_fields(self):
"""Test inclusion of detail fields."""
# Test without extra detail fields
for val in [True, False]:
response = self.get(
self.url,
data={'part_detail': val, 'project_code_detail': val, 'limit': 1},
expected_code=200,
)
data = response.data['results'][0]
if val:
self.assertIn('part_detail', data)
self.assertIn('project_code_detail', data)
else:
self.assertNotIn('part_detail', data)
self.assertNotIn('project_code_detail', data)
def test_get_all_builds(self): def test_get_all_builds(self):
"""Retrieve *all* builds via the API.""" """Retrieve *all* builds via the API."""
builds = self.get(self.url) builds = self.get(self.url)
@@ -1195,7 +1240,6 @@ class BuildListTest(BuildAPITest):
self.url, self.url,
[ [
'part_detail', 'part_detail',
('project_code_detail', 'project_code'),
'project_code_detail', 'project_code_detail',
('user_detail', 'responsible_detail'), ('user_detail', 'responsible_detail'),
('user_detail', 'issued_by_detail'), ('user_detail', 'issued_by_detail'),

View File

@@ -11,7 +11,6 @@ import structlog
from moneyed import CURRENCIES from moneyed import CURRENCIES
import InvenTree.helpers import InvenTree.helpers
import InvenTree.ready
logger = structlog.get_logger('inventree') logger = structlog.get_logger('inventree')
@@ -20,9 +19,6 @@ def currency_code_default(create: bool = True):
"""Returns the default currency code (or USD if not specified).""" """Returns the default currency code (or USD if not specified)."""
from common.settings import get_global_setting from common.settings import get_global_setting
if InvenTree.ready.isRunningMigrations():
return '' # pragma: no cover
try: try:
code = get_global_setting( code = get_global_setting(
'INVENTREE_DEFAULT_CURRENCY', create=create, cache=True 'INVENTREE_DEFAULT_CURRENCY', create=create, cache=True