diff --git a/InvenTree/company/templates/company/supplier_part_stock.html b/InvenTree/company/templates/company/supplier_part_stock.html index b14f702504..95c2559977 100644 --- a/InvenTree/company/templates/company/supplier_part_stock.html +++ b/InvenTree/company/templates/company/supplier_part_stock.html @@ -44,23 +44,13 @@ }); $("#item-create").click(function() { - launchModalForm("{% url 'stock-item-create' %}", { - reload: true, + createNewStockItem({ data: { part: {{ part.part.id }}, supplier_part: {{ part.id }}, }, - secondary: [ - { - field: 'location', - label: '{% trans "New Location" %}', - title: '{% trans "Create New Location" %}', - url: "{% url 'stock-location-create' %}", - } - ] + reload: true, }); - - return false; }); diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 3030363476..e968a72102 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -25,14 +25,12 @@ {{ block.super }} $('#add-stock-item').click(function () { - launchModalForm( - "{% url 'stock-item-create' %}", - { - reload: true, - data: { - part: {{ part.id }} - } - }); + createNewStockItem({ + reload: true, + data: { + part: {{ part.id }}, + } + }); }); loadStockTable($("#stock-table"), { @@ -64,37 +62,12 @@ }); $('#item-create').click(function () { - launchModalForm("{% url 'stock-item-create' %}", { + createNewStockItem({ reload: true, data: { - part: {{ part.id }} - }, - secondary: [ - { - field: 'part', - label: '{% trans "New Part" %}', - title: '{% trans "Create New Part" %}', - url: "{% url 'part-create' %}", - }, - { - field: 'supplier_part', - label: '{% trans "New Supplier Part" %}', - title: '{% trans "Create new Supplier Part" %}', - url: "{% url 'supplier-part-create' %}", - data: { - part: {{ part.id }} - }, - }, - { - field: 'location', - label: '{% trans "New Location" %}', - title: '{% trans "Create New Location" %}', - url: "{% url 'stock-location-create' %}", - } - ] + part: {{ part.id }}, + } }); - - return false; }); {% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index bcc2087b25..f2b80596fd 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -320,15 +320,12 @@ $("#print-label").click(function() { }); $("#stock-duplicate").click(function() { - launchModalForm( - "{% url 'stock-item-create' %}", - { - follow: true, - data: { - copy: {{ item.id }}, - }, + createNewStockItem({ + follow: true, + data: { + copy: {{ item.id }}, } - ); + }); }); $("#stock-edit").click(function () { diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 9ef74f238b..75e2053076 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -204,59 +204,13 @@ {% endif %} $('#item-create').click(function () { - launchModalForm("{% url 'stock-item-create' %}", - { - follow: true, - data: { - {% if location %} - location: {{ location.id }} - {% endif %} - }, - callback: [ - { - field: 'part', - action: function(value) { - - reloadFieldOptions( - 'supplier_part', - { - url: "{% url 'api-supplier-part-list' %}", - params: { - part: value, - pretty: true, - }, - text: function(item) { - return item.pretty_name; - } - } - ) - } - }, - ], - secondary: [ - { - field: 'part', - label: 'New Part', - title: 'Create New Part', - url: "{% url 'part-create' %}", - }, - { - field: 'supplier_part', - label: 'New Supplier Part', - title: 'Create new Supplier Part', - url: "{% url 'supplier-part-create' %}" - }, - { - field: 'location', - label: 'New Location', - title: 'Create New Location', - url: "{% url 'stock-location-create' %}", - } - ] - }); - - - return false; + createNewStockItem({ + data: { + {% if location %} + location: {{ location.id }} + {% endif %} + } + }); }); loadStockTable($("#stock-table"), { diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index 11cf6a94e3..9393b29739 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -734,4 +734,60 @@ function loadStockTrackingTable(table, options) { reload: true, }); }); +} + + +function createNewStockItem(options) { + /* Launch a modal form to create a new stock item. + * + * This is really just a helper function which calls launchModalForm, + * but it does get called a lot, so here we are ... + */ + + // Add in some funky options + + options.callback = [ + { + field: 'part', + action: function(value) { + + reloadFieldOptions( + 'supplier_part', + { + url: "{% url 'api-supplier-part-list' %}", + params: { + part: value, + pretty: true, + }, + text: function(item) { + return item.pretty_name; + } + } + ); + } + }, + ]; + + options.secondary = [ + { + field: 'part', + label: '{% trans "New Part" %}', + title: '{% trans "Create New Part" %}', + url: "{% url 'part-create' %}", + }, + { + field: 'supplier_part', + label: '{% trans "New Supplier Part" %}', + title: '{% trans "Create new Supplier Part" %}', + url: "{% url 'supplier-part-create' %}" + }, + { + field: 'location', + label: '{% trans "New Location" %}', + title: '{% trans "Create New Location" %}', + url: "{% url 'stock-location-create' %}", + }, + ]; + + launchModalForm("{% url 'stock-item-create' %}", options); } \ No newline at end of file