mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Validate and save the new serailizer
This commit is contained in:
parent
960784644f
commit
12b3a5c9cc
@ -275,6 +275,7 @@ class BuildFinish(generics.CreateAPIView):
|
|||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
class BuildAllocate(generics.CreateAPIView):
|
class BuildAllocate(generics.CreateAPIView):
|
||||||
"""
|
"""
|
||||||
API endpoint to allocate stock items to a build order
|
API endpoint to allocate stock items to a build order
|
||||||
|
@ -555,7 +555,7 @@ class Build(MPTTModel, ReferenceIndexingMixin):
|
|||||||
if self.incomplete_count > 0:
|
if self.incomplete_count > 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.completed < self.quantity:
|
if self.remaining > 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not self.areUntrackedPartsFullyAllocated():
|
if not self.areUntrackedPartsFullyAllocated():
|
||||||
|
@ -250,13 +250,35 @@ class BuildCompleteSerializer(serializers.Serializer):
|
|||||||
help_text=_('Accept that stock items have not been fully allocated to this build order'),
|
help_text=_('Accept that stock items have not been fully allocated to this build order'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_accept_unallocated(self, value):
|
||||||
|
|
||||||
|
build = self.context['build']
|
||||||
|
|
||||||
|
if not build.areUntrackedPartsFullyAllocated() and not value:
|
||||||
|
raise ValidationError(_('Required stock has not been fully allocated'))
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
accept_incomplete = serializers.BooleanField(
|
accept_incomplete = serializers.BooleanField(
|
||||||
label=_('Accept Incomplete'),
|
label=_('Accept Incomplete'),
|
||||||
help_text=_('Accept that the required number of build outputs have not been completed'),
|
help_text=_('Accept that the required number of build outputs have not been completed'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_accept_incomplete(self, value):
|
||||||
|
|
||||||
|
build = self.context['build']
|
||||||
|
|
||||||
|
if build.remaining > 0 and not value:
|
||||||
|
raise ValidationError(_('Required build quantity has not been completed'))
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
pass
|
|
||||||
|
request = self.context['request']
|
||||||
|
build = self.context['build']
|
||||||
|
|
||||||
|
build.complete_build(request.user)
|
||||||
|
|
||||||
|
|
||||||
class BuildUnallocationSerializer(serializers.Serializer):
|
class BuildUnallocationSerializer(serializers.Serializer):
|
||||||
|
@ -224,6 +224,13 @@ src="{% static 'img/blank_image.png' %}"
|
|||||||
'{% trans "Build Order cannot be completed as incomplete build outputs remain" %}'
|
'{% trans "Build Order cannot be completed as incomplete build outputs remain" %}'
|
||||||
);
|
);
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
|
completeBuildOrder({{ build.pk }}, {
|
||||||
|
allocated: {% if build.areUntrackedPartsFullyAllocated %}true{% else %}false{% endif %},
|
||||||
|
completed: {% if build.remaining == 0 %}true{% else %}false{% endif %},
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
launchModalForm(
|
launchModalForm(
|
||||||
"{% url 'build-complete' build.id %}",
|
"{% url 'build-complete' build.id %}",
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
allocateStockToBuild,
|
allocateStockToBuild,
|
||||||
|
completeBuildOrder,
|
||||||
editBuildOrder,
|
editBuildOrder,
|
||||||
loadAllocationTable,
|
loadAllocationTable,
|
||||||
loadBuildOrderAllocationTable,
|
loadBuildOrderAllocationTable,
|
||||||
@ -120,6 +121,57 @@ function newBuildOrder(options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Construct a form to "complete" (finish) a build order */
|
||||||
|
function completeBuildOrder(build_id, options={}) {
|
||||||
|
|
||||||
|
var url = `/api/build/${build_id}/finish/`;
|
||||||
|
|
||||||
|
var fields = {
|
||||||
|
accept_unallocated: {},
|
||||||
|
accept_incomplete: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
|
||||||
|
if (options.can_complete) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
html += `
|
||||||
|
<div class='alert alert-block alert-danger'>
|
||||||
|
<strong>{% trans "Build Order is incomplete" %}</strong>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (!options.allocated) {
|
||||||
|
html += `<div class='alert alert-block alert-warning'>{% trans "Required stock has not been fully allocated" %}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.completed) {
|
||||||
|
html += `<div class='alert alert-block alert-warning'>{% trans "Required build quantity has not been completed" %}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide particular fields if they are not required
|
||||||
|
|
||||||
|
if (options.allocated) {
|
||||||
|
delete fields.accept_unallocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.completed) {
|
||||||
|
delete fields.accept_incomplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructForm(url, {
|
||||||
|
fields: fields,
|
||||||
|
reload: true,
|
||||||
|
confirm: true,
|
||||||
|
method: 'POST',
|
||||||
|
title: '{% trans "Complete Build Order" %}',
|
||||||
|
preFormContent: html,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Construct a set of output buttons for a particular build output
|
* Construct a set of output buttons for a particular build output
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user