mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 19:15:41 +00:00
Add 'has_variants' and 'variant_of' field for Part
- StockItem cannot point to a part which is a template part
This commit is contained in:
19
InvenTree/stock/migrations/0002_auto_20190525_2226.py
Normal file
19
InvenTree/stock/migrations/0002_auto_20190525_2226.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2 on 2019-05-25 12:26
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitem',
|
||||
name='part',
|
||||
field=models.ForeignKey(help_text='Base part', limit_choices_to={'active': True, 'has_variants': True}, on_delete=django.db.models.deletion.CASCADE, related_name='stock_items', to='part.Part'),
|
||||
),
|
||||
]
|
@ -135,11 +135,18 @@ class StockItem(models.Model):
|
||||
})
|
||||
|
||||
if self.part is not None:
|
||||
# A trackable part must have a serial number
|
||||
if self.part.trackable and not self.serial:
|
||||
raise ValidationError({
|
||||
'serial': _('Serial number must be set for trackable items')
|
||||
})
|
||||
|
||||
# A template part cannot be instantiated as a StockItem
|
||||
if self.part.has_variants:
|
||||
raise ValidationError({
|
||||
'part': _('Stock item cannot be created for a template Part')
|
||||
})
|
||||
|
||||
except Part.DoesNotExist:
|
||||
# This gets thrown if self.supplier_part is null
|
||||
# TODO - Find a test than can be perfomed...
|
||||
@ -186,7 +193,12 @@ class StockItem(models.Model):
|
||||
}
|
||||
)
|
||||
|
||||
part = models.ForeignKey('part.Part', on_delete=models.CASCADE, related_name='stock_items', help_text='Base part')
|
||||
part = models.ForeignKey('part.Part', on_delete=models.CASCADE,
|
||||
related_name='stock_items', help_text='Base part',
|
||||
limit_choices_to={
|
||||
'has_variants': True,
|
||||
'active': True,
|
||||
})
|
||||
|
||||
supplier_part = models.ForeignKey('company.SupplierPart', blank=True, null=True, on_delete=models.SET_NULL,
|
||||
help_text='Select a matching supplier part for this stock item')
|
||||
|
Reference in New Issue
Block a user