class SerializeStockForm(HelperForm): """ Form for serializing a StockItem. """ destination = TreeNodeChoiceField(queryset=StockLocation.objects.all(), label='Destination', required=True, help_text='Destination for serialized stock (by default, will remain in current location)') serial_numbers = forms.CharField(label='Serial numbers', required=True, help_text='Unique serial numbers (must match quantity)') note = forms.CharField(label='Notes', required=False, help_text='Add transaction note (optional)') quantity = RoundingDecimalFormField(max_digits=10, decimal_places=5) def __init__(self, *args, **kwargs): # Extract the stock item item = kwargs.pop('item', None) if item: self.field_placeholder['serial_numbers'] = item.part.getSerialNumberString(item.quantity) super().__init__(*args, **kwargs) class Meta: model = StockItem fields = [ 'quantity', 'serial_numbers', 'destination', 'note', ]
class UninstallStockForm(forms.ModelForm): """ Form for uninstalling a stock item which is installed in another item. """ location = TreeNodeChoiceField( queryset=StockLocation.objects.all(), label=_('Location'), help_text=_('Destination location for uninstalled items')) note = forms.CharField(label=_('Notes'), required=False, help_text=_('Add transaction note (optional)')) confirm = forms.BooleanField( required=False, initial=False, label=_('Confirm uninstall'), help_text=_('Confirm removal of installed stock items')) class Meta: model = StockItem fields = [ 'location', 'note', 'confirm', ]
class AdjustStockForm(forms.ModelForm): """ Form for performing simple stock adjustments. - Add stock - Remove stock - Count stock - Move stock This form is used for managing stock adjuments for single or multiple stock items. """ destination = TreeNodeChoiceField(queryset=StockLocation.objects.all(), label=_('Destination'), required=True, help_text=_('Destination stock location')) note = forms.CharField(label=_('Notes'), required=True, help_text=_('Add note (required)')) # transaction = forms.BooleanField(required=False, initial=False, label='Create Transaction', help_text='Create a stock transaction for these parts') confirm = forms.BooleanField(required=False, initial=False, label=_('Confirm stock adjustment'), help_text=_('Confirm movement of stock items')) set_loc = forms.BooleanField(required=False, initial=False, label=_('Set Default Location'), help_text=_('Set the destination as the default location for selected parts')) class Meta: model = StockItem fields = [ 'destination', 'note', # 'transaction', 'confirm', ]
class SerializeStockForm(forms.ModelForm): """ Form for serializing a StockItem. """ destination = TreeNodeChoiceField( queryset=StockLocation.objects.all(), label='Destination', required=True, help_text= 'Destination for serialized stock (by default, will remain in current location)' ) serial_numbers = forms.CharField( label='Serial numbers', required=True, help_text='Unique serial numbers (must match quantity)') note = forms.CharField(label='Notes', required=False, help_text='Add transaction note (optional)') class Meta: model = StockItem fields = [ 'quantity', 'serial_numbers', 'destination', 'note', ]
class DomainAdminForm(MPTTAdminForm): # restrict list of domains allowed to be parents to those domains # without a parent (1 level deep only) parent = TreeNodeChoiceField( queryset=Domain.objects.filter(parent__isnull=True), required=False) class Meta: model = Domain exclude = [] def clean_parent(self): parent = self.cleaned_data["parent"] if parent: # check parent id - cannot point to self if parent.id == self.instance.id: raise ValidationError( "Not permitted: a domain can not be its own parent", code='invalid') # restrict hierarchy to one level elif parent.parent: raise ValidationError( "Domain hierarchy restricted to depth of 1; " + parent.name + " is a collection of " + parent.parent.name, code='invalid') return parent def clean(self): # policy is optional by default, but top-level domains must have one (can't inherit from parent) if not self.cleaned_data.get('parent', None) and not self.cleaned_data['policy']: raise ValidationError("Policy is required for top-level domains") return self.cleaned_data
class ReceivePurchaseOrderForm(HelperForm): location = TreeNodeChoiceField(queryset=StockLocation.objects.all(), required=True, help_text=_('Receive parts to this location')) class Meta: model = PurchaseOrder fields = [ 'location', ]
class CustomUserCreationForm(UserCreationForm): # username = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Username'})) # first_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'First Name'}), max_length=32, help_text='First name') # last_name=forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Last Name'}), max_length=32, help_text='Last name') # email=forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': 'Email'}), max_length=64, help_text='Enter a valid email address') password1=forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Introduzca su password'})) password2=forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Repita su password'})) section = TreeNodeChoiceField(queryset=Section.objects.all()) class Meta(UserCreationForm.Meta): model = CustomUser fields = ('username', 'email', 'first_name', 'last_name', 'password1', 'password2')
class ReceivePurchaseOrderForm(HelperForm): location = TreeNodeChoiceField( queryset=StockLocation.objects.all(), required=True, label=_("Destination"), help_text=_("Receive parts to this location"), ) class Meta: model = PurchaseOrder fields = [ "location", ]
class EditProviderForm(forms.Form): first_name = forms.CharField(max_length=50, required=True, \ label=ugettext_lazy(u"First Name")) last_name = forms.CharField(max_length=50, required=True, \ label=ugettext_lazy(u"Last Name")) email = forms.EmailField(required=False, \ label=ugettext_lazy(u"E-mail Address")) phone_number = forms.CharField(max_length=12, required=False, \ label=ugettext_lazy(u"Phone Number")) role = forms.ChoiceField(label=ugettext_lazy(u"Role"), \ choices=[(role.slug, role.name) \ for role \ in Role.objects.all().order_by('name')]) entity = TreeNodeChoiceField(queryset=Entity.tree.all(), \ level_indicator=u'---', \ label=ugettext_lazy(u"Entity"))
class SetPartCategoryForm(forms.Form): """ Form for setting the category of multiple Part objects """ part_category = TreeNodeChoiceField(queryset=PartCategory.objects.all(), required=True, help_text=_('Select part category'))
class CustomUserChangeForm(UserChangeForm): section = TreeNodeChoiceField(queryset=Section.objects.all()) class Meta: model = CustomUser fields = UserChangeForm.Meta.fields
class PidAdminForm(ModelForm): domain = TreeNodeChoiceField(queryset=Domain.objects.all()) class Meta: model = Pid exclude = []
class ProductForm(forms.ModelForm): category = TreeNodeChoiceField(queryset=Category.objects.all()) class Meta: model = Product exclude = ['is_seen', 'is_deleted', 'is_active', 'store', 'slug']