mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Add form / view for installing a stock item into another stock item
This commit is contained in:
		@@ -8,6 +8,7 @@ from __future__ import unicode_literals
 | 
				
			|||||||
from django import forms
 | 
					from django import forms
 | 
				
			||||||
from django.forms.utils import ErrorDict
 | 
					from django.forms.utils import ErrorDict
 | 
				
			||||||
from django.utils.translation import ugettext as _
 | 
					from django.utils.translation import ugettext as _
 | 
				
			||||||
 | 
					from django.core.validators import MinValueValidator
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from mptt.fields import TreeNodeChoiceField
 | 
					from mptt.fields import TreeNodeChoiceField
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -271,6 +272,33 @@ class ExportOptionsForm(HelperForm):
 | 
				
			|||||||
        self.fields['file_format'].choices = self.get_format_choices()
 | 
					        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):
 | 
					class UninstallStockForm(forms.ModelForm):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Form for uninstalling a stock item which is installed in another item.
 | 
					    Form for uninstalling a stock item which is installed in another item.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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'^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'^assign/', views.StockItemAssignToCustomer.as_view(), name='stock-item-assign'),
 | 
				
			||||||
    url(r'^return/', views.StockItemReturnToStock.as_view(), name='stock-item-return'),
 | 
					    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'),
 | 
					    url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -683,6 +683,46 @@ class StockItemQRCode(QRCodeView):
 | 
				
			|||||||
            return None
 | 
					            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):
 | 
					class StockItemUninstall(AjaxView, FormMixin):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    View for uninstalling one or more StockItems,
 | 
					    View for uninstalling one or more StockItems,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user