2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-03 04:00:57 +00:00

Use the client-side PO table in more places

This commit is contained in:
Oliver Walters
2019-12-09 21:55:00 +11:00
parent a257f94ac0
commit 71c1faf9ff
5 changed files with 79 additions and 59 deletions
InvenTree
InvenTree
static
script
inventree
company
order
part
templates

@ -100,6 +100,63 @@ function removePurchaseOrderLineItem(e) {
}); });
} }
function loadPurchaseOrderTable(table, options) {
/* Create a purchase-order table */
table.inventreeTable({
url: options.url,
formatNoMatches: function() { return "No purchase orders found"; },
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
sortable: true,
field: 'supplier',
title: 'Supplier',
formatter: function(value, row, index, field) {
return imageHoverIcon(row.supplier__image) + renderLink(row.supplier__name, '/company/' + value + '/purchase-orders/');
}
},
{
sortable: true,
field: 'reference',
title: 'Reference',
formatter: function(value, row, index, field) {
return renderLink(value, "/order/purchase-order/" + row.pk + "/");
}
},
{
sortable: true,
field: 'creation_date',
title: 'Date',
},
{
sortable: true,
field: 'description',
title: 'Description',
},
{
sortable: true,
field: 'status',
title: 'Status',
formatter: function(value, row, index, field) {
return orderStatusLabel(row.status, row.status_text);
}
},
{
sortable: true,
field: 'lines',
title: 'Items'
},
],
});
}
function orderStatusLabel(code, label) { function orderStatusLabel(code, label) {
/* Render a purchase-order status label. */ /* Render a purchase-order status label. */

@ -13,17 +13,19 @@
</div> </div>
</div> </div>
{% include "order/po_table.html" with orders=company.outstanding_purchase_orders.all toolbar='#button-bar' %} <table class='table table-striped table-condensed po-table' id='purchase-order-table' data-toolbar='#button-bar'>
</table>
{% if company.closed_purchase_orders.count > 0 %}
{% include "order/po_table_collapse.html" with title="Closed Orders" orders=company.closed_purchase_orders.all %}
{% endif %}
{% endblock %} {% endblock %}
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
loadPurchaseOrderTable($("#purchase-order-table"), {
url: "{% url 'api-po-list' %}?supplier={{ company.id }}",
});
function newOrder() { function newOrder() {
launchModalForm("{% url 'purchase-order-create' %}", launchModalForm("{% url 'purchase-order-create' %}",
{ {

@ -17,6 +17,8 @@ from InvenTree.status_codes import OrderStatus
import os import os
from part.models import Part
from .models import PurchaseOrder, PurchaseOrderLineItem from .models import PurchaseOrder, PurchaseOrderLineItem
from .serializers import POSerializer, POLineItemSerializer from .serializers import POSerializer, POLineItemSerializer
@ -52,6 +54,14 @@ class POList(generics.ListCreateAPIView):
except ValueError: except ValueError:
pass pass
# Attempt to filter by part
if 'part' in request.GET:
try:
part = Part.objects.get(pk=request.GET['part'])
queryset = queryset.filter(id__in=[p.id for p in part.purchase_orders()])
except (Part.DoesNotExist, ValueError):
pass
data = queryset.values( data = queryset.values(
'pk', 'pk',
'supplier', 'supplier',

@ -37,55 +37,8 @@ $("#po-create").click(function() {
$("#po-table").inventreeTable({ $("#po-table").inventreeTable({
}); });
$("#purchase-order-table").inventreeTable({ loadPurchaseOrderTable($("#purchase-order-table"), {
url: "{% url 'api-po-list' %}", url: "{% url 'api-po-list' %}",
formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; },
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
sortable: true,
field: 'supplier',
title: 'Supplier',
formatter: function(value, row, index, field) {
return imageHoverIcon(row.supplier__image) + renderLink(row.supplier__name, '/company/' + value + '/');
}
},
{
sortable: true,
field: 'reference',
title: 'Reference',
formatter: function(value, row, index, field) {
return renderLink(value, "/order/purchase-order/" + row.pk + "/");
}
},
{
sortable: true,
field: 'creation_date',
title: 'Date',
},
{
sortable: true,
field: 'description',
title: 'Description',
},
{
sortable: true,
field: 'status_text',
title: 'Status',
formatter: function(value, row, index, field) {
return orderStatusLabel(row.status, row.status_text);
}
},
{
sortable: true,
field: 'lines',
title: 'Items'
},
],
}); });
{% endblock %} {% endblock %}

@ -14,19 +14,17 @@
</div> </div>
</div> </div>
{% include "order/po_table.html" with orders=part.open_purchase_orders toolbar='#button-bar' %} <table class='table table-striped table-condensed po-table' id='purchase-order-table' data-toolbar='#button-bar'>
</table>
{% if part.closed_purchase_orders|length > 0 %}
<h4>Closed Orders</h4>
{% include "order/po_table.html" with orders=part.closed_purchase_orders %}
{% endif %}
{% endblock %} {% endblock %}
{% block js_ready %} {% block js_ready %}
{{ block.super }} {{ block.super }}
$("#po-table").inventreeTable({ loadPurchaseOrderTable($("#purchase-order-table"), {
url: "{% url 'api-po-list' %}?part={{ part.id }}",
}); });
$("#part-order2").click(function() { $("#part-order2").click(function() {