Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable the build output completion if are tests not passed #6057

Merged
merged 14 commits into from
Feb 17, 2024
Merged
19 changes: 19 additions & 0 deletions InvenTree/build/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from stock.models import generate_batch_code, StockItem, StockLocation
from stock.serializers import StockItemSerializerBrief, LocationSerializer

import common.settings
from common.serializers import ProjectCodeSerializer
import part.filters
from part.serializers import BomItemSerializer, PartSerializer, PartBriefSerializer
Expand Down Expand Up @@ -519,6 +520,24 @@ def validate(self, data):

outputs = data.get('outputs', [])

if common.settings.prevent_build_output_complete_on_incompleted_tests:
error_string = ''
fail_count = 0

for output in outputs:
stock_item = output['output']
if stock_item.hasRequiredTests() and not stock_item.passedAllRequiredTests():
if stock_item.part.trackable:
if len(error_string):
error_string += "<br>"
martonmiklos marked this conversation as resolved.
Show resolved Hide resolved
error_string += _("The %s stock item was not passed on all of the required tests" % stock_item.serial)
else:
fail_count += stock_item.quantity
if fail_count:
error_string = _("The %d stock item(s) was not passed on all required tests" % fail_count)
if len(error_string):
raise ValidationError(error_string)

if len(outputs) == 0:
raise ValidationError(_("A list of build outputs must be provided"))

Expand Down
7 changes: 7 additions & 0 deletions InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,13 @@ def save(self, *args, **kwargs):
'description': _('Display Users full names instead of usernames'),
'default': False,
'validator': bool
},

'PREVENT_BUILD_COMPLETION_HAVING_INCOMPLETED_TESTS': {
'name': _('Block build orders until required tests are completed'),
martonmiklos marked this conversation as resolved.
Show resolved Hide resolved
'description': _('Would you like required tests to be mandatory passed for completing build orders?'),
martonmiklos marked this conversation as resolved.
Show resolved Hide resolved
'default': False,
'validator': bool
}
}

Expand Down
7 changes: 7 additions & 0 deletions InvenTree/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ def stock_expiry_enabled():
from common.models import InvenTreeSetting

return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY', False, create=False)


def prevent_build_output_complete_on_incompleted_tests():
"""Returns True if the completion of the build outputs is disabled until the required tests are passed."""
from common.models import InvenTreeSetting

return InvenTreeSetting.get_setting('PREVENT_BUILD_COMPLETION_HAVING_INCOMPLETED_TESTS', False, create=False)
1 change: 1 addition & 0 deletions InvenTree/templates/InvenTree/settings/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<table class='table table-striped table-condensed'>
<tbody>
{% include "InvenTree/settings/setting.html" with key="BUILDORDER_REFERENCE_PATTERN" %}
{% include "InvenTree/settings/setting.html" with key="PREVENT_BUILD_COMPLETION_HAVING_INCOMPLETED_TESTS" %}
martonmiklos marked this conversation as resolved.
Show resolved Hide resolved
</tbody>
</table>

Expand Down
Loading