diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py
index bdd77e15bc..259b64f087 100644
--- a/InvenTree/order/forms.py
+++ b/InvenTree/order/forms.py
@@ -29,7 +29,6 @@ class EditPurchaseOrderForm(HelperForm):
'supplier',
'description',
'URL',
- 'status',
'notes'
]
diff --git a/InvenTree/order/migrations/0009_auto_20190606_2133.py b/InvenTree/order/migrations/0009_auto_20190606_2133.py
new file mode 100644
index 0000000000..0cadfe87fe
--- /dev/null
+++ b/InvenTree/order/migrations/0009_auto_20190606_2133.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.2 on 2019-06-06 11:33
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('order', '0008_auto_20190605_2140'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='purchaseorder',
+ name='description',
+ field=models.CharField(help_text='Order description', max_length=250),
+ ),
+ ]
diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py
index dc72522e67..a239458d33 100644
--- a/InvenTree/order/models.py
+++ b/InvenTree/order/models.py
@@ -43,7 +43,7 @@ class Order(models.Model):
reference = models.CharField(unique=True, max_length=64, blank=False, help_text=_('Order reference'))
- description = models.CharField(max_length=250, blank=True, help_text=_('Order description'))
+ description = models.CharField(max_length=250, help_text=_('Order description'))
URL = models.URLField(blank=True, help_text=_('Link to external page'))
diff --git a/InvenTree/order/templates/order/purchase_orders.html b/InvenTree/order/templates/order/purchase_orders.html
index c599bfcd20..0c7ac717cd 100644
--- a/InvenTree/order/templates/order/purchase_orders.html
+++ b/InvenTree/order/templates/order/purchase_orders.html
@@ -8,8 +8,30 @@ InvenTree | Purchase Orders
{% block content %}
-
Purchase Orders
+
+
+
Purchase Orders
+
+
+
+
+
+
+
{% include "order/po_table.html" %}
+{% endblock %}
+
+{% block js_ready %}
+{{ block.super }}
+
+$("#po-create").click(function() {
+ launchModalForm("{% url 'purchase-order-create' %}",
+ {
+ reload: true,
+ }
+ );
+});
+
{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py
index 16ca858e39..20379edb76 100644
--- a/InvenTree/order/urls.py
+++ b/InvenTree/order/urls.py
@@ -24,6 +24,8 @@ po_line_urls = [
purchase_order_urls = [
+ url(r'^new/', views.PurchaseOrderCreate.as_view(), name='purchase-order-create'),
+
# Display detail view for a single purchase order
url(r'^(?P\d+)/', include(purchase_order_detail_urls)),
diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py
index 6bacdda93e..56b5077d22 100644
--- a/InvenTree/order/views.py
+++ b/InvenTree/order/views.py
@@ -24,6 +24,14 @@ class PurchaseOrderIndex(ListView):
template_name = 'order/purchase_orders.html'
context_object_name = 'orders'
+ def get_queryset(self):
+ """ Retrieve the list of purchase orders,
+ ensure that the most recent ones are returned first. """
+
+ queryset = PurchaseOrder.objects.all().order_by('-creation_date')
+
+ return queryset
+
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
@@ -47,6 +55,21 @@ class PurchaseOrderDetail(DetailView):
return ctx
+class PurchaseOrderCreate(AjaxCreateView):
+ """ View for creating a new PurchaseOrder object using a modal form """
+
+ model = PurchaseOrder
+ ajax_form_title = "Create Purchase Order"
+ form_class = order_forms.EditPurchaseOrderForm
+
+ def get_initial(self):
+ initials = super().get_initial().copy()
+
+ initials['status'] = OrderStatus.PENDING
+
+ return initials
+
+
class PurchaseOrderEdit(AjaxUpdateView):
""" View for editing a PurchaseOrder using a modal form """
@@ -60,6 +83,7 @@ class PurchaseOrderEdit(AjaxUpdateView):
order = self.get_object()
+ # Prevent user from editing supplier if there are already lines in the order
if order.lines.count() > 0:
form.fields['supplier'].widget = HiddenInput()