mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
More fixes
- Allow stock item creation for inactive parts - Better handling of successful stock item creation - Disable fields rather than hiding them
This commit is contained in:
parent
b41dbba2b0
commit
f27acde934
@ -322,7 +322,6 @@ $("#item-create").click(function() {
|
|||||||
part: {{ part.part.id }},
|
part: {{ part.part.id }},
|
||||||
supplier_part: {{ part.id }},
|
supplier_part: {{ part.id }},
|
||||||
},
|
},
|
||||||
reload: true,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -886,7 +886,6 @@
|
|||||||
onPanelLoad("part-stock", function() {
|
onPanelLoad("part-stock", function() {
|
||||||
$('#new-stock-item').click(function () {
|
$('#new-stock-item').click(function () {
|
||||||
createNewStockItem({
|
createNewStockItem({
|
||||||
reload: true,
|
|
||||||
data: {
|
data: {
|
||||||
part: {{ part.id }},
|
part: {{ part.id }},
|
||||||
{% if part.default_location %}
|
{% if part.default_location %}
|
||||||
@ -919,7 +918,6 @@
|
|||||||
|
|
||||||
$('#item-create').click(function () {
|
$('#item-create').click(function () {
|
||||||
createNewStockItem({
|
createNewStockItem({
|
||||||
reload: true,
|
|
||||||
data: {
|
data: {
|
||||||
part: {{ part.id }},
|
part: {{ part.id }},
|
||||||
}
|
}
|
||||||
|
20
InvenTree/stock/migrations/0067_alter_stockitem_part.py
Normal file
20
InvenTree/stock/migrations/0067_alter_stockitem_part.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -456,7 +456,6 @@ class StockItem(MPTTModel):
|
|||||||
verbose_name=_('Base Part'),
|
verbose_name=_('Base Part'),
|
||||||
related_name='stock_items', help_text=_('Base part'),
|
related_name='stock_items', help_text=_('Base part'),
|
||||||
limit_choices_to={
|
limit_choices_to={
|
||||||
'active': True,
|
|
||||||
'virtual': False
|
'virtual': False
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -308,7 +308,6 @@
|
|||||||
|
|
||||||
$('#item-create').click(function () {
|
$('#item-create').click(function () {
|
||||||
createNewStockItem({
|
createNewStockItem({
|
||||||
table: '#stock-table',
|
|
||||||
data: {
|
data: {
|
||||||
{% if location %}
|
{% if location %}
|
||||||
location: {{ location.id }}
|
location: {{ location.id }}
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
|
clearFormInput,
|
||||||
|
disableFormInput,
|
||||||
|
enableFormInput,
|
||||||
hideFormInput,
|
hideFormInput,
|
||||||
setFormGroupVisibility,
|
setFormGroupVisibility,
|
||||||
showFormInput,
|
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
|
// Hide a form input
|
||||||
function hideFormInput(name, options) {
|
function hideFormInput(name, options) {
|
||||||
$(options.modal).find(`#div_id_${name}`).hide();
|
$(options.modal).find(`#div_id_${name}`).hide();
|
||||||
|
@ -138,20 +138,33 @@ function stockItemFields(options={}) {
|
|||||||
onSelect: function(data, field, opts) {
|
onSelect: function(data, field, opts) {
|
||||||
// Callback when a new "part" is selected
|
// 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 (options.create) {
|
||||||
|
|
||||||
// If a "trackable" part is selected, enable serial number field
|
// If a "trackable" part is selected, enable serial number field
|
||||||
if (data.trackable) {
|
if (data.trackable) {
|
||||||
showFormInput('serial_numbers', opts);
|
enableFormInput('serial_numbers', opts);
|
||||||
|
// showFormInput('serial_numbers', opts);
|
||||||
} else {
|
} else {
|
||||||
updateFieldValue('serial_numbers', '', {}, opts);
|
clearFormInput('serial_numbers', opts);
|
||||||
hideFormInput('serial_numbers', opts);
|
disableFormInput('serial_numbers', opts);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Hide "purchase price" fields for non purchaseable parts!
|
// 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);
|
||||||
|
|
||||||
// TODO: Update "location" based on "default_location" returned
|
disableFormInput('supplier_part', opts);
|
||||||
|
disableFormInput('purchase_price', opts);
|
||||||
|
disableFormInput('purchase_price_currency', opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
supplier_part: {
|
supplier_part: {
|
||||||
@ -204,7 +217,7 @@ function stockItemFields(options={}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (options.create) {
|
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'];
|
delete fields['serial'];
|
||||||
} else {
|
} else {
|
||||||
// These fields cannot be edited once the stock item has been created
|
// These fields cannot be edited once the stock item has been created
|
||||||
@ -321,25 +334,28 @@ function createNewStockItem(options={}) {
|
|||||||
options.onSuccess = function(response) {
|
options.onSuccess = function(response) {
|
||||||
// If a single stock item has been created, follow it!
|
// If a single stock item has been created, follow it!
|
||||||
if (response.pk) {
|
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',
|
icon: 'fas fa-boxes',
|
||||||
});
|
});
|
||||||
|
|
||||||
location.href = url;
|
window.location.href = url;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// Multiple stock items have been created (i.e. serialized stock)
|
||||||
|
|
||||||
var q = response.quantity;
|
var q = response.quantity;
|
||||||
|
|
||||||
showMessage('{% trans "Created stock items" %}', {
|
showMessage('{% trans "Created multiple stock items" %}', {
|
||||||
icon: 'fas fa-boxes',
|
icon: 'fas fa-boxes',
|
||||||
|
details: `{% trans "Serial numbers" %}: ${response.serial_numbers}`
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.table) {
|
var table = options.table || '#stock-table';
|
||||||
|
|
||||||
// Reload the table
|
// Reload the table
|
||||||
$(options.table).bootstrapTable('refresh');
|
$(table).bootstrapTable('refresh');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user