mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Add uniqueness checking for the BomItemSubstitute model
This commit is contained in:
parent
0e1e8226b1
commit
ea4c4c514f
21
InvenTree/part/migrations/0073_auto_20211013_1048.py
Normal file
21
InvenTree/part/migrations/0073_auto_20211013_1048.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 3.2.5 on 2021-10-13 10:48
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('part', '0072_bomitemsubstitute'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='bomitemsubstitute',
|
||||||
|
options={'verbose_name': 'BOM Item Substitute'},
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='bomitemsubstitute',
|
||||||
|
unique_together={('part', 'bom_item')},
|
||||||
|
),
|
||||||
|
]
|
@ -2623,6 +2623,26 @@ class BomItemSubstitute(models.Model):
|
|||||||
part: The part which can be used as a substitute
|
part: The part which can be used as a substitute
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _("BOM Item Substitute")
|
||||||
|
|
||||||
|
# Prevent duplication of substitute parts
|
||||||
|
unique_together = ('part', 'bom_item')
|
||||||
|
|
||||||
|
def validate_unique(self, exclude=None):
|
||||||
|
"""
|
||||||
|
Ensure that this BomItemSubstitute is "unique":
|
||||||
|
|
||||||
|
- It cannot point to the same "part" as the "sub_part" of the parent "bom_item"
|
||||||
|
"""
|
||||||
|
|
||||||
|
super().validate_unique(exclude=exclude)
|
||||||
|
|
||||||
|
if self.part == self.bom_item.sub_part:
|
||||||
|
raise ValidationError({
|
||||||
|
"part": _("Substitute part cannot be the same as the master part"),
|
||||||
|
})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_api_url():
|
def get_api_url():
|
||||||
return reverse('api-bom-substitute-list')
|
return reverse('api-bom-substitute-list')
|
||||||
|
@ -213,11 +213,16 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
constructForm('{% url "api-bom-substitute-list" %}', {
|
constructForm('{% url "api-bom-substitute-list" %}', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
fields: {
|
fields: {
|
||||||
|
bom_item: {
|
||||||
|
hidden: true,
|
||||||
|
value: bom_item_id,
|
||||||
|
},
|
||||||
part: {
|
part: {
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
preFormContent: html,
|
preFormContent: html,
|
||||||
|
cancelText: '{% trans "Close" %}',
|
||||||
submitText: '{% trans "Add Substitute" %}',
|
submitText: '{% trans "Add Substitute" %}',
|
||||||
title: '{% trans "Edit BOM Item Substitutes" %}',
|
title: '{% trans "Edit BOM Item Substitutes" %}',
|
||||||
afterRender: function(fields, opts) {
|
afterRender: function(fields, opts) {
|
||||||
@ -243,8 +248,22 @@ function bomSubstitutesDialog(bom_item_id, substitutes, options={}) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSubmit: function(fields, opts) {
|
preventClose: true,
|
||||||
// TODO
|
onSuccess: function(response, opts) {
|
||||||
|
|
||||||
|
// Clear the form
|
||||||
|
var field = {
|
||||||
|
type: 'related field',
|
||||||
|
};
|
||||||
|
|
||||||
|
updateFieldValue('part', null, field, opts);
|
||||||
|
|
||||||
|
// Add the new substitute to the table
|
||||||
|
var row = renderSubstituteRow(response);
|
||||||
|
$(opts.modal).find('#substitute-table > tbody:last-child').append(row);
|
||||||
|
|
||||||
|
// Re-enable the "submit" button
|
||||||
|
$(opts.modal).find('#modal-form-submit').prop('disabled', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user