mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add confirmation for "over-allocated" stock when completing BuildOrder (#3272)
This commit is contained in:
parent
825e4b4cd8
commit
73445b4b79
@ -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 = []
|
||||
|
@ -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'),
|
||||
|
@ -174,6 +174,7 @@ function completeBuildOrder(build_id, options={}) {
|
||||
|
||||
var fields = {
|
||||
accept_unallocated: {},
|
||||
accept_overallocated: {},
|
||||
accept_incomplete: {},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user