Add order status field

- Display status field in PurchaseOrder list view
This commit is contained in:
Oliver Walters 2019-06-04 23:09:51 +10:00
parent da53de844a
commit 76a72be926
11 changed files with 112 additions and 12 deletions

View File

@ -0,0 +1,28 @@
from django.utils.translation import ugettext as _
class StatusCode:
@classmethod
def items(cls):
return cls.options.items()
class OrderStatus(StatusCode):
# Order status codes
PENDING = 10 # Order is pending (not yet placed)
PLACED = 20 # Order has been placed
COMPLETE = 30 # Order has been completed
CANCELLED = 40 # Order was cancelled
LOST = 50 # Order was lost
RETURNED = 60 # Order was returned
options = {
PENDING: _("Pending"),
PLACED: _("Placed"),
COMPLETE: _("Complete"),
CANCELLED: _("Cancelled"),
LOST: _("Lost"),
RETURNED: _("Returned"),
}

View File

@ -17,6 +17,8 @@ from django.urls import reverse
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
from InvenTree.status_codes import OrderStatus
def rename_company_image(instance, filename): def rename_company_image(instance, filename):
""" Function to rename a company image after upload """ Function to rename a company image after upload
@ -128,6 +130,26 @@ class Company(models.Model):
stock = apps.get_model('stock', 'StockItem') stock = apps.get_model('stock', 'StockItem')
return stock.objects.filter(supplier_part__supplier=self.id).count() return stock.objects.filter(supplier_part__supplier=self.id).count()
def outstanding_purchase_orders(self):
""" Return purchase orders which are 'outstanding' """
return self.purchase_orders.filter(status__in=[
OrderStatus.PENDING,
OrderStatus.PLACED
])
def complete_purchase_orders(self):
return self.purchase_orders.filter(status=OrderStatus.COMPLETE)
def failed_purchase_orders(self):
""" Return any purchase orders which were not successful """
return self.purchase_orders.filter(status__in=[
OrderStatus.CANCELLED,
OrderStatus.LOST,
OrderStatus.RETURNED
])
class Contact(models.Model): class Contact(models.Model):
""" A Contact represents a person who works at a particular company. """ A Contact represents a person who works at a particular company.

View File

@ -6,7 +6,7 @@
<div class='row'> <div class='row'>
<div class='col-sm-6'> <div class='col-sm-6'>
<h3>Company Details</h3> <h4>Company Details</h4>
</div> </div>
<div class='col-sm-6'> <div class='col-sm-6'>
<h3> <h3>

View File

@ -4,7 +4,7 @@
{% include 'company/tabs.html' with tab='parts' %} {% include 'company/tabs.html' with tab='parts' %}
<h3>Supplier Parts</h3> <h4>Supplier Parts</h4>
<div id='button-toolbar'> <div id='button-toolbar'>
<button class="btn btn-success" id='part-create'>New Supplier Part</button> <button class="btn btn-success" id='part-create'>New Supplier Part</button>

View File

@ -4,4 +4,17 @@
{% include 'company/tabs.html' with tab='po' %} {% include 'company/tabs.html' with tab='po' %}
<h4>Purchase Orders</h4>
<table class='table table-striped table-condensed' id='po-table'>
<tr>
<th>Reference</th>
<th>Description</th>
<th>Status</th>
</tr>
{% include "company/po_list.html" with orders=company.outstanding_purchase_orders %}
{% include "company/po_list.html" with orders=company.complete_purchase_orders %}
{% include "company/po_list.html" with orders=company.failed_purchase_orders %}
</table>
{% endblock %} {% endblock %}

View File

@ -5,7 +5,7 @@
{% include "company/tabs.html" with tab='stock' %} {% include "company/tabs.html" with tab='stock' %}
<h3>Supplier Stock</h3> <h4>Supplier Stock</h4>
{% include "stock_table.html" %} {% include "stock_table.html" %}

View File

@ -0,0 +1,7 @@
{% for order in orders %}
<tr>
<td>{{ order }}</td>
<td>{{ order.description }}</td>
<td>{% include "order/order_status.html" with order=order %}</td>
</tr>
{% endfor %}

View File

@ -12,6 +12,7 @@ class PurchaseOrderAdmin(admin.ModelAdmin):
list_display = ( list_display = (
'reference', 'reference',
'supplier', 'supplier',
'status',
'description', 'description',
'creation_date' 'creation_date'
) )

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2019-06-04 12:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('order', '0003_auto_20190604_2226'),
]
operations = [
migrations.AddField(
model_name='purchaseorder',
name='status',
field=models.PositiveIntegerField(choices=[(10, 'Pending'), (20, 'Placed'), (30, 'Complete'), (40, 'Cancelled'), (50, 'Lost'), (60, 'Returned')], default=10, help_text='Order status'),
),
]

View File

@ -8,6 +8,8 @@ from part.models import Part
from company.models import Company from company.models import Company
from stock.models import StockItem from stock.models import StockItem
from InvenTree.status_codes import OrderStatus
class Order(models.Model): class Order(models.Model):
""" Abstract model for an order. """ Abstract model for an order.
@ -26,13 +28,17 @@ class Order(models.Model):
""" """
# Order status codes ORDER_PREFIX = ""
PENDING = 10 # Order is pending (not yet placed)
PLACED = 20 # Order has been placed def __str__(self):
RECEIVED = 30 # Order has been received el = []
CANCELLED = 40 # Order was cancelled
LOST = 50 # Order was lost if self.ORDER_PREFIX:
RETURNED = 60 # Order was returned el.append(self.ORDER_PREFIX)
el.append(self.reference)
return " ".join(el)
class Meta: class Meta:
abstract = True abstract = True
@ -45,6 +51,9 @@ class Order(models.Model):
creation_date = models.DateField(auto_now=True, editable=False) creation_date = models.DateField(auto_now=True, editable=False)
status = models.PositiveIntegerField(default=OrderStatus.PENDING, choices=OrderStatus.items(),
help_text='Order status')
created_by = models.ForeignKey(User, created_by = models.ForeignKey(User,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
blank=True, null=True, blank=True, null=True,
@ -64,6 +73,8 @@ class PurchaseOrder(Order):
""" """
ORDER_PREFIX = "PO"
supplier = models.ForeignKey(Company, on_delete=models.CASCADE, supplier = models.ForeignKey(Company, on_delete=models.CASCADE,
limit_choices_to={ limit_choices_to={
'is_supplier': True, 'is_supplier': True,

View File

@ -2,9 +2,9 @@
<span class='label label-info'> <span class='label label-info'>
{% elif order.status == order.PLACED %} {% elif order.status == order.PLACED %}
<span class='label label-primary'> <span class='label label-primary'>
{% elif order.status == order.RECEIVED %} {% elif order.status == order.COMPLETE %}
<span class='label label-success'> <span class='label label-success'>
{% elif order.status == order.CANCELLED %} {% elif order.status == order.CANCELLED or order.status == order.RETURNED %}
<span class='label label-warning'> <span class='label label-warning'>
{% else %} {% else %}
<span class='label label-danger'> <span class='label label-danger'>