mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Form / view for creating a new purchase order
This commit is contained in:
parent
c1f3bddf45
commit
7b139a7f05
@ -29,7 +29,6 @@ class EditPurchaseOrderForm(HelperForm):
|
|||||||
'supplier',
|
'supplier',
|
||||||
'description',
|
'description',
|
||||||
'URL',
|
'URL',
|
||||||
'status',
|
|
||||||
'notes'
|
'notes'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
18
InvenTree/order/migrations/0009_auto_20190606_2133.py
Normal file
18
InvenTree/order/migrations/0009_auto_20190606_2133.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
@ -43,7 +43,7 @@ class Order(models.Model):
|
|||||||
|
|
||||||
reference = models.CharField(unique=True, max_length=64, blank=False, help_text=_('Order reference'))
|
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'))
|
URL = models.URLField(blank=True, help_text=_('Link to external page'))
|
||||||
|
|
||||||
|
@ -8,8 +8,30 @@ InvenTree | Purchase Orders
|
|||||||
|
|
||||||
{% block content %}
|
{% 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" %}
|
{% include "order/po_table.html" %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js_ready %}
|
||||||
|
{{ block.super }}
|
||||||
|
|
||||||
|
$("#po-create").click(function() {
|
||||||
|
launchModalForm("{% url 'purchase-order-create' %}",
|
||||||
|
{
|
||||||
|
reload: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -24,6 +24,8 @@ po_line_urls = [
|
|||||||
|
|
||||||
purchase_order_urls = [
|
purchase_order_urls = [
|
||||||
|
|
||||||
|
url(r'^new/', views.PurchaseOrderCreate.as_view(), name='purchase-order-create'),
|
||||||
|
|
||||||
# Display detail view for a single purchase order
|
# Display detail view for a single purchase order
|
||||||
url(r'^(?P<pk>\d+)/', include(purchase_order_detail_urls)),
|
url(r'^(?P<pk>\d+)/', include(purchase_order_detail_urls)),
|
||||||
|
|
||||||
|
@ -24,6 +24,14 @@ class PurchaseOrderIndex(ListView):
|
|||||||
template_name = 'order/purchase_orders.html'
|
template_name = 'order/purchase_orders.html'
|
||||||
context_object_name = 'orders'
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
@ -47,6 +55,21 @@ class PurchaseOrderDetail(DetailView):
|
|||||||
return ctx
|
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):
|
class PurchaseOrderEdit(AjaxUpdateView):
|
||||||
""" View for editing a PurchaseOrder using a modal form """
|
""" View for editing a PurchaseOrder using a modal form """
|
||||||
|
|
||||||
@ -60,6 +83,7 @@ class PurchaseOrderEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
order = self.get_object()
|
order = self.get_object()
|
||||||
|
|
||||||
|
# Prevent user from editing supplier if there are already lines in the order
|
||||||
if order.lines.count() > 0:
|
if order.lines.count() > 0:
|
||||||
form.fields['supplier'].widget = HiddenInput()
|
form.fields['supplier'].widget = HiddenInput()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user