{% extends "company/supplier_part_base.html" %}
{% load static %}
{% load i18n %}

{% block menubar %}
{% include "company/supplier_part_navbar.html" with tab='stock' %}
{% endblock %}

{% block heading %}
{% trans "Supplier Part Stock" %}
{% endblock %}

{% block details %}
{% include "stock_table.html" %}

{% endblock %}

{% block js_ready %}
{{ block.super }}

    loadStockTable($("#stock-table"), {
        params: {
            supplier_part: {{ part.id }},
            location_detail: true,
            part_detail: false,
        },
        groupByField: 'location',
        buttons: ['#stock-options'],
        url: "{% url 'api-stock-list' %}",
    });

    $("#stock-export").click(function() {
        launchModalForm("{% url 'stock-export-options' %}", {
            submit_text: '{% trans "Export" %}',
            success: function(response) {
                var url = "{% url 'stock-export' %}";

                url += "?format=" + response.format;
                url += "&cascade=" + response.cascade;
                url += "&supplier_part={{ part.id }}";

                location.href = url;
            },
        });
    });

    $("#item-create").click(function() {
        createNewStockItem({
            data: {
                part: {{ part.part.id }},
                supplier_part: {{ part.id }},
            },
            reload: true,
        });
    });


{% endblock %}