mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Ability to 'issue' a purchase order
This commit is contained in:
parent
9efdd836f4
commit
ec669dd670
@ -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',
|
||||
]
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
@ -1 +1,7 @@
|
||||
{% extends "modal_form.html" %}
|
||||
{% extends "modal_form.html" %}
|
||||
|
||||
{% block pre_form_content %}
|
||||
|
||||
After placing this purchase order, line items will no longer be editable.
|
||||
|
||||
{% endblock %}
|
@ -58,7 +58,7 @@ InvenTree | {{ order }}
|
||||
<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>
|
||||
<button type='button' class='btn btn-primary' id='place-order'>Place Order</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@ -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 %}",
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user