Form / view for creating a new purchase order

This commit is contained in:
Oliver Walters 2019-06-06 21:39:04 +10:00
parent c1f3bddf45
commit 7b139a7f05
6 changed files with 68 additions and 3 deletions

View File

@ -29,7 +29,6 @@ class EditPurchaseOrderForm(HelperForm):
'supplier',
'description',
'URL',
'status',
'notes'
]

View File

@ -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),
),
]

View File

@ -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'))

View File

@ -8,8 +8,30 @@ InvenTree | Purchase Orders
{% block content %}
<h4>Purchase Orders</h4>
<div class='row'>
<div class='col-sm-6'>
<h3>Purchase Orders</h3>
</div>
<div class='col-sm-6'>
<div class='btn-group' style='float: right;'>
<button class='btn btn-primary' type='button' id='po-create' title='Create new purchase order'>New Purchase Order</button>
</div>
</div>
</div>
{% include "order/po_table.html" %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
$("#po-create").click(function() {
launchModalForm("{% url 'purchase-order-create' %}",
{
reload: true,
}
);
});
{% endblock %}

View File

@ -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<pk>\d+)/', include(purchase_order_detail_urls)),

View File

@ -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()