mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add button to mark a purchase order as complete, even if not all line items are received
This commit is contained in:
parent
3f172cb065
commit
7f2804dff3
@ -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'))
|
||||
|
@ -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
|
||||
|
13
InvenTree/order/templates/order/order_complete.html
Normal file
13
InvenTree/order/templates/order/order_complete.html
Normal 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 %}
|
@ -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 %}";
|
||||
});
|
||||
|
@ -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'),
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user