From f04977e7e12dd7f6ba17abf6bbab5a017b1c0ab8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 4 Oct 2020 20:41:28 +1100 Subject: [PATCH] Add form / view for installing a stock item into another stock item --- InvenTree/stock/forms.py | 28 ++++++++++++++++++++++++++++ InvenTree/stock/urls.py | 1 + InvenTree/stock/views.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index a5c689a605..ebcf31cb23 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -8,6 +8,7 @@ from __future__ import unicode_literals from django import forms from django.forms.utils import ErrorDict from django.utils.translation import ugettext as _ +from django.core.validators import MinValueValidator from mptt.fields import TreeNodeChoiceField @@ -271,6 +272,33 @@ class ExportOptionsForm(HelperForm): self.fields['file_format'].choices = self.get_format_choices() +class InstallStockForm(HelperForm): + """ + Form for manually installing a stock item into another stock item + """ + + stock_item = forms.ModelChoiceField( + required=True, + queryset=StockItem.objects.filter(StockItem.IN_STOCK_FILTER), + help_text=_('Stock item to install') + ) + + quantity = RoundingDecimalFormField( + max_digits=10, decimal_places=5, + help_text=_('Stock quantity to assign'), + validators=[ + MinValueValidator(0.001) + ] + ) + + class Meta: + model = StockItem + fields = [ + 'stock_item', + 'quantity', + ] + + class UninstallStockForm(forms.ModelForm): """ Form for uninstalling a stock item which is installed in another item. diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index 4c86995cda..7ad8bc4f7f 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -25,6 +25,7 @@ stock_item_detail_urls = [ url(r'^delete_test_data/', views.StockItemDeleteTestData.as_view(), name='stock-item-delete-test-data'), url(r'^assign/', views.StockItemAssignToCustomer.as_view(), name='stock-item-assign'), url(r'^return/', views.StockItemReturnToStock.as_view(), name='stock-item-return'), + url(r'^install/', views.StockItemInstall.as_view(), name='stock-item-install'), url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'), diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index c09c328c66..d818e82aa9 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -683,6 +683,46 @@ class StockItemQRCode(QRCodeView): return None +class StockItemInstall(AjaxUpdateView): + """ + View for manually installing stock items into + a particular stock item. + + In contrast to the StockItemUninstall view, + only a single stock item can be installed at once. + + The "part" to be installed must be provided in the GET query parameters. + + """ + + model = StockItem + form_class = StockForms.InstallStockForm + ajax_form_title = _('Install Stock Item') + + def get_form(self): + + form = super().get_form() + + return form + + def post(self, request, *args, **kwargs): + + + form = self.get_form() + valid = False + + valid = form.is_valid() and valid + + if valid: + pass + + data = { + 'form_valid': valid, + } + + return self.renderJsonResponse(request, form, data=data) + + class StockItemUninstall(AjaxView, FormMixin): """ View for uninstalling one or more StockItems,