mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Create a new part directly from the BOM view
- Pass data through to the part creation - Populate the new part into the select dropdown -
This commit is contained in:
parent
ff5af8f217
commit
85e803f345
@ -54,13 +54,14 @@ class BomUploadManager:
|
||||
# Fields which would be helpful but are not required
|
||||
OPTIONAL_HEADERS = [
|
||||
'Reference',
|
||||
'Notes',
|
||||
'Overage',
|
||||
'Description',
|
||||
'Category',
|
||||
'Supplier',
|
||||
'Manufacturer',
|
||||
'MPN',
|
||||
'Overage',
|
||||
'Notes'
|
||||
'IPN',
|
||||
]
|
||||
|
||||
EDITABLE_HEADERS = [
|
||||
|
@ -35,7 +35,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in bom_rows %}
|
||||
<tr>
|
||||
<tr part-description='{{ row.description }}' part-select='#select_part_{{ row.index }}'>
|
||||
<td>
|
||||
<button class='btn btn-default btn-remove' id='del_row_{{ forloop.counter }}' style='display: inline; float: right;' title='Remove row'>
|
||||
<span row_id='{{ forloop.counter }}' onClick='removeRowFromBomWizard()' class='glyphicon glyphicon-small glyphicon-remove'></span>
|
||||
@ -51,7 +51,7 @@
|
||||
<span row_id='{{ row.index }}' class='glyphicon glyphicon-small glyphicon-plus' onClick='newPartFromBomWizard()'/>
|
||||
</button>
|
||||
|
||||
<select class='select bomselect' id='id_part_{{ row.index }}' name='part_select_{{ row.index }}'>
|
||||
<select class='select bomselect' id='select_part_{{ row.index }}' name='part_select_{{ row.index }}'>
|
||||
<option value=''>---------</option>
|
||||
{% for part in row.part_options %}
|
||||
<option value='{{ part.id }}'>{{ part.full_name }} - <i>{{ part.description }}</i></option>
|
||||
@ -60,8 +60,12 @@
|
||||
<i>{{ item.cell }}</i>
|
||||
{% elif item.column.guess == 'Quantity' %}
|
||||
<input class='numberinput' type='number' min='1' value='{{ row.quantity }}'/>
|
||||
{% elif item.editable %}
|
||||
<input id='id_edit_{{ item.column.guess }}_{{ row.index }}' name='edit_{{ item.column.guess }}_{{ row.index }}' value='{{ item.cell }}'/>
|
||||
{% elif item.column.guess == 'Reference' %}
|
||||
<input name='reference_{{ row.index }}' value='{{ row.reference }}'/>
|
||||
{% elif item.column.guess == 'Notes' %}
|
||||
<input name='notes_{{ row.index }}' value='{{ row.notes }}'/>
|
||||
{% elif item.column.guess == 'Overage' %}
|
||||
<input name='overage_{{ row.index }}' value='{{ row.overage }}'/>
|
||||
{% else %}
|
||||
{{ item.cell }}
|
||||
{% endif %}
|
||||
|
@ -494,6 +494,11 @@ class PartCreate(AjaxCreateView):
|
||||
initials['keywords'] = category.default_keywords
|
||||
except PartCategory.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Allow initial data to be passed through as arguments
|
||||
for label in ['name', 'IPN', 'description', 'revision', 'keywords']:
|
||||
if label in self.request.GET:
|
||||
initials[label] = self.request.GET.get(label)
|
||||
|
||||
return initials
|
||||
|
||||
@ -698,8 +703,14 @@ class BomUpload(FormView):
|
||||
rows.append({
|
||||
'index': row.get('index', -1),
|
||||
'data': data,
|
||||
'part_options': row.get('part_options', []),
|
||||
|
||||
# User-input (passed between client and server)
|
||||
'quantity': row.get('quantity', None),
|
||||
'part_options': row.get('part_options', [])
|
||||
'description': row.get('description', ''),
|
||||
'part': row.get('part', None),
|
||||
'reference': row.get('reference', ''),
|
||||
'notes': row.get('notes', ''),
|
||||
})
|
||||
|
||||
ctx['part'] = self.part
|
||||
@ -774,21 +785,29 @@ class BomUpload(FormView):
|
||||
return self.render_to_response(self.get_context_data(form=form))
|
||||
|
||||
|
||||
def getColumnIndex(self, name):
|
||||
""" Return the index of the column with the given name.
|
||||
It named column is not found, return -1
|
||||
"""
|
||||
|
||||
try:
|
||||
idx = list(self.column_selections.values()).index(name)
|
||||
except ValueError:
|
||||
idx = -1
|
||||
|
||||
return idx
|
||||
|
||||
|
||||
def preFillSelections(self):
|
||||
""" Once data columns have been selected,
|
||||
attempt to pre-select the proper data from the database.
|
||||
"""
|
||||
|
||||
try:
|
||||
# Index of quantity field
|
||||
q_idx = list(self.column_selections.values()).index('Quantity')
|
||||
except ValueError:
|
||||
q_idx = -1
|
||||
|
||||
try:
|
||||
p_idx = list(self.column_selections.values()).index('Part')
|
||||
except ValueError:
|
||||
p_idx = -1
|
||||
q_idx = self.getColumnIndex('Quantity')
|
||||
p_idx = self.getColumnIndex('Part')
|
||||
d_idx = self.getColumnIndex('Description')
|
||||
r_idx = self.getColumnIndex('Reference')
|
||||
n_idx = self.getColumnIndex('Notes')
|
||||
|
||||
for row in self.bom_rows:
|
||||
|
||||
@ -816,11 +835,21 @@ class BomUpload(FormView):
|
||||
if len(matches) > 0:
|
||||
matches = sorted(matches, key=lambda item: item['match'], reverse=True)
|
||||
|
||||
if d_idx >= 0:
|
||||
row['description'] = row['data'][d_idx]
|
||||
|
||||
if r_idx >= 0:
|
||||
row['reference'] = row['data'][r_idx]
|
||||
|
||||
if n_idx >= 0:
|
||||
row['notes'] = row['data'][n_idx]
|
||||
|
||||
row['part'] = part
|
||||
row['quantity'] = quantity
|
||||
row['part_options'] = [m['part'] for m in matches]
|
||||
|
||||
|
||||
|
||||
def extractDataFromFile(self, bom):
|
||||
""" Read data from the BOM file """
|
||||
|
||||
|
@ -70,8 +70,21 @@ function newPartFromBomWizard(e) {
|
||||
|
||||
var src = e.target || e.srcElement;
|
||||
|
||||
var row = $(src).closest('tr');
|
||||
|
||||
launchModalForm('/part/new/', {
|
||||
success: function() {
|
||||
data: {
|
||||
'description': row.attr('part-description'),
|
||||
'name': row.attr('part-name'),
|
||||
},
|
||||
success: function(response) {
|
||||
/* A new part has been created! Push it as an option.
|
||||
*/
|
||||
|
||||
var select = row.attr('part-select');
|
||||
|
||||
var option = new Option(response.text, response.pk, true, true);
|
||||
$(select).append(option).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user