{% extends "part/part_base.html" %}
{% load status_codes %}
{% load i18n %}
{% load inventree_extras %}

{% block details %}

{% include "part/tabs.html" with tab="allocation" %}

<h4>{% trans "Part Stock Allocations" %}</h4>

<table class='table table-striped table-condensed' id='build-table'>
<tr>
    <th>{% trans "Order" %}</th>
    <th>{% trans "Stock Item" %}</th>
    <th>{% trans "Quantity" %}</th>
</tr>
{% for allocation in part.build_order_allocations %}
<tr>
    <td><a href="{% url 'build-detail' allocation.build.id %}">{% trans "Build Order" %}: {{ allocation.build }}</a></td>
    <td><a href="{% url 'stock-item-detail' allocation.stock_item.id %}">{% trans "Stock Item" %}: {{ allocation.stock_item }}</a></td>
    <td>{% decimal allocation.quantity %}</td>
</tr>
{% endfor %}
{% for allocation in part.sales_order_allocations %}
<tr>
    <td><a href="{% url 'so-detail' allocation.line.order.id %}">{% trans "Sales Order" %}: {{ allocation.line.order }}</a></td>
    <td><a href="{% url 'stock-item-detail' allocation.item.id %}">{% trans "Stock Item" %}: {{ allocation.item }}</a></td>
    <td>{% decimal allocation.quantity %}</td>
</tr>
{% endfor %}
</table>

{% endblock %}

{% block js_ready %}

    $("#build-table").inventreeTable({
        columns: [
            {
                title: '{% trans "Order" %}',
                sortable: true,
            },
            {
                title: '{% trans "Stock Item" %}',
                sortable: true,
            },
            {
                title: '{% trans "Quantity" %}',
                sortable: true,
            }
        ]
    });

{% endblock %}
