mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
adding in optional headers
This commit is contained in:
@ -26,6 +26,8 @@ class FileManager:
|
||||
# Fields which would be helpful but are not required
|
||||
OPTIONAL_HEADERS = []
|
||||
|
||||
OPTIONAL_MATCH_HEADERS = []
|
||||
|
||||
EDITABLE_HEADERS = []
|
||||
|
||||
HEADERS = []
|
||||
@ -82,8 +84,8 @@ class FileManager:
|
||||
def update_headers(self):
|
||||
""" Update headers """
|
||||
|
||||
self.HEADERS = self.REQUIRED_HEADERS + self.ITEM_MATCH_HEADERS + self.OPTIONAL_HEADERS
|
||||
|
||||
self.HEADERS = self.REQUIRED_HEADERS + self.ITEM_MATCH_HEADERS + self.OPTIONAL_MATCH_HEADERS + self.OPTIONAL_HEADERS
|
||||
|
||||
def setup(self):
|
||||
""" Setup headers depending on the file name """
|
||||
|
||||
|
@ -220,3 +220,24 @@ class MatchItem(forms.Form):
|
||||
required=False,
|
||||
initial=value,
|
||||
)
|
||||
|
||||
# Optional item selection box
|
||||
elif col_guess in file_manager.OPTIONAL_MATCH_HEADERS:
|
||||
# Get item options
|
||||
item_options = [(option.id, option) for option in row['match_options_' + col_guess]]
|
||||
# Get item match
|
||||
item_match = row['match_' + col_guess]
|
||||
# Set field name
|
||||
field_name = col_guess.lower() + '-' + str(row['index'])
|
||||
# Set field select box
|
||||
self.fields[field_name] = forms.ChoiceField(
|
||||
choices=[('', '-' * 10)] + item_options,
|
||||
required=False,
|
||||
widget=forms.Select(attrs={
|
||||
'class': 'select bomselect',
|
||||
})
|
||||
)
|
||||
# Update select box when match was found
|
||||
if item_match:
|
||||
# Update initial value
|
||||
self.fields[field_name].initial = item_match.id
|
||||
|
Reference in New Issue
Block a user