2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Fixed form validation for previous step, hide tab depending on order status, added purchase_price field

This commit is contained in:
eeintech
2021-05-10 11:42:22 -04:00
parent 6857964c17
commit f0932040ee
7 changed files with 111 additions and 23 deletions

View File

@ -102,8 +102,9 @@ class FileManager:
]
self.OPTIONAL_HEADERS = [
'Unit_Price',
'Extended_Price',
'Purchase_Price',
'Reference',
'Notes',
]
# Update headers

View File

@ -8,6 +8,8 @@ from __future__ import unicode_literals
from django import forms
from django.utils.translation import gettext as _
from djmoney.forms.fields import MoneyField
from InvenTree.forms import HelperForm
from .files import FileManager
@ -121,6 +123,7 @@ class MatchItem(forms.Form):
for row in row_data:
# Navigate column data
for col in row['data']:
# Create input for required headers
if col['column']['guess'] in file_manager.REQUIRED_HEADERS:
# Set field name
@ -156,11 +159,37 @@ class MatchItem(forms.Form):
# Set field select box
self.fields[field_name] = forms.ChoiceField(
choices=[('', '-' * 10)] + item_options,
required=True,
required=False,
widget=forms.Select(attrs={
'class': 'select bomselect',
})
)
# Update initial selection
# Update select box when match was found
if item_match:
# Make it a required field
self.fields[field_name].required = True
# Update initial value
self.fields[field_name].initial = item_match.id
# Optional entries
elif col['column']['guess'] in file_manager.OPTIONAL_HEADERS:
# Set field name
field_name = col['column']['guess'].lower() + '-' + str(row['index'])
# Get value
value = row.get(col['column']['guess'].lower(), '')
# Set field input box
if 'price' in col['column']['guess'].lower():
self.fields[field_name] = MoneyField(
label=_(col['column']['guess']),
default_currency='USD',
decimal_places=5,
max_digits=19,
required=False,
default_amount=value,
)
else:
self.fields[field_name] = forms.Input(
required=True,
widget=forms.Select(attrs={
})
)

View File

@ -191,6 +191,7 @@ class FileManagementFormView(MultiStepFormView):
# Set keys for item matching
key_item_select = 'item_select'
key_quantity_select = 'quantity'
key_price_select = 'price'
def get_context_data(self, form, **kwargs):
context = super().get_context_data(form=form, **kwargs)
@ -314,6 +315,19 @@ class FileManagementFormView(MultiStepFormView):
self.column_selections[col_name] = value
def set_form_table_data(self, form=None):
""" Set the form table data """
if self.column_names:
# Re-construct the column data
self.columns = []
for key in self.column_names:
header = ({
'name': key,
'guess': self.column_selections.get(key, ''),
})
self.columns.append(header)
if self.row_data:
# Re-construct the row data
self.rows = []
@ -323,12 +337,12 @@ class FileManagementFormView(MultiStepFormView):
items = []
for col_idx in sorted(row.keys()):
value = row[col_idx]
items.append(value)
self.rows.append({
'index': row_idx,
'column': self.columns[row_idx],
'data': items,
'errors': {},
})
@ -370,17 +384,8 @@ class FileManagementFormView(MultiStepFormView):
row['item_select'] = self.key_item_select + '-' + str(row['index'])
# Add quantity select field
row['quantity_select'] = self.key_quantity_select + '-' + str(row['index'])
if self.column_names:
# Re-construct the column data
self.columns = []
for key in self.column_names:
header = ({
'name': key,
'guess': self.column_selections.get(key, ''),
})
self.columns.append(header)
# Add price select field
row['price_select'] = self.key_price_select + '-' + str(row['index'])
def get_column_index(self, name):
""" Return the index of the column with the given name.