From ec669dd67085d0fb327c805932717bd5c5d6657e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 10 Jun 2019 22:14:23 +1000 Subject: [PATCH] Ability to 'issue' a purchase order --- InvenTree/order/forms.py | 6 ++++- InvenTree/order/models.py | 16 ++++++++++++ .../order/templates/order/order_issue.html | 8 +++++- .../order/purchase_order_detail.html | 9 ++++++- InvenTree/order/views.py | 25 +++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 259b64f087..08e9a6f740 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -5,6 +5,8 @@ Django Forms for interacting with Order objects # -*- coding: utf-8 -*- from __future__ import unicode_literals +from django import forms + from InvenTree.forms import HelperForm from .models import PurchaseOrder, PurchaseOrderLineItem @@ -12,10 +14,12 @@ from .models import PurchaseOrder, PurchaseOrderLineItem class IssuePurchaseOrderForm(HelperForm): + confirm = forms.BooleanField(required=False, help_text='Place order') + class Meta: model = PurchaseOrder fields = [ - 'status', + 'confirm', ] diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index ed102e928a..e71e50f743 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -1,9 +1,17 @@ +""" +Order model definitions +""" + +# -*- coding: utf-8 -*- + from django.db import models from django.core.validators import MinValueValidator from django.contrib.auth.models import User from django.utils.translation import ugettext as _ +from datetime import datetime + from company.models import Company, SupplierPart from InvenTree.status_codes import OrderStatus @@ -62,6 +70,14 @@ class Order(models.Model): notes = models.TextField(blank=True, help_text=_('Order notes')) + def place_order(self): + """ Marks the order as PLACED. Order must be currently PENDING. """ + + if self.status == OrderStatus.PENDING: + self.status = OrderStatus.PLACED + self.issue_date = datetime.now().date() + self.save() + class PurchaseOrder(Order): """ A PurchaseOrder represents goods shipped inwards from an external supplier. diff --git a/InvenTree/order/templates/order/order_issue.html b/InvenTree/order/templates/order/order_issue.html index c7de8c74b2..ad80fc5a0d 100644 --- a/InvenTree/order/templates/order/order_issue.html +++ b/InvenTree/order/templates/order/order_issue.html @@ -1 +1,7 @@ -{% extends "modal_form.html" %} \ No newline at end of file +{% extends "modal_form.html" %} + +{% block pre_form_content %} + +After placing this purchase order, line items will no longer be editable. + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index dbabb2f940..5fb9a76ac9 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -58,7 +58,7 @@ InvenTree | {{ order }}
{% if order.status == OrderStatus.PENDING %} - + {% endif %}
@@ -103,6 +103,13 @@ InvenTree | {{ order }} {% block js_ready %} +$("#place-order").click(function() { + launchModalForm("{% url 'purchase-order-issue' order.id %}", + { + reload: true, + }); +}); + $("#edit-order").click(function() { launchModalForm("{% url 'purchase-order-edit' order.id %}", { diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index c4bcc05f69..5e85e0ae82 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -15,6 +15,7 @@ from company.models import SupplierPart from . import forms as order_forms from InvenTree.views import AjaxCreateView, AjaxUpdateView +from InvenTree.helpers import str2bool from InvenTree.status_codes import OrderStatus @@ -100,6 +101,30 @@ class PurchaseOrderIssue(AjaxUpdateView): ajax_template_name = "order/order_issue.html" form_class = order_forms.IssuePurchaseOrderForm + def post(self, request, *args, **kwargs): + """ Mark the purchase order as 'PLACED' """ + + order = self.get_object() + form = self.get_form() + + confirm = str2bool(request.POST.get('confirm', False)) + + valid = False + + if not confirm: + form.errors['confirm'] = [_('Confirm order placement')] + else: + valid = True + + data = { + 'form_valid': valid, + } + + if valid: + order.issue_order() + + return self.renderJsonResponse(request, form, data) + class POLineItemCreate(AjaxCreateView): """ AJAX view for creating a new PurchaseOrderLineItem object