Add form / view to edit purchase order details

- Cannot edit the COMPANY if there are line items already
This commit is contained in:
Oliver Walters 2019-06-05 22:24:18 +10:00
parent bcc08f982b
commit 96eb4086cf
7 changed files with 82 additions and 11 deletions

View File

@ -7,10 +7,35 @@ from __future__ import unicode_literals
from InvenTree.forms import HelperForm from InvenTree.forms import HelperForm
from .models import PurchaseOrderLineItem from .models import PurchaseOrder, PurchaseOrderLineItem
class IssuePurchaseOrderForm(HelperForm):
class Meta:
model = PurchaseOrder
fields = [
'status',
]
class EditPurchaseOrderForm(HelperForm):
""" Form for editing a PurchaseOrder object """
class Meta:
model = PurchaseOrder
fields = [
'reference',
'supplier',
'description',
'URL',
'status',
'notes'
]
class EditPurchaseOrderLineItemForm(HelperForm): class EditPurchaseOrderLineItemForm(HelperForm):
""" Form for editing a PurchaseOrderLineItem object """
class Meta: class Meta:
model = PurchaseOrderLineItem model = PurchaseOrderLineItem

View File

@ -0,0 +1 @@
{% extends "modal_form.html" %}

View File

@ -1,13 +1,13 @@
{% if order.status == OrderStatus.PENDING %} {% if order.status == OrderStatus.PENDING %}
<span class='label label-info'> <span class='label label-large label-info'>
{% elif order.status == OrderStatus.PLACED %} {% elif order.status == OrderStatus.PLACED %}
<span class='label label-primary'> <span class='label label-large label-primary'>
{% elif order.status == OrderStatus.COMPLETE %} {% elif order.status == OrderStatus.COMPLETE %}
<span class='label label-success'> <span class='label label-large label-success'>
{% elif order.status == OrderStatus.CANCELLED or order.status == OrderStatus.RETURNED %} {% elif order.status == OrderStatus.CANCELLED or order.status == OrderStatus.RETURNED %}
<span class='label label-warning'> <span class='label label-large label-warning'>
{% else %} {% else %}
<span class='label label-danger'> <span class='label label-large label-danger'>
{% endif %} {% endif %}
{{ order.get_status_display }} {{ order.get_status_display }}
</span> </span>

View File

@ -55,6 +55,13 @@ InvenTree | {{ order }}
<hr> <hr>
<div class='btn-group' style='float: right;'>
<button type='button' class='btn btn-primary' id='edit-order'>Edit Order</button>
{% if order.status == OrderStatus.PENDING %}
<button type='button' class='btn btn-primary' id='issue-order'>Issue Order</button>
{% endif %}
</div>
<h4>Order Items</h4> <h4>Order Items</h4>
<button type='button' class='btn btn-default' id='new-po-line'>Add Line Item</button> <button type='button' class='btn btn-default' id='new-po-line'>Add Line Item</button>
@ -96,6 +103,14 @@ InvenTree | {{ order }}
{% block js_ready %} {% block js_ready %}
$("#edit-order").click(function() {
launchModalForm("{% url 'purchase-order-edit' order.id %}",
{
reload: true,
}
);
});
$('#new-po-line').click(function() { $('#new-po-line').click(function() {
launchModalForm("{% url 'po-line-item-create' %}", launchModalForm("{% url 'po-line-item-create' %}",
{ {

View File

@ -11,6 +11,9 @@ from . import views
purchase_order_detail_urls = [ 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'^.*$', views.PurchaseOrderDetail.as_view(), name='purchase-order-detail'), url(r'^.*$', views.PurchaseOrderDetail.as_view(), name='purchase-order-detail'),
] ]

View File

@ -9,7 +9,8 @@ from django.views.generic import DetailView, ListView
from django.forms import HiddenInput from django.forms import HiddenInput
from .models import PurchaseOrder, PurchaseOrderLineItem from .models import PurchaseOrder, PurchaseOrderLineItem
from .forms import EditPurchaseOrderLineItemForm
from . import forms as order_forms
from InvenTree.views import AjaxCreateView, AjaxUpdateView from InvenTree.views import AjaxCreateView, AjaxUpdateView
@ -46,14 +47,41 @@ class PurchaseOrderDetail(DetailView):
return ctx return ctx
class PurchaseOrderEdit(AjaxUpdateView):
""" View for editing a PurchaseOrder using a modal form """
model = PurchaseOrder
ajax_form_title = 'Edit Purchase Order'
form_class = order_forms.EditPurchaseOrderForm
def get_form(self):
form = super(AjaxUpdateView, self).get_form()
order = self.get_object()
if order.lines.count() > 0:
form.fields['supplier'].widget = HiddenInput()
return form
class PurchaseOrderIssue(AjaxUpdateView):
""" View for changing a purchase order from 'PENDING' to 'ISSUED' """
model = PurchaseOrder
ajax_form_title = 'Issue Order'
ajax_template_name = "order/order_issue.html"
form_class = order_forms.IssuePurchaseOrderForm
class POLineItemCreate(AjaxCreateView): class POLineItemCreate(AjaxCreateView):
""" AJAX view for creating a new PurchaseOrderLineItem object """ AJAX view for creating a new PurchaseOrderLineItem object
""" """
model = PurchaseOrderLineItem model = PurchaseOrderLineItem
context_object_name = 'line' context_object_name = 'line'
form_class = EditPurchaseOrderLineItemForm form_class = order_forms.EditPurchaseOrderLineItemForm
ajax_template_name = 'modal_form.html'
ajax_form_title = 'Add Line Item' ajax_form_title = 'Add Line Item'
def get_form(self): def get_form(self):
@ -113,6 +141,6 @@ class POLineItemCreate(AjaxCreateView):
class POLineItemEdit(AjaxUpdateView): class POLineItemEdit(AjaxUpdateView):
model = PurchaseOrderLineItem model = PurchaseOrderLineItem
form_class = EditPurchaseOrderLineItemForm form_class = order_forms.EditPurchaseOrderLineItemForm
ajax_template_name = 'modal_form.html' ajax_template_name = 'modal_form.html'
ajax_form_action = 'Edit Line Item' ajax_form_action = 'Edit Line Item'

View File

@ -38,7 +38,6 @@
/* Extra label styles */ /* Extra label styles */
.label-large { .label-large {
padding: 5px;
margin: 3px; margin: 3px;
font-size: 100%; font-size: 100%;
} }