2019-04-27 12:18:07 +00:00
|
|
|
"""
|
|
|
|
Django Forms for interacting with Part objects
|
|
|
|
"""
|
|
|
|
|
2018-04-29 14:59:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from InvenTree.forms import HelperForm
|
2018-04-14 15:18:12 +00:00
|
|
|
|
2019-09-17 04:06:11 +00:00
|
|
|
from mptt.fields import TreeNodeChoiceField
|
2019-04-13 12:46:26 +00:00
|
|
|
from django import forms
|
2019-09-03 12:00:43 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2019-04-13 12:46:26 +00:00
|
|
|
|
2019-05-02 07:29:21 +00:00
|
|
|
from .models import Part, PartCategory, PartAttachment
|
|
|
|
from .models import BomItem
|
2019-08-20 04:14:21 +00:00
|
|
|
from .models import PartParameterTemplate, PartParameter
|
2018-04-14 15:18:12 +00:00
|
|
|
|
2019-09-03 12:00:43 +00:00
|
|
|
from common.models import Currency
|
|
|
|
|
2018-04-14 15:18:12 +00:00
|
|
|
|
2018-04-29 14:59:36 +00:00
|
|
|
class PartImageForm(HelperForm):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" Form for uploading a Part image """
|
2018-04-29 02:25:07 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Part
|
|
|
|
fields = [
|
|
|
|
'image',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-05-12 06:27:50 +00:00
|
|
|
class BomValidateForm(HelperForm):
|
|
|
|
""" Simple confirmation form for BOM validation.
|
|
|
|
User is presented with a single checkbox input,
|
|
|
|
to confirm that the BOM for this part is valid
|
|
|
|
"""
|
|
|
|
|
2019-09-03 12:00:43 +00:00
|
|
|
validate = forms.BooleanField(required=False, initial=False, help_text=_('Confirm that the BOM is correct'))
|
2019-05-12 06:27:50 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Part
|
|
|
|
fields = [
|
|
|
|
'validate'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-06-27 13:49:01 +00:00
|
|
|
class BomUploadSelectFile(HelperForm):
|
2019-05-24 13:56:36 +00:00
|
|
|
""" Form for importing a BOM. Provides a file input box for upload """
|
2019-04-13 12:46:26 +00:00
|
|
|
|
2019-09-03 12:00:43 +00:00
|
|
|
bom_file = forms.FileField(label='BOM file', required=True, help_text=_("Select BOM file to upload"))
|
2019-04-13 12:46:26 +00:00
|
|
|
|
2019-06-27 13:49:01 +00:00
|
|
|
class Meta:
|
|
|
|
model = Part
|
|
|
|
fields = [
|
|
|
|
'bom_file',
|
2019-06-27 12:16:24 +00:00
|
|
|
]
|
2019-06-27 13:49:01 +00:00
|
|
|
|
|
|
|
|
2019-05-02 07:29:21 +00:00
|
|
|
class EditPartAttachmentForm(HelperForm):
|
|
|
|
""" Form for editing a PartAttachment object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PartAttachment
|
|
|
|
fields = [
|
|
|
|
'part',
|
|
|
|
'attachment',
|
|
|
|
'comment'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-17 04:06:11 +00:00
|
|
|
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'))
|
|
|
|
|
|
|
|
|
2018-04-29 14:59:36 +00:00
|
|
|
class EditPartForm(HelperForm):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" Form for editing a Part object """
|
2018-04-14 15:18:12 +00:00
|
|
|
|
2019-05-13 11:41:32 +00:00
|
|
|
deep_copy = forms.BooleanField(required=False,
|
|
|
|
initial=True,
|
2019-09-03 12:00:43 +00:00
|
|
|
help_text=_("Perform 'deep copy' which will duplicate all BOM data for this part"),
|
2019-05-13 11:41:32 +00:00
|
|
|
widget=forms.HiddenInput())
|
|
|
|
|
|
|
|
confirm_creation = forms.BooleanField(required=False,
|
|
|
|
initial=False,
|
2019-09-03 12:00:43 +00:00
|
|
|
help_text=_('Confirm part creation'),
|
2019-05-13 11:41:32 +00:00
|
|
|
widget=forms.HiddenInput())
|
2019-05-11 02:29:02 +00:00
|
|
|
|
2018-04-14 15:18:12 +00:00
|
|
|
class Meta:
|
|
|
|
model = Part
|
|
|
|
fields = [
|
2019-05-13 11:41:32 +00:00
|
|
|
'deep_copy',
|
2019-05-11 02:29:02 +00:00
|
|
|
'confirm_creation',
|
2018-04-14 15:18:12 +00:00
|
|
|
'category',
|
|
|
|
'name',
|
2019-05-14 07:23:20 +00:00
|
|
|
'IPN',
|
2018-04-14 15:18:12 +00:00
|
|
|
'description',
|
2019-06-20 11:46:16 +00:00
|
|
|
'revision',
|
2019-05-14 07:23:20 +00:00
|
|
|
'keywords',
|
2019-06-02 10:07:30 +00:00
|
|
|
'variant_of',
|
|
|
|
'is_template',
|
2018-04-14 15:18:12 +00:00
|
|
|
'URL',
|
2018-04-17 08:23:24 +00:00
|
|
|
'default_location',
|
|
|
|
'default_supplier',
|
2019-04-15 14:01:15 +00:00
|
|
|
'units',
|
2018-04-14 15:18:12 +00:00
|
|
|
'minimum_stock',
|
2019-06-18 12:54:32 +00:00
|
|
|
'active',
|
2018-04-15 01:40:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-08-20 04:33:18 +00:00
|
|
|
class EditPartParameterTemplateForm(HelperForm):
|
|
|
|
""" Form for editing a PartParameterTemplate object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PartParameterTemplate
|
|
|
|
fields = [
|
|
|
|
'name',
|
|
|
|
'units'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-08-20 04:14:21 +00:00
|
|
|
class EditPartParameterForm(HelperForm):
|
|
|
|
""" Form for editing a PartParameter object """
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PartParameter
|
|
|
|
fields = [
|
|
|
|
'part',
|
|
|
|
'template',
|
|
|
|
'data'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-04-29 14:59:36 +00:00
|
|
|
class EditCategoryForm(HelperForm):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" Form for editing a PartCategory object """
|
2018-04-15 01:40:03 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PartCategory
|
|
|
|
fields = [
|
|
|
|
'parent',
|
|
|
|
'name',
|
2019-05-04 09:03:32 +00:00
|
|
|
'description',
|
2019-05-14 07:30:24 +00:00
|
|
|
'default_location',
|
|
|
|
'default_keywords',
|
2018-04-15 11:29:24 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-04-29 14:59:36 +00:00
|
|
|
class EditBomItemForm(HelperForm):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" Form for editing a BomItem object """
|
2018-04-15 11:29:24 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = BomItem
|
|
|
|
fields = [
|
|
|
|
'part',
|
|
|
|
'sub_part',
|
2019-04-15 15:41:01 +00:00
|
|
|
'quantity',
|
2019-06-27 13:57:21 +00:00
|
|
|
'reference',
|
2019-05-14 14:16:34 +00:00
|
|
|
'overage',
|
2019-04-15 15:41:01 +00:00
|
|
|
'note'
|
2018-04-15 15:02:17 +00:00
|
|
|
]
|
2019-04-27 23:53:42 +00:00
|
|
|
|
|
|
|
# Prevent editing of the part associated with this BomItem
|
2019-04-15 15:41:01 +00:00
|
|
|
widgets = {'part': forms.HiddenInput()}
|
2019-05-18 12:58:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PartPriceForm(forms.Form):
|
|
|
|
""" Simple form for viewing part pricing information """
|
|
|
|
|
|
|
|
quantity = forms.IntegerField(
|
|
|
|
required=True,
|
|
|
|
initial=1,
|
2019-09-03 12:00:43 +00:00
|
|
|
help_text=_('Input quantity for price calculation')
|
2019-05-18 12:58:11 +00:00
|
|
|
)
|
|
|
|
|
2019-09-17 10:17:25 +00:00
|
|
|
currency = forms.ModelChoiceField(queryset=Currency.objects.all(), label='Currency', help_text=_('Select currency for price calculation'))
|
2019-09-03 12:00:43 +00:00
|
|
|
|
2019-05-18 12:58:11 +00:00
|
|
|
class Meta:
|
|
|
|
model = Part
|
|
|
|
fields = [
|
2019-09-03 12:00:43 +00:00
|
|
|
'quantity',
|
|
|
|
'currency',
|
2019-05-18 12:58:11 +00:00
|
|
|
]
|