<commit_before>{% extends "order/order_base.html" %}

{% load inventree_extras %}
{% load status_codes %}
{% load i18n %}
{% load static %}

{% block menubar %}
{% include 'order/po_navbar.html' with tab='details' %}

{% endblock %}

{% block heading %}
{% trans "Purchase Order Items" %}
{% endblock %}


{% block details %}


<div id='order-toolbar-buttons' class='btn-group' style='float: right;'>
    {% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
    <button type='button' class='btn btn-primary' id='new-po-line'>
        <span class='fas fa-plus-circle'></span> {% trans "Add Line Item" %}
    </button>
    {% endif %}
</div>


<table class='table table-striped table-condensed' id='po-table' data-toolbar='#order-toolbar-buttons'>
</table>

{% endblock %}

{% block js_ready %}

{{ block.super }}

{% if order.status == PurchaseOrderStatus.PENDING %}
$('#new-po-line').click(function() {
    launchModalForm("{% url 'po-line-item-create' %}",
        {
            reload: true,
            data: {
                order: {{ order.id }},
            },
            secondary: [
                {
                    field: 'part',
                    label: '{% trans "New Supplier Part" %}',
                    title: '{% trans "Create new supplier part" %}',
                    url: "{% url 'supplier-part-create' %}",
                    data: {
                        supplier: {{ order.supplier.id }},
                    },
                },
            ],
        }
    );
});
{% endif %}

function reloadTable() {
    $("#po-table").bootstrapTable("refresh");
}

function setupCallbacks() {
    // Setup callbacks for the line buttons

    var table = $("#po-table");

    {% if order.status == PurchaseOrderStatus.PENDING %}
    table.find(".button-line-edit").click(function() {
        var pk = $(this).attr('pk');

        constructForm(`/api/order/po-line/${pk}/`, {
            fields: {
                part: {},
                quantity: {},
                reference: {},
                purchase_price: {},
                purchase_price_currency: {},
                destination: {},
                notes: {},
            },
            title: '{% trans "Edit Line Item" %}',
            onSuccess: reloadTable,
        });
    });

    table.find(".button-line-delete").click(function() {
        var pk = $(this).attr('pk');

        constructForm(`/api/order/po-line/${pk}/`, {
            method: 'DELETE',
            title: '{% trans "Delete Line Item" %}',
            onSuccess: reloadTable,
        });
    });
    {% endif %}<commit_msg>Fix form filters<commit_after>{% extends "order/order_base.html" %}

{% load inventree_extras %}
{% load status_codes %}
{% load i18n %}
{% load static %}

{% block menubar %}
{% include 'order/po_navbar.html' with tab='details' %}

{% endblock %}

{% block heading %}
{% trans "Purchase Order Items" %}
{% endblock %}


{% block details %}


<div id='order-toolbar-buttons' class='btn-group' style='float: right;'>
    {% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
    <button type='button' class='btn btn-primary' id='new-po-line'>
        <span class='fas fa-plus-circle'></span> {% trans "Add Line Item" %}
    </button>
    {% endif %}
</div>


<table class='table table-striped table-condensed' id='po-table' data-toolbar='#order-toolbar-buttons'>
</table>

{% endblock %}

{% block js_ready %}

{{ block.super }}

{% if order.status == PurchaseOrderStatus.PENDING %}
$('#new-po-line').click(function() {
    launchModalForm("{% url 'po-line-item-create' %}",
        {
            reload: true,
            data: {
                order: {{ order.id }},
            },
            secondary: [
                {
                    field: 'part',
                    label: '{% trans "New Supplier Part" %}',
                    title: '{% trans "Create new supplier part" %}',
                    url: "{% url 'supplier-part-create' %}",
                    data: {
                        supplier: {{ order.supplier.id }},
                    },
                },
            ],
        }
    );
});
{% endif %}

function reloadTable() {
    $("#po-table").bootstrapTable("refresh");
}

function setupCallbacks() {
    // Setup callbacks for the line buttons

    var table = $("#po-table");

    {% if order.status == PurchaseOrderStatus.PENDING %}
    table.find(".button-line-edit").click(function() {
        var pk = $(this).attr('pk');

        constructForm(`/api/order/po-line/${pk}/`, {
            fields: {
                part: {
                    filters: {
                        supplier_detail: true,
                        supplier: {{ order.supplier.pk }},
                    }
                },
                quantity: {},
                reference: {},
                purchase_price: {},
                purchase_price_currency: {},
                destination: {},
                notes: {},
            },
            title: '{% trans "Edit Line Item" %}',
            onSuccess: reloadTable,
        });
    });

    table.find(".button-line-delete").click(function() {
        var pk = $(this).attr('pk');

        constructForm(`/api/order/po-line/${pk}/`, {
            method: 'DELETE',
            title: '{% trans "Delete Line Item" %}',
            onSuccess: reloadTable,
        });
    });
    {% endif %}
{'fraction_non_alphanumeric': 0.1745152354570637, 'fraction_numerical': 0.0007386888273314866, 'mean_word_length': 1.7731694828469022, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7657451', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1514, 'n_words': 303}