Add button to mark a purchase order as complete, even if not all line items are received

This commit is contained in:
Oliver Walters 2019-12-05 10:29:16 +11:00
parent 3f172cb065
commit 7f2804dff3
6 changed files with 78 additions and 0 deletions

View File

@ -27,6 +27,17 @@ class IssuePurchaseOrderForm(HelperForm):
]
class CompletePurchaseOrderForm(HelperForm):
confirm = forms.BooleanField(required=False, help_text=_("Mark order as complete"))
class Meta:
model = PurchaseOrder
fields = [
'confirm',
]
class CancelPurchaseOrderForm(HelperForm):
confirm = forms.BooleanField(required=False, help_text=_('Cancel order'))

View File

@ -188,6 +188,12 @@ class PurchaseOrder(Order):
return self.lines.filter(quantity__gt=F('received'))
@property
def is_complete(self):
""" Return True if all line items have been received """
return self.pending_line_items().count() == 0
@transaction.atomic
def receive_line_item(self, line, location, quantity, user):
""" Receive a line item (or partial line item) against this PO

View File

@ -0,0 +1,13 @@
{% extends "modal_form.html" %}
{% block pre_form_content %}
Mark this order as complete?
{% if not order.is_complete %}
<div class='alert alert-warning alert-block'>
This order has line items which have not been marked as received.
Marking this order as complete will remove these line items.
</div>
{% endif %}
{% endblock %}

View File

@ -44,6 +44,9 @@ InvenTree | {{ order }}
<button type='button' class='btn btn-default btn-glyph' id='receive-order' title='Receive items'>
<span class='glyphicon glyphicon-check'></span>
</button>
<button type='button' class='btn btn-default btn-glyph' id='complete-order' title='Mark order as complete'>
<span class='glyphicon glyphicon-ok'></span>
</button>
{% endif %}
{% if order.status == OrderStatus.PENDING or order.status == OrderStatus.PLACED %}
<button type='button' class='btn btn-default btn-glyph' id='cancel-order' title='Cancel order'>
@ -171,12 +174,14 @@ InvenTree | {{ order }}
{% block js_ready %}
{% if order.status == OrderStatus.PENDING and order.lines.count > 0 %}
$("#place-order").click(function() {
launchModalForm("{% url 'purchase-order-issue' order.id %}",
{
reload: true,
});
});
{% endif %}
$("#edit-order").click(function() {
launchModalForm("{% url 'purchase-order-edit' order.id %}",
@ -228,6 +233,12 @@ $("#receive-order").click(function() {
});
});
$("#complete-order").click(function() {
launchModalForm("{% url 'purchase-order-complete' order.id %}", {
reload: true,
});
});
$("#export-order").click(function() {
location.href = "{% url 'purchase-order-export' order.id %}";
});

View File

@ -15,6 +15,7 @@ purchase_order_detail_urls = [
url(r'^edit/?', views.PurchaseOrderEdit.as_view(), name='purchase-order-edit'),
url(r'^issue/?', views.PurchaseOrderIssue.as_view(), name='purchase-order-issue'),
url(r'^receive/?', views.PurchaseOrderReceive.as_view(), name='purchase-order-receive'),
url(r'^complete/?', views.PurchaseOrderComplete.as_view(), name='purchase-order-complete'),
url(r'^export/?', views.PurchaseOrderExport.as_view(), name='purchase-order-export'),

View File

@ -184,6 +184,42 @@ class PurchaseOrderIssue(AjaxUpdateView):
return self.renderJsonResponse(request, form, data)
class PurchaseOrderComplete(AjaxUpdateView):
""" View for marking a PurchaseOrder as complete.
"""
form_class = order_forms.CompletePurchaseOrderForm
model = PurchaseOrder
ajax_template_name = "order/order_complete.html"
ajax_form_title = "Complete Order"
context_object_name = 'order'
def get_context_data(self):
ctx = {
'order': self.get_object(),
}
return ctx
def post(self, request, *args, **kwargs):
confirm = str2bool(request.POST.get('confirm', False))
if confirm:
po = self.get_object()
po.status = OrderStatus.COMPLETE
po.save()
data = {
'form_valid': confirm
}
form = self.get_form()
return self.renderJsonResponse(request, form, data)
class PurchaseOrderExport(AjaxView):
""" File download for a purchase order