mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Pass part selection back-and-forwards between client/server
This commit is contained in:
parent
782d740323
commit
99dee64f79
@ -55,17 +55,20 @@
|
|||||||
<span row_id='{{ row.index }}' class='glyphicon glyphicon-small glyphicon-plus' onClick='newPartFromBomWizard()'/>
|
<span row_id='{{ row.index }}' class='glyphicon glyphicon-small glyphicon-plus' onClick='newPartFromBomWizard()'/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<select class='select bomselect' id='select_part_{{ row.index }}' name='part_select_{{ row.index }}'>
|
<select class='select bomselect' id='select_part_{{ row.index }}' name='part_{{ row.index }}'>
|
||||||
<option value=''>---------</option>
|
<option value=''>---------</option>
|
||||||
{% for part in row.part_options %}
|
{% for part in row.part_options %}
|
||||||
<option value='{{ part.id }}'>{{ part.full_name }} - <i>{{ part.description }}</i></option>
|
<option value='{{ part.id }}'{% if part.id == row.part.id %} selected='selected'{% endif %}>{{ part.full_name }} - {{ part.description }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<i>{{ item.cell }}</i>
|
<i>{{ item.cell }}</i>
|
||||||
|
{% if row.errors.part %}
|
||||||
|
<p class='help-inline'>{{ row.errors.part }}</p>
|
||||||
|
{% endif %}
|
||||||
{% elif item.column.guess == 'Quantity' %}
|
{% elif item.column.guess == 'Quantity' %}
|
||||||
<input name='quantity_{{ row.index }}' class='numberinput' type='number' min='1' value='{{ row.quantity }}'/>
|
<input name='quantity_{{ row.index }}' class='numberinput' type='number' min='1' value='{{ row.quantity }}'/>
|
||||||
{% if row.errors.quantity %}
|
{% if row.errors.quantity %}
|
||||||
<p class='help-block'>{{ row.errors.quantity }}</p>
|
<p class='help-inline'>{{ row.errors.quantity }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif item.column.guess == 'Reference' %}
|
{% elif item.column.guess == 'Reference' %}
|
||||||
<input name='reference_{{ row.index }}' value='{{ row.reference }}'/>
|
<input name='reference_{{ row.index }}' value='{{ row.reference }}'/>
|
||||||
|
@ -702,7 +702,7 @@ class BomUpload(FormView):
|
|||||||
rows.append({
|
rows.append({
|
||||||
'index': row.get('index', -1),
|
'index': row.get('index', -1),
|
||||||
'data': data,
|
'data': data,
|
||||||
'part_options': row.get('part_options', []),
|
'part_options': row.get('part_options', self.allowed_parts),
|
||||||
|
|
||||||
# User-input (passed between client and server)
|
# User-input (passed between client and server)
|
||||||
'quantity': row.get('quantity', None),
|
'quantity': row.get('quantity', None),
|
||||||
@ -1025,7 +1025,6 @@ class BomUpload(FormView):
|
|||||||
row = self.getRowByIndex(row_id)
|
row = self.getRowByIndex(row_id)
|
||||||
|
|
||||||
if row is None:
|
if row is None:
|
||||||
print("No match found for row", row_id)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
q = 1
|
q = 1
|
||||||
@ -1042,6 +1041,51 @@ class BomUpload(FormView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Extract part from each row
|
||||||
|
if key.startswith('part_'):
|
||||||
|
try:
|
||||||
|
row_id = int(key.replace('part_', ''))
|
||||||
|
|
||||||
|
row = self.getRowByIndex(row_id)
|
||||||
|
|
||||||
|
if row is None:
|
||||||
|
continue
|
||||||
|
except ValueError:
|
||||||
|
# Row ID non integer value
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
part_id = int(value)
|
||||||
|
part = Part.objects.get(id=part_id)
|
||||||
|
except ValueError:
|
||||||
|
row['errors']['part'] = _('Select valid part')
|
||||||
|
continue
|
||||||
|
except Part.DoesNotExist:
|
||||||
|
row['errors']['part'] = _('Select valid part')
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Keep track of how many of each part we have seen
|
||||||
|
if part_id in parts:
|
||||||
|
parts[part_id]['quantity'] += 1
|
||||||
|
row['errors']['part'] = _('Duplicate part selected')
|
||||||
|
else:
|
||||||
|
parts[part_id] = {
|
||||||
|
'part': part,
|
||||||
|
'quantity': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
row['part'] = part
|
||||||
|
|
||||||
|
# Are there any errors after form handling?
|
||||||
|
valid = True
|
||||||
|
|
||||||
|
for row in self.bom_rows:
|
||||||
|
errors = row.get('errors', [])
|
||||||
|
|
||||||
|
if len(errors) > 0:
|
||||||
|
valid = False
|
||||||
|
|
||||||
|
|
||||||
self.template_name = 'part/bom_upload/select_parts.html'
|
self.template_name = 'part/bom_upload/select_parts.html'
|
||||||
|
|
||||||
return self.render_to_response(self.get_context_data(form=None))
|
return self.render_to_response(self.get_context_data(form=None))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user