From 3869bc27c9ae1a771d8140a3a5b5d18302afdd79 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 30 May 2019 09:01:16 +1000 Subject: [PATCH] Whoops, that form was being used. Created a copy of the form for multiple-item-stock-movements --- InvenTree/InvenTree/models.py | 2 +- InvenTree/stock/forms.py | 36 +++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index a7fc93bf3f..948163555c 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -198,7 +198,7 @@ class InvenTreeTree(models.Model): def __str__(self): """ String representation of a category is the full path to that category """ - return self.pathstring + return "{path} - {desc}".format(path=self.pathstring, desc=self.description) @receiver(pre_delete, sender=InvenTreeTree, dispatch_uid='tree_pre_delete_log') diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 5f22602a39..5ee74e40e3 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -42,9 +42,21 @@ class CreateStockItemForm(HelperForm): ] -class MoveStockItemForm(forms.ModelForm): +class MoveStockItemForm(HelperForm): """ Form for moving a StockItem to a new location """ + note = forms.CharField(label='Notes', required=True, help_text='Add note (required)') + + class Meta: + model = StockItem + + fields = [ + 'location', + 'note' + ] + +class MoveMultipleStockItemsForm(forms.ModelForm): + def get_location_choices(self): locs = StockLocation.objects.all() @@ -68,7 +80,27 @@ class MoveStockItemForm(forms.ModelForm): self.fields['location'].choices = self.get_location_choices() for item in stock_items: - self.fields['stock_item_{id}'.format(id=item.id)] = forms.IntegerField(required=True, initial=item.quantity, help_text='Quantity for ' + str(item)) + field = forms.IntegerField( + label= str(item.part), + required=True, + initial=item.quantity, + help_text='Quantity for ' + str(item)) + + extra = { + 'name': str(item.part), + 'location': str(item.location), + 'quantity': str(item.quantity), + } + + field.extra = extra + + self.fields['stock_item_{id}'.format(id=item.id)] = field + + def get_stock_fields(self): + for field_name in self.fields: + if field_name.startswith('stock_item_'): + print(field_name, self[field_name], self[field_name].extra) + yield self[field_name] class Meta: model = StockItem