2022-06-01 15:37:39 +00:00
|
|
|
"""Django Forms for interacting with Part objects."""
|
2019-04-27 12:18:07 +00:00
|
|
|
|
2021-07-01 04:44:23 +00:00
|
|
|
from django import forms
|
2022-05-01 20:03:49 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-07-01 04:44:23 +00:00
|
|
|
|
2021-07-05 18:57:45 +00:00
|
|
|
from common.forms import MatchItemForm
|
2022-05-20 15:24:51 +00:00
|
|
|
from InvenTree.helpers import clean_decimal
|
2021-01-14 04:20:42 +00:00
|
|
|
|
2022-07-25 01:17:59 +00:00
|
|
|
from .models import Part
|
2021-03-16 21:28:12 +00:00
|
|
|
|
|
|
|
|
2021-07-05 18:57:45 +00:00
|
|
|
class BomMatchItemForm(MatchItemForm):
|
2022-06-01 15:37:39 +00:00
|
|
|
"""Override MatchItemForm fields."""
|
2021-07-05 18:57:45 +00:00
|
|
|
|
|
|
|
def get_special_field(self, col_guess, row, file_manager):
|
2022-06-01 15:37:39 +00:00
|
|
|
"""Set special fields."""
|
2021-07-05 18:57:45 +00:00
|
|
|
# set quantity field
|
|
|
|
if 'quantity' in col_guess.lower():
|
|
|
|
return forms.CharField(
|
|
|
|
required=False,
|
|
|
|
widget=forms.NumberInput(attrs={
|
|
|
|
'name': 'quantity' + str(row['index']),
|
|
|
|
'class': 'numberinput',
|
|
|
|
'type': 'number',
|
|
|
|
'min': '0',
|
|
|
|
'step': 'any',
|
|
|
|
'value': clean_decimal(row.get('quantity', '')),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
return super().get_special_field(col_guess, row, file_manager)
|
2019-06-27 13:49:01 +00:00
|
|
|
|
|
|
|
|
2019-05-18 12:58:11 +00:00
|
|
|
class PartPriceForm(forms.Form):
|
2022-06-01 15:37:39 +00:00
|
|
|
"""Simple form for viewing part pricing information."""
|
2019-05-18 12:58:11 +00:00
|
|
|
|
|
|
|
quantity = forms.IntegerField(
|
|
|
|
required=True,
|
|
|
|
initial=1,
|
2021-04-04 20:44:14 +00:00
|
|
|
label=_('Quantity'),
|
2019-09-03 12:00:43 +00:00
|
|
|
help_text=_('Input quantity for price calculation')
|
2019-05-18 12:58:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2022-06-01 15:37:39 +00:00
|
|
|
"""Metaclass defines fields for this form"""
|
2019-05-18 12:58:11 +00:00
|
|
|
model = Part
|
|
|
|
fields = [
|
2019-09-03 12:00:43 +00:00
|
|
|
'quantity',
|
2019-05-18 12:58:11 +00:00
|
|
|
]
|