diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index d3bee4e797..276a9f7ebc 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -322,7 +322,6 @@ $("#item-create").click(function() { part: {{ part.part.id }}, supplier_part: {{ part.id }}, }, - reload: true, }); }); diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index e9b7b4252a..f03127e996 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -886,7 +886,6 @@ onPanelLoad("part-stock", function() { $('#new-stock-item').click(function () { createNewStockItem({ - reload: true, data: { part: {{ part.id }}, {% if part.default_location %} @@ -919,7 +918,6 @@ $('#item-create').click(function () { createNewStockItem({ - reload: true, data: { part: {{ part.id }}, } diff --git a/InvenTree/stock/migrations/0067_alter_stockitem_part.py b/InvenTree/stock/migrations/0067_alter_stockitem_part.py new file mode 100644 index 0000000000..7f00b8f7b1 --- /dev/null +++ b/InvenTree/stock/migrations/0067_alter_stockitem_part.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.5 on 2021-11-04 12:40 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0074_partcategorystar'), + ('stock', '0066_stockitem_scheduled_for_deletion'), + ] + + operations = [ + migrations.AlterField( + model_name='stockitem', + name='part', + field=models.ForeignKey(help_text='Base part', limit_choices_to={'virtual': False}, on_delete=django.db.models.deletion.CASCADE, related_name='stock_items', to='part.part', verbose_name='Base Part'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index eb0e6aa12f..320807e0c1 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -456,7 +456,6 @@ class StockItem(MPTTModel): verbose_name=_('Base Part'), related_name='stock_items', help_text=_('Base part'), limit_choices_to={ - 'active': True, 'virtual': False }) diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 24a6da69a9..18b78b2290 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -308,7 +308,6 @@ $('#item-create').click(function () { createNewStockItem({ - table: '#stock-table', data: { {% if location %} location: {{ location.id }} diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js index 42e3aac289..a86b64d0e2 100644 --- a/InvenTree/templates/js/translated/forms.js +++ b/InvenTree/templates/js/translated/forms.js @@ -25,6 +25,9 @@ */ /* exported + clearFormInput, + disableFormInput, + enableFormInput, hideFormInput, setFormGroupVisibility, showFormInput, @@ -1261,6 +1264,23 @@ function initializeGroups(fields, options) { } } +// Clear a form input +function clearFormInput(name, options) { + updateFieldValue(name, null, {}, options); +} + +// Disable a form input +function disableFormInput(name, options) { + $(options.modal).find(`#id_${name}`).prop('disabled', true); +} + + +// Enable a form input +function enableFormInput(name, options) { + $(options.modal).find(`#id_${name}`).prop('disabled', false); +} + + // Hide a form input function hideFormInput(name, options) { $(options.modal).find(`#div_id_${name}`).hide(); diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 3e6b35ca83..a7a60230f4 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -138,20 +138,33 @@ function stockItemFields(options={}) { onSelect: function(data, field, opts) { // Callback when a new "part" is selected - // If we are "creating" a new stock item + // If we are "creating" a new stock item, + // change the available fields based on the part properties if (options.create) { + // If a "trackable" part is selected, enable serial number field if (data.trackable) { - showFormInput('serial_numbers', opts); + enableFormInput('serial_numbers', opts); + // showFormInput('serial_numbers', opts); } else { - updateFieldValue('serial_numbers', '', {}, opts); - hideFormInput('serial_numbers', opts); + clearFormInput('serial_numbers', opts); + disableFormInput('serial_numbers', opts); + } + + // Enable / disable fields based on purchaseable status + if (data.purchaseable) { + enableFormInput('supplier_part', opts); + enableFormInput('purchase_price', opts); + enableFormInput('purchase_price_currency', opts); + } else { + clearFormInput('supplier_part', opts); + clearFormInput('purchase_price', opts); + + disableFormInput('supplier_part', opts); + disableFormInput('purchase_price', opts); + disableFormInput('purchase_price_currency', opts); } } - - // TODO: Hide "purchase price" fields for non purchaseable parts! - - // TODO: Update "location" based on "default_location" returned } }, supplier_part: { @@ -204,7 +217,7 @@ function stockItemFields(options={}) { }; if (options.create) { - // Use "serial numbers" field when creating a new stock item + // Use special "serial numbers" field when creating a new stock item delete fields['serial']; } else { // These fields cannot be edited once the stock item has been created @@ -321,25 +334,28 @@ function createNewStockItem(options={}) { options.onSuccess = function(response) { // If a single stock item has been created, follow it! if (response.pk) { - var url = `/stock/item/${pk}/`; + var url = `/stock/item/${response.pk}/`; - addCachedAlert('{% trans "Created stock item" %}', { + addCachedAlert('{% trans "Created new stock item" %}', { icon: 'fas fa-boxes', }); - location.href = url; + window.location.href = url; } else { + // Multiple stock items have been created (i.e. serialized stock) + var q = response.quantity; - showMessage('{% trans "Created stock items" %}', { + showMessage('{% trans "Created multiple stock items" %}', { icon: 'fas fa-boxes', + details: `{% trans "Serial numbers" %}: ${response.serial_numbers}` }); - if (options.table) { - // Reload the table - $(options.table).bootstrapTable('refresh'); - } + var table = options.table || '#stock-table'; + + // Reload the table + $(table).bootstrapTable('refresh'); } } }