mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
Add option for controlling test result uploads (#8076)
* Fix typo * Add new setting * Gate creation of new test result template * Refactor test result template validation * Update API unit testing
This commit is contained in:
parent
e3205184be
commit
9b272bd60f
@ -188,6 +188,7 @@ Configuration of stock item options
|
|||||||
{{ globalsetting("STOCK_ENFORCE_BOM_INSTALLATION") }}
|
{{ globalsetting("STOCK_ENFORCE_BOM_INSTALLATION") }}
|
||||||
{{ globalsetting("STOCK_ALLOW_OUT_OF_STOCK_TRANSFER") }}
|
{{ globalsetting("STOCK_ALLOW_OUT_OF_STOCK_TRANSFER") }}
|
||||||
{{ globalsetting("TEST_STATION_DATA") }}
|
{{ globalsetting("TEST_STATION_DATA") }}
|
||||||
|
{{ globalsetting("TEST_UPLOAD_CREATE_TEMPLATE") }}
|
||||||
|
|
||||||
### Build Orders
|
### Build Orders
|
||||||
|
|
||||||
|
@ -2160,6 +2160,14 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'default': False,
|
'default': False,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
'TEST_UPLOAD_CREATE_TEMPLATE': {
|
||||||
|
'name': _('Create Template on Upload'),
|
||||||
|
'description': _(
|
||||||
|
'Create a new test template when uploading test data which does not match an existing template'
|
||||||
|
),
|
||||||
|
'default': True,
|
||||||
|
'validator': bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
typ = 'inventree'
|
typ = 'inventree'
|
||||||
|
@ -2429,19 +2429,16 @@ class StockItemTestResult(InvenTree.models.InvenTreeMetadataModel):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# If this test result corresponds to a template, check the requirements of the template
|
# If this test result corresponds to a template, check the requirements of the template
|
||||||
|
try:
|
||||||
template = self.template
|
template = self.template
|
||||||
|
except PartModels.PartTestTemplate.DoesNotExist:
|
||||||
|
template = None
|
||||||
|
|
||||||
if template is None:
|
if not template:
|
||||||
# Fallback if there is no matching template
|
raise ValidationError({'template': _('Test template does not exist')})
|
||||||
for template in self.stock_item.part.getTestTemplates():
|
|
||||||
if self.key == template.key:
|
|
||||||
break
|
|
||||||
|
|
||||||
if template:
|
|
||||||
if template.requires_value and not self.value:
|
if template.requires_value and not self.value:
|
||||||
raise ValidationError({
|
raise ValidationError({'value': _('Value must be provided for this test')})
|
||||||
'value': _('Value must be provided for this test')
|
|
||||||
})
|
|
||||||
|
|
||||||
if template.requires_attachment and not self.attachment:
|
if template.requires_attachment and not self.attachment:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
|
@ -268,13 +268,13 @@ class StockItemTestResultSerializer(
|
|||||||
).first():
|
).first():
|
||||||
data['template'] = template
|
data['template'] = template
|
||||||
|
|
||||||
else:
|
elif get_global_setting('TEST_UPLOAD_CREATE_TEMPLATE', False):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"No matching test template found for '%s' - creating a new template",
|
"No matching test template found for '%s' - creating a new template",
|
||||||
test_name,
|
test_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create a new test template based on the provided dasta
|
# Create a new test template based on the provided data
|
||||||
data['template'] = part_models.PartTestTemplate.objects.create(
|
data['template'] = part_models.PartTestTemplate.objects.create(
|
||||||
part=stock_item.part, test_name=test_name
|
part=stock_item.part, test_name=test_name
|
||||||
)
|
)
|
||||||
|
@ -1716,6 +1716,14 @@ class StockTestResultTest(StockAPITestCase):
|
|||||||
'notes': 'I guess there was just too much pressure?',
|
'notes': 'I guess there was just too much pressure?',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# First, test with TEST_UPLOAD_CREATE_TEMPLATE set to False
|
||||||
|
InvenTreeSetting.set_setting('TEST_UPLOAD_CREATE_TEMPLATE', False, self.user)
|
||||||
|
|
||||||
|
response = self.post(url, data, expected_code=400)
|
||||||
|
|
||||||
|
# Again, with the setting enabled
|
||||||
|
InvenTreeSetting.set_setting('TEST_UPLOAD_CREATE_TEMPLATE', True, self.user)
|
||||||
|
|
||||||
response = self.post(url, data, expected_code=201)
|
response = self.post(url, data, expected_code=201)
|
||||||
|
|
||||||
# Check that a new test template has been created
|
# Check that a new test template has been created
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
{% include "InvenTree/settings/setting.html" with key="STOCK_ENFORCE_BOM_INSTALLATION" icon="fa-check-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="STOCK_ENFORCE_BOM_INSTALLATION" icon="fa-check-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_OUT_OF_STOCK_TRANSFER" icon="fa-dolly" %}
|
{% include "InvenTree/settings/setting.html" with key="STOCK_ALLOW_OUT_OF_STOCK_TRANSFER" icon="fa-dolly" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="TEST_STATION_DATA" icon="fa-network-wired" %}
|
{% include "InvenTree/settings/setting.html" with key="TEST_STATION_DATA" icon="fa-network-wired" %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="TEST_UPLOAD_CREATE_TEMPLATE" %}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -221,7 +221,8 @@ export default function SystemSettings() {
|
|||||||
'STOCK_SHOW_INSTALLED_ITEMS',
|
'STOCK_SHOW_INSTALLED_ITEMS',
|
||||||
'STOCK_ENFORCE_BOM_INSTALLATION',
|
'STOCK_ENFORCE_BOM_INSTALLATION',
|
||||||
'STOCK_ALLOW_OUT_OF_STOCK_TRANSFER',
|
'STOCK_ALLOW_OUT_OF_STOCK_TRANSFER',
|
||||||
'TEST_STATION_DATA'
|
'TEST_STATION_DATA',
|
||||||
|
'TEST_UPLOAD_CREATE_TEMPLATE'
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user