mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Calculate initial values for the view
This commit is contained in:
parent
fd22e713ff
commit
a686500df1
@ -600,12 +600,13 @@ class StockItem(MPTTModel):
|
||||
return self.installedItemCount() > 0
|
||||
|
||||
@transaction.atomic
|
||||
def installIntoStockItem(self, otherItem, user, notes):
|
||||
def installIntoStockItem(self, otherItem, quantity, user, notes):
|
||||
"""
|
||||
Install this stock item into another stock item.
|
||||
|
||||
Args
|
||||
otherItem: The stock item to install this item into
|
||||
quantity: The quantity of stock to install
|
||||
user: The user performing the operation
|
||||
notes: Any notes associated with the operation
|
||||
"""
|
||||
|
@ -699,25 +699,52 @@ class StockItemInstall(AjaxUpdateView):
|
||||
form_class = StockForms.InstallStockForm
|
||||
ajax_form_title = _('Install Stock Item')
|
||||
|
||||
def get_stock_items(self):
|
||||
"""
|
||||
Return a list of stock items suitable for displaying to the user.
|
||||
|
||||
Requirements:
|
||||
- Items must be in stock
|
||||
|
||||
Filters:
|
||||
- Items can be filtered by Part reference
|
||||
"""
|
||||
|
||||
items = StockItem.objects.filter(StockItem.IN_STOCK_FILTER)
|
||||
|
||||
# Filter by Part association
|
||||
try:
|
||||
part = self.request.GET.get('part', None)
|
||||
|
||||
print(self.request.GET)
|
||||
|
||||
if part is not None:
|
||||
part = Part.objects.get(pk=part)
|
||||
items = items.filter(part=part)
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
return items
|
||||
|
||||
def get_initial(self):
|
||||
|
||||
initials = super().get_initial()
|
||||
|
||||
items = self.get_stock_items()
|
||||
|
||||
# If there is a single stock item available, we can use it!
|
||||
if items.count() == 1:
|
||||
item = items.first()
|
||||
initials['stock_item'] = item.pk
|
||||
initials['quantity_to_install'] = item.quantity
|
||||
|
||||
return initials
|
||||
|
||||
def get_form(self):
|
||||
|
||||
form = super().get_form()
|
||||
|
||||
queryset = form.fields['stock_item'].queryset
|
||||
|
||||
part = self.request.GET.get('part', None)
|
||||
|
||||
# Filter the available stock items based on the Part reference
|
||||
if part:
|
||||
try:
|
||||
part = Part.objects.get(pk=part)
|
||||
|
||||
queryset = queryset.filter(part=part)
|
||||
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
form.fields['stock_item'].queryset = queryset
|
||||
form.fields['stock_item'].queryset = self.get_stock_items()
|
||||
|
||||
return form
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user