mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-15 19:43:09 +00:00
suggested changes @eeintech
This commit is contained in:
parent
75cdec81ae
commit
fc9e1e6770
@ -180,4 +180,4 @@ class MatchItem(forms.Form):
|
|||||||
|
|
||||||
def get_special_field(self, col_guess, row, file_manager):
|
def get_special_field(self, col_guess, row, file_manager):
|
||||||
""" function to be overriden in inherited forms to add specific form settings """
|
""" function to be overriden in inherited forms to add specific form settings """
|
||||||
pass
|
return None
|
||||||
|
@ -176,11 +176,11 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
form_list = [
|
forms = {
|
||||||
('upload', forms.UploadFile),
|
'upload': forms.UploadFile,
|
||||||
('fields', forms.MatchField),
|
'fields': forms.MatchField,
|
||||||
('items', forms.MatchItem),
|
'items': forms.MatchItem,
|
||||||
]
|
}
|
||||||
form_steps_description = [
|
form_steps_description = [
|
||||||
_("Upload File"),
|
_("Upload File"),
|
||||||
_("Match Fields"),
|
_("Match Fields"),
|
||||||
@ -190,29 +190,21 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
extra_context_data = {}
|
extra_context_data = {}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
""" initialize the FormView """
|
""" initialize the FormView
|
||||||
# check if form_list should be overriden
|
Use the following syntax to override the forms that should be used in the steps:
|
||||||
if hasattr(self, 'form_list_override'):
|
|
||||||
# check for list
|
|
||||||
if not isinstance(self.form_list_override, list):
|
|
||||||
raise ValueError('form_list_override must be a list')
|
|
||||||
|
|
||||||
# loop through and override /add form_list enrties
|
def __init__(self, *args, **kwargs):
|
||||||
for entry in self.form_list_override:
|
self.forms['items'] = self.CustomMatchItem
|
||||||
# fetch postition
|
return super().__init__(*args, **kwargs)
|
||||||
pos = [self.form_list.index(i) for i in self.form_list if i[0] == 'items']
|
"""
|
||||||
# replace if exists
|
# Construct form_list
|
||||||
if pos:
|
self.form_list = [(key, value) for key, value in self.forms.items()]
|
||||||
self.form_list[pos[0]] = entry
|
|
||||||
# or append
|
|
||||||
else:
|
|
||||||
self.form_list.append(entry)
|
|
||||||
|
|
||||||
# perform all checks and inits for MultiStepFormView
|
# perform all checks and inits for MultiStepFormView
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
# Check for file manager class
|
# Check for file manager class
|
||||||
if not(hasattr(self, 'file_manager_class') and issubclass(self.file_manager_class, FileManager)):
|
if not hasattr(self, 'file_manager_class') and not issubclass(self.file_manager_class, FileManager):
|
||||||
raise NotImplementedError('A subclass of a file manager class needs to be set!')
|
raise NotImplementedError('A subclass of a file manager class needs to be set!')
|
||||||
|
|
||||||
def get_context_data(self, form=None, **kwargs):
|
def get_context_data(self, form=None, **kwargs):
|
||||||
@ -414,11 +406,7 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
'data': data,
|
'data': data,
|
||||||
'errors': {},
|
'errors': {},
|
||||||
}
|
}
|
||||||
|
self.rows.append(row)
|
||||||
# make sure that the row was submitted - solves https://github.com/inventree/InvenTree/pull/1588#issuecomment-847889353
|
|
||||||
row_exist_check = [a for a in self.request.POST.keys() if a.startswith(f'row_{int(row_idx) +1}_')]
|
|
||||||
if True in row_exist_check:
|
|
||||||
self.rows.append(row)
|
|
||||||
|
|
||||||
# In the item selection step: update row data with mapping to form fields
|
# In the item selection step: update row data with mapping to form fields
|
||||||
if form and self.steps.current == 'items':
|
if form and self.steps.current == 'items':
|
||||||
|
@ -581,9 +581,6 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
""" override MatchItem fields """
|
""" override MatchItem fields """
|
||||||
def get_special_field(self, col_guess, row, file_manager):
|
def get_special_field(self, col_guess, row, file_manager):
|
||||||
""" set special field """
|
""" set special field """
|
||||||
# run default
|
|
||||||
super().get_special_field(col_guess, row, file_manager)
|
|
||||||
|
|
||||||
# set quantity field
|
# set quantity field
|
||||||
if 'quantity' in col_guess.lower():
|
if 'quantity' in col_guess.lower():
|
||||||
return CharField(
|
return CharField(
|
||||||
@ -608,6 +605,9 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
default_amount=self.clean_nbr(row.get('price', '')),
|
default_amount=self.clean_nbr(row.get('price', '')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# return default
|
||||||
|
return super().get_special_field(col_guess, row, file_manager)
|
||||||
|
|
||||||
class OrderFileManager(FileManager):
|
class OrderFileManager(FileManager):
|
||||||
REQUIRED_HEADERS = [
|
REQUIRED_HEADERS = [
|
||||||
'Quantity',
|
'Quantity',
|
||||||
@ -625,9 +625,6 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
name = 'order'
|
name = 'order'
|
||||||
form_list_override = [
|
|
||||||
('items', OrderMatchItem),
|
|
||||||
]
|
|
||||||
form_steps_template = [
|
form_steps_template = [
|
||||||
'order/order_wizard/po_upload.html',
|
'order/order_wizard/po_upload.html',
|
||||||
'order/order_wizard/match_fields.html',
|
'order/order_wizard/match_fields.html',
|
||||||
@ -647,6 +644,10 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
}
|
}
|
||||||
file_manager_class = OrderFileManager
|
file_manager_class = OrderFileManager
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.forms['items'] = self.OrderMatchItem
|
||||||
|
return super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def get_order(self):
|
def get_order(self):
|
||||||
""" Get order or return 404 """
|
""" Get order or return 404 """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user