From 982803a0a7096c294053041440d11fd28f453674 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 17 Apr 2018 18:23:24 +1000 Subject: [PATCH] Updated Part model - Added 'default_location' - Added 'default_supplier' --- InvenTree/part/forms.py | 2 ++ .../migrations/0021_part_default_location.py | 22 +++++++++++++++ .../migrations/0022_auto_20180417_0819.py | 27 +++++++++++++++++++ InvenTree/part/models.py | 12 +++++++++ InvenTree/part/templates/part/detail.html | 12 +++++++++ InvenTree/stock/views.py | 6 ++++- 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 InvenTree/part/migrations/0021_part_default_location.py create mode 100644 InvenTree/part/migrations/0022_auto_20180417_0819.py diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 1b35767a31..dce4f007d7 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -24,6 +24,8 @@ class EditPartForm(forms.ModelForm): 'description', 'IPN', 'URL', + 'default_location', + 'default_supplier', 'minimum_stock', 'buildable', 'trackable', diff --git a/InvenTree/part/migrations/0021_part_default_location.py b/InvenTree/part/migrations/0021_part_default_location.py new file mode 100644 index 0000000000..0690abb280 --- /dev/null +++ b/InvenTree/part/migrations/0021_part_default_location.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.12 on 2018-04-17 08:12 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('stock', '0010_stockitem_build'), + ('part', '0020_part_salable'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='default_location', + field=models.ForeignKey(blank=True, help_text='Where is this item normally stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/part/migrations/0022_auto_20180417_0819.py b/InvenTree/part/migrations/0022_auto_20180417_0819.py new file mode 100644 index 0000000000..ed7c74db03 --- /dev/null +++ b/InvenTree/part/migrations/0022_auto_20180417_0819.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.12 on 2018-04-17 08:19 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('supplier', '0007_auto_20180416_1253'), + ('part', '0021_part_default_location'), + ] + + operations = [ + migrations.AddField( + model_name='part', + name='default_supplier', + field=models.ForeignKey(blank=True, help_text='Default supplier part', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='supplier.SupplierPart'), + ), + migrations.AlterField( + model_name='part', + name='default_location', + field=models.ForeignKey(blank=True, help_text='Where is this item normally stored?', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_parts', to='stock.StockLocation'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 16c349cf11..d44b2ae6b5 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -106,6 +106,18 @@ class Part(models.Model): image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True) + default_location = models.ForeignKey('stock.StockLocation', on_delete=models.SET_NULL, + blank=True, null=True, + help_text='Where is this item normally stored?', + related_name='default_parts') + + # Default supplier part + default_supplier = models.ForeignKey('supplier.SupplierPart', + on_delete=models.SET_NULL, + blank=True, null=True, + help_text='Default supplier part', + related_name='default_parts') + # Minimum "allowed" stock level minimum_stock = models.PositiveIntegerField(default=0, validators=[MinValueValidator(0)], help_text='Minimum allowed stock level') diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 0e1c7aae34..b45d62aa15 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -23,6 +23,18 @@ {% endif %} +{% if part.default_location %} + + Default Location + {{ part.default_location.pathstring }} + +{% endif %} +{% if part.default_supplier %} + + Default Supplier + {{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }} + +{% endif %} Units {{ part.units }} diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index cc715c0669..089953b16f 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -88,7 +88,11 @@ class StockItemCreate(CreateView): loc_id = self.request.GET.get('location', None) if part_id: - initials['part'] = get_object_or_404(Part, pk=part_id) + part = get_object_or_404(Part, pk=part_id) + if part: + initials['part'] = get_object_or_404(Part, pk=part_id) + initials['location'] = part.default_location + initials['supplier_part'] = part.default_supplier if loc_id: initials['location'] = get_object_or_404(StockLocation, pk=loc_id)