Add confirmation for "over-allocated" stock when completing BuildOrder (#3272)

This commit is contained in:
Oliver 2022-06-29 14:59:55 +10:00 committed by GitHub
parent 825e4b4cd8
commit 73445b4b79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -1018,6 +1018,20 @@ class Build(MPTTModel, ReferenceIndexingMixin):
"""Returns True if the un-tracked parts are fully allocated for this BuildOrder."""
return self.is_fully_allocated(None)
def has_overallocated_parts(self, output):
"""Check if parts have been 'over-allocated' against the specified output.
Note: If output=None, test un-tracked parts
"""
bom_items = self.tracked_bom_items if output else self.untracked_bom_items
for bom_item in bom_items:
if self.allocated_quantity(bom_item, output) > self.required_quantity(bom_item, output):
return True
return False
def unallocated_bom_items(self, output):
"""Return a list of bom items which have *not* been fully allocated against a particular output."""
unallocated = []

View File

@ -466,6 +466,22 @@ class BuildCancelSerializer(serializers.Serializer):
class BuildCompleteSerializer(serializers.Serializer):
"""DRF serializer for marking a BuildOrder as complete."""
accept_overallocated = serializers.BooleanField(
label=_('Accept Overallocated'),
help_text=_('Accept stock items which have been overallocated to this build order'),
required=False,
default=False,
)
def validate_accept_overallocated(self, value):
"""Check if the 'accept_overallocated' field is required"""
build = self.context['build']
if build.has_overallocated_parts(output=None) and not value:
raise ValidationError(_('Some stock items have been overallocated'))
return value
accept_unallocated = serializers.BooleanField(
label=_('Accept Unallocated'),
help_text=_('Accept that stock items have not been fully allocated to this build order'),

View File

@ -174,6 +174,7 @@ function completeBuildOrder(build_id, options={}) {
var fields = {
accept_unallocated: {},
accept_overallocated: {},
accept_incomplete: {},
};