mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Almost there?
This commit is contained in:
parent
6d8f94619b
commit
c9e77edf04
@ -126,15 +126,17 @@ class MatchItem(forms.Form):
|
|||||||
for row in row_data:
|
for row in row_data:
|
||||||
# Navigate column data
|
# Navigate column data
|
||||||
for col in row['data']:
|
for col in row['data']:
|
||||||
|
# Get column matching
|
||||||
|
col_guess = col['column'].get('guess', None)
|
||||||
|
|
||||||
# Create input for required headers
|
# Create input for required headers
|
||||||
if col['column']['guess'] in file_manager.REQUIRED_HEADERS:
|
if col_guess in file_manager.REQUIRED_HEADERS:
|
||||||
# Set field name
|
# Set field name
|
||||||
field_name = col['column']['guess'].lower() + '-' + str(row['index'])
|
field_name = col_guess.lower() + '-' + str(row['index'])
|
||||||
# Set field input box
|
# Set field input box
|
||||||
if 'quantity' in col['column']['guess'].lower():
|
if 'quantity' in col_guess.lower():
|
||||||
self.fields[field_name] = forms.CharField(
|
self.fields[field_name] = forms.CharField(
|
||||||
required=True,
|
required=False,
|
||||||
widget=forms.NumberInput(attrs={
|
widget=forms.NumberInput(attrs={
|
||||||
'name': 'quantity' + str(row['index']),
|
'name': 'quantity' + str(row['index']),
|
||||||
'class': 'numberinput', # form-control',
|
'class': 'numberinput', # form-control',
|
||||||
@ -144,15 +146,11 @@ class MatchItem(forms.Form):
|
|||||||
'value': row['quantity'],
|
'value': row['quantity'],
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
else:
|
# else:
|
||||||
self.fields[field_name] = forms.Input(
|
# self.fields[field_name] = forms.TextInput()
|
||||||
required=True,
|
|
||||||
widget=forms.Select(attrs={
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create item selection box
|
# Create item selection box
|
||||||
elif col['column']['guess'] in file_manager.ITEM_MATCH_HEADERS:
|
elif col_guess in file_manager.ITEM_MATCH_HEADERS:
|
||||||
# Get item options
|
# Get item options
|
||||||
item_options = [(option.id, option) for option in row['item_options']]
|
item_options = [(option.id, option) for option in row['item_options']]
|
||||||
# Get item match
|
# Get item match
|
||||||
@ -169,30 +167,27 @@ class MatchItem(forms.Form):
|
|||||||
)
|
)
|
||||||
# Update select box when match was found
|
# Update select box when match was found
|
||||||
if item_match:
|
if item_match:
|
||||||
# Make it a required field
|
# Make it a required field: does not validate if
|
||||||
self.fields[field_name].required = True
|
# removed using JS function
|
||||||
|
# self.fields[field_name].required = True
|
||||||
# Update initial value
|
# Update initial value
|
||||||
self.fields[field_name].initial = item_match.id
|
self.fields[field_name].initial = item_match.id
|
||||||
|
|
||||||
# Optional entries
|
# Optional entries
|
||||||
elif col['column']['guess'] in file_manager.OPTIONAL_HEADERS:
|
elif col_guess in file_manager.OPTIONAL_HEADERS:
|
||||||
# Set field name
|
# Set field name
|
||||||
field_name = col['column']['guess'].lower() + '-' + str(row['index'])
|
field_name = col_guess.lower() + '-' + str(row['index'])
|
||||||
# Get value
|
# Get value
|
||||||
value = row.get(col['column']['guess'].lower(), '')
|
value = row.get(col_guess.lower(), '')
|
||||||
# Set field input box
|
# Set field input box
|
||||||
if 'price' in col['column']['guess'].lower():
|
if 'price' in col_guess.lower():
|
||||||
self.fields[field_name] = MoneyField(
|
self.fields[field_name] = MoneyField(
|
||||||
label=_(col['column']['guess']),
|
label=_(col_guess),
|
||||||
default_currency=InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY'),
|
default_currency=InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY'),
|
||||||
decimal_places=5,
|
decimal_places=5,
|
||||||
max_digits=19,
|
max_digits=19,
|
||||||
required=False,
|
required=False,
|
||||||
default_amount=value,
|
default_amount=value,
|
||||||
)
|
)
|
||||||
else:
|
# else:
|
||||||
self.fields[field_name] = forms.Input(
|
# self.fields[field_name] = forms.TextInput()
|
||||||
required=True,
|
|
||||||
widget=forms.Select(attrs={
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
@ -205,8 +205,10 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
stored_data = self.storage.get_step_data(self.steps.current)
|
stored_data = self.storage.get_step_data(self.steps.current)
|
||||||
if stored_data:
|
if stored_data:
|
||||||
self.get_form_table_data(stored_data)
|
self.get_form_table_data(stored_data)
|
||||||
# Set form table data
|
else:
|
||||||
self.set_form_table_data(form=form)
|
if form.is_valid() or self.steps.current == 'items':
|
||||||
|
# Set form table data
|
||||||
|
self.set_form_table_data(form=form)
|
||||||
|
|
||||||
# Update context
|
# Update context
|
||||||
context.update({'rows': self.rows})
|
context.update({'rows': self.rows})
|
||||||
@ -302,7 +304,7 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.column_names[value] = col_id
|
self.column_names[col_id] = value
|
||||||
|
|
||||||
# Extract the column selections (in the 'select fields' view)
|
# Extract the column selections (in the 'select fields' view)
|
||||||
if item.startswith('fields-'):
|
if item.startswith('fields-'):
|
||||||
@ -312,7 +314,30 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.column_selections[col_name] = value
|
for idx, name in self.column_names.items():
|
||||||
|
if name == col_name:
|
||||||
|
self.column_selections[idx] = value
|
||||||
|
break
|
||||||
|
|
||||||
|
# Extract the row data
|
||||||
|
if item.startswith('row_'):
|
||||||
|
# Item should be of the format row_<r>_col_<c>
|
||||||
|
s = item.split('_')
|
||||||
|
|
||||||
|
if len(s) < 4:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Ignore row/col IDs which are not correct numeric values
|
||||||
|
try:
|
||||||
|
row_id = int(s[1])
|
||||||
|
col_id = int(s[3])
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if row_id not in self.row_data:
|
||||||
|
self.row_data[row_id] = {}
|
||||||
|
|
||||||
|
self.row_data[row_id][col_id] = value
|
||||||
|
|
||||||
def set_form_table_data(self, form=None):
|
def set_form_table_data(self, form=None):
|
||||||
""" Set the form table data """
|
""" Set the form table data """
|
||||||
@ -321,10 +346,10 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
# Re-construct the column data
|
# Re-construct the column data
|
||||||
self.columns = []
|
self.columns = []
|
||||||
|
|
||||||
for key in self.column_names:
|
for idx, value in self.column_names.items():
|
||||||
header = ({
|
header = ({
|
||||||
'name': key,
|
'name': value,
|
||||||
'guess': self.column_selections.get(key, ''),
|
'guess': self.column_selections.get(idx, ''),
|
||||||
})
|
})
|
||||||
self.columns.append(header)
|
self.columns.append(header)
|
||||||
|
|
||||||
@ -332,49 +357,45 @@ class FileManagementFormView(MultiStepFormView):
|
|||||||
# Re-construct the row data
|
# Re-construct the row data
|
||||||
self.rows = []
|
self.rows = []
|
||||||
|
|
||||||
for row_idx in sorted(self.row_data.keys()):
|
# if self.column_names:
|
||||||
row = self.row_data[row_idx]
|
# rows_shown = []
|
||||||
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': {},
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
if self.column_names:
|
|
||||||
rows_shown = []
|
|
||||||
|
|
||||||
# Update the row data
|
# Update the row data
|
||||||
for row in self.rows:
|
for row_idx in sorted(self.row_data.keys()):
|
||||||
row_data = row['data']
|
row_data = self.row_data[row_idx]
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
show_data = []
|
# show_data = []
|
||||||
|
|
||||||
for idx, item in enumerate(row_data):
|
for idx, item in row_data.items():
|
||||||
column_data = {
|
column_data = {
|
||||||
|
'name': self.column_names[idx],
|
||||||
|
'guess': self.column_selections[idx],
|
||||||
|
}
|
||||||
|
|
||||||
|
cell_data = {
|
||||||
'cell': item,
|
'cell': item,
|
||||||
'idx': idx,
|
'idx': idx,
|
||||||
'column': self.columns[idx],
|
'column': column_data,
|
||||||
}
|
}
|
||||||
data.append(column_data)
|
data.append(cell_data)
|
||||||
if not self.column_names or self.columns[idx]['name'] in self.column_names:
|
# if not self.column_names or column_data.get('name', '') in self.column_names:
|
||||||
show_data.append(column_data)
|
# show_data.append(cell_data)
|
||||||
|
|
||||||
|
row = {
|
||||||
|
'index': row_idx,
|
||||||
|
'data': data,
|
||||||
|
'errors': {},
|
||||||
|
}
|
||||||
|
self.rows.append(row)
|
||||||
|
|
||||||
|
# if self.column_names:
|
||||||
|
# current_row = row
|
||||||
|
# current_row['data'] = show_data
|
||||||
|
# rows_shown.append(current_row)
|
||||||
|
|
||||||
row['data'] = data
|
# if self.column_names and self.get_step_index() == 3:
|
||||||
if self.column_names:
|
# self.rows = rows_shown
|
||||||
current_row = row
|
|
||||||
current_row['data'] = show_data
|
|
||||||
rows_shown.append(current_row)
|
|
||||||
|
|
||||||
if self.column_names and self.get_step_index() == 3:
|
|
||||||
self.rows = rows_shown
|
|
||||||
|
|
||||||
# In the item selection step: update row data to contain fields
|
# In the item selection step: update row data to contain fields
|
||||||
if form and self.steps.current == 'items':
|
if form and self.steps.current == 'items':
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
{% block form_content %}
|
{% block form_content %}
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
|
||||||
<th>{% trans "File Fields" %}</th>
|
<th>{% trans "File Fields" %}</th>
|
||||||
|
<th></th>
|
||||||
{% for col in form %}
|
{% for col in form %}
|
||||||
<th>
|
<th>
|
||||||
<div>
|
<div>
|
||||||
@ -49,8 +49,8 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
|
||||||
<td>{% trans "Match Fields" %}</td>
|
<td>{% trans "Match Fields" %}</td>
|
||||||
|
<td></td>
|
||||||
{% for col in form %}
|
{% for col in form %}
|
||||||
<td>
|
<td>
|
||||||
{{ col }}
|
{{ col }}
|
||||||
@ -65,18 +65,18 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
{% with forloop.counter as row_index %}
|
{% with forloop.counter0 as row_index %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td style='width: 32px;'>
|
||||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ row_index }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ row_index }}' style='display: inline; float: left;' title='{% trans "Remove row" %}'>
|
||||||
<span row_id='{{ row_index }}' class='fas fa-trash-alt icon-red'></span>
|
<span row_id='{{ row_index }}' class='fas fa-trash-alt icon-red'></span>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ row_index }}</td>
|
<td style='text-align: left;'>{{ row_index }}</td>
|
||||||
{% for item in row.data %}
|
{% for item in row.data %}
|
||||||
<td>
|
<td>
|
||||||
<input type='hidden' name='row_{{ row_index }}_col_{{ forloop.counter0 }}' value='{{ item }}'/>
|
<input type='hidden' name='row_{{ row_index }}_col_{{ forloop.counter0 }}' value='{{ item }}'/>
|
||||||
{{ item.cell }}
|
{{ item }}
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
{% block form_alert %}
|
{% block form_alert %}
|
||||||
|
{% if form.errors %}
|
||||||
|
{% endif %}
|
||||||
{% if form_errors %}
|
{% if form_errors %}
|
||||||
<div class='alert alert-danger alert-block' role='alert'>
|
<div class='alert alert-danger alert-block' role='alert'>
|
||||||
{% trans "Errors exist in the submitted data" %}
|
{% trans "Errors exist in the submitted data" %}
|
||||||
@ -21,11 +23,12 @@
|
|||||||
{% block form_content %}
|
{% block form_content %}
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>{% trans "Row" %}</th>
|
<th>{% trans "Row" %}</th>
|
||||||
<th>{% trans "Select Supplier Part" %}</th>
|
<th>{% trans "Select Supplier Part" %}</th>
|
||||||
|
<th>{% trans "Quantity" %}</th>
|
||||||
{% for col in columns %}
|
{% for col in columns %}
|
||||||
|
{% if col.name != 'Quantity' %}
|
||||||
<th>
|
<th>
|
||||||
<input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
|
<input type='hidden' name='col_name_{{ forloop.counter0 }}' value='{{ col.name }}'/>
|
||||||
<input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
|
<input type='hidden' name='col_guess_{{ forloop.counter0 }}' value='{{ col.guess }}'/>
|
||||||
@ -35,6 +38,7 @@
|
|||||||
{{ col.name }}
|
{{ col.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</th>
|
</th>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -42,13 +46,12 @@
|
|||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
<tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
|
<tr {% if row.errors %} style='background: #ffeaea;'{% endif %} part-select='#select_part_{{ row.index }}'>
|
||||||
<td>
|
<td>
|
||||||
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ forloop.counter }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
<button class='btn btn-default btn-remove' onClick='removeRowFromBomWizard()' id='del_row_{{ forloop.counter0 }}' style='display: inline; float: right;' title='{% trans "Remove row" %}'>
|
||||||
<span row_id='{{ forloop.counter }}' class='fas fa-trash-alt icon-red'></span>
|
<span row_id='{{ forloop.counter }}' class='fas fa-trash-alt icon-red'></span>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
|
||||||
<td>
|
<td>
|
||||||
{% add row.index 1 %}
|
{{ row.index }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% for field in form.visible_fields %}
|
{% for field in form.visible_fields %}
|
||||||
@ -60,18 +63,20 @@
|
|||||||
<p class='help-inline'>{{ row.errors.part }}</p>
|
<p class='help-inline'>{{ row.errors.part }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% for item in row.data %}
|
|
||||||
<td>
|
<td>
|
||||||
{% if item.column.guess == 'Quantity' %}
|
{% for field in form.visible_fields %}
|
||||||
{% for field in form.visible_fields %}
|
{% if field.name == row.quantity_select %}
|
||||||
{% if field.name == row.quantity_select %}
|
{{ field }}
|
||||||
{{ field }}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% if row.errors.quantity %}
|
|
||||||
<p class='help-inline'>{{ row.errors.quantity }}</p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif item.column.guess == 'Purchase_Price' %}
|
{% endfor %}
|
||||||
|
{% if row.errors.quantity %}
|
||||||
|
<p class='help-inline'>{{ row.errors.quantity }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
{% for item in row.data %}
|
||||||
|
{% if item.column.guess != 'Quantity' %}
|
||||||
|
<td>
|
||||||
|
{% if item.column.guess == 'Purchase_Price' %}
|
||||||
{% for field in form.visible_fields %}
|
{% for field in form.visible_fields %}
|
||||||
{% if field.name == row.price_select %}
|
{% if field.name == row.price_select %}
|
||||||
{{ field }}
|
{{ field }}
|
||||||
@ -82,6 +87,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<input type='hidden' name='row_{{ row.index }}_col_{{ forloop.counter0 }}' value='{{ item.cell }}'/>
|
<input type='hidden' name='row_{{ row.index }}_col_{{ forloop.counter0 }}' value='{{ item.cell }}'/>
|
||||||
</td>
|
</td>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -651,8 +651,8 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
except (ValueError, SupplierPart.DoesNotExist, SupplierPart.MultipleObjectsReturned):
|
except (ValueError, SupplierPart.DoesNotExist, SupplierPart.MultipleObjectsReturned):
|
||||||
exact_match_part = None
|
exact_match_part = None
|
||||||
|
|
||||||
# Check if there is a column corresponding to "Manufacturer MPN"
|
# Check if there is a column corresponding to "Manufacturer MPN" and no exact match found yet
|
||||||
if m_idx >= 0:
|
if m_idx >= 0 and not exact_match_part:
|
||||||
mpn = row['data'][m_idx]['cell']
|
mpn = row['data'][m_idx]['cell']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -755,7 +755,7 @@ class PurchaseOrderUpload(FileManagementFormView):
|
|||||||
order=order,
|
order=order,
|
||||||
part=supplier_part,
|
part=supplier_part,
|
||||||
quantity=purchase_order_item['quantity'],
|
quantity=purchase_order_item['quantity'],
|
||||||
purchase_price=purchase_order_item['purchase_price'],
|
purchase_price=purchase_order_item.get('purchase_price', None),
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
purchase_order_line_item.save()
|
purchase_order_line_item.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user