From 4ffaad3f1acd12c031f232e17de5740f101ad9e8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 4 May 2019 19:00:11 +1000 Subject: [PATCH] Add a default_location to the PartCategory model - If a part does not specify a default location, look at the default location of the category --- .../0015_partcategory_default_location.py | 20 +++++++++++++++++++ InvenTree/part/models.py | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 InvenTree/part/migrations/0015_partcategory_default_location.py diff --git a/InvenTree/part/migrations/0015_partcategory_default_location.py b/InvenTree/part/migrations/0015_partcategory_default_location.py new file mode 100644 index 0000000000..33a47cc440 --- /dev/null +++ b/InvenTree/part/migrations/0015_partcategory_default_location.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2 on 2019-05-04 08:57 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0013_remove_stockitem_uuid'), + ('part', '0014_auto_20190502_2039'), + ] + + operations = [ + migrations.AddField( + model_name='partcategory', + name='default_location', + field=models.ForeignKey(blank=True, help_text='Default location for parts in this category', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_categories', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index e2823ba93b..fb4dcd350d 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -30,6 +30,13 @@ class PartCategory(InvenTreeTree): """ PartCategory provides hierarchical organization of Part objects. """ + default_location = models.ForeignKey( + 'stock.StockLocation', related_name="default_categories", + null=True, blank=True, + on_delete = models.SET_NULL, + help_text='Default location for parts in this category' + ) + def get_absolute_url(self): return reverse('category-detail', kwargs={'pk': self.id})