diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 8ab88155e2..9cd5435423 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -89,7 +89,8 @@ class EditStockLocationForm(HelperForm): fields = [ 'name', 'parent', - 'description' + 'description', + 'owner', ] @@ -132,6 +133,7 @@ class CreateStockItemForm(HelperForm): 'link', 'delete_on_deplete', 'status', + 'owner', ] # Custom clean to prevent complex StockItem.clean() logic from running (yet) @@ -403,6 +405,7 @@ class EditStockItemForm(HelperForm): 'purchase_price', 'link', 'delete_on_deplete', + 'owner', ] diff --git a/InvenTree/stock/migrations/0056_auto_20201201_1844.py b/InvenTree/stock/migrations/0056_auto_20201201_1844.py new file mode 100644 index 0000000000..bc5f8bc4db --- /dev/null +++ b/InvenTree/stock/migrations/0056_auto_20201201_1844.py @@ -0,0 +1,27 @@ +# Generated by Django 3.0.7 on 2020-12-01 18:44 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0011_update_proxy_permissions'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('stock', '0055_auto_20201117_1453'), + ] + + operations = [ + migrations.AddField( + model_name='stockitem', + name='owner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owner_stockitems', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='stocklocation', + name='owner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owner_stocklocations', to='auth.Group'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index d1e46c53a7..d42ba88e28 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -16,7 +16,7 @@ from django.db import models, transaction from django.db.models import Sum, Q from django.db.models.functions import Coalesce from django.core.validators import MinValueValidator -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from django.db.models.signals import pre_delete from django.dispatch import receiver @@ -44,6 +44,9 @@ class StockLocation(InvenTreeTree): Stock locations can be heirarchical as required """ + owner = models.ForeignKey(Group, on_delete=models.SET_NULL, blank=True, null=True, + related_name='owner_stocklocations') + def get_absolute_url(self): return reverse('stock-location-detail', kwargs={'pk': self.id}) @@ -459,6 +462,9 @@ class StockItem(MPTTModel): help_text=_('Single unit purchase price at time of purchase'), ) + owner = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True, + related_name='owner_stockitems') + def clearAllocations(self): """ Clear all order allocations for this StockItem: