2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-15 08:48:11 +00:00

StockLocation owner is now a GenericForeignKey that can be set to user or group models

This commit is contained in:
eeintech
2021-01-11 12:56:40 -05:00
parent 587bf26d94
commit 6a88bdb37d
4 changed files with 88 additions and 39 deletions

View File

@@ -10,6 +10,7 @@ from django.forms.utils import ErrorDict
from django.utils.translation import ugettext as _
from django.core.validators import MinValueValidator
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User, Group
from mptt.fields import TreeNodeChoiceField
@@ -85,15 +86,37 @@ class EditStockItemTestResultForm(HelperForm):
class EditStockLocationForm(HelperForm):
""" Form for editing a StockLocation """
owner = forms.ChoiceField(
label=_('Owner'),
help_text=_('Select Owner')
)
class Meta:
model = StockLocation
fields = [
'name',
'parent',
'description',
'owner',
]
def get_owner_choices(self):
choices = [('', '-' * 10)]
for group in Group.objects.all():
choices.append((f'group_{group.name}', f'{group} (Group)'))
for user in User.objects.all():
choices.append((f'user_{user.username}', f'{user} (User)'))
return choices
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['owner'].choices = self.get_owner_choices()
class ConvertStockItemForm(HelperForm):
"""