2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Supply part name for auto-fill when creating a new part

This commit is contained in:
Oliver Walters 2019-07-08 09:33:44 +10:00
parent 85e803f345
commit dff8d1fb95
2 changed files with 9 additions and 5 deletions

View File

@ -35,7 +35,7 @@
</thead> </thead>
<tbody> <tbody>
{% for row in bom_rows %} {% for row in bom_rows %}
<tr part-description='{{ row.description }}' part-select='#select_part_{{ row.index }}'> <tr part-name='{{ row.part_name }}' part-description='{{ row.description }}' part-select='#select_part_{{ row.index }}'>
<td> <td>
<button class='btn btn-default btn-remove' id='del_row_{{ forloop.counter }}' style='display: inline; float: right;' title='Remove row'> <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> <span row_id='{{ forloop.counter }}' onClick='removeRowFromBomWizard()' class='glyphicon glyphicon-small glyphicon-remove'></span>

View File

@ -708,6 +708,7 @@ class BomUpload(FormView):
# User-input (passed between client and server) # User-input (passed between client and server)
'quantity': row.get('quantity', None), 'quantity': row.get('quantity', None),
'description': row.get('description', ''), 'description': row.get('description', ''),
'part_name': row.get('part_name', ''),
'part': row.get('part', None), 'part': row.get('part', None),
'reference': row.get('reference', ''), 'reference': row.get('reference', ''),
'notes': row.get('notes', ''), 'notes': row.get('notes', ''),
@ -799,8 +800,9 @@ class BomUpload(FormView):
def preFillSelections(self): def preFillSelections(self):
""" Once data columns have been selected, """ Once data columns have been selected, attempt to pre-select the proper data from the database.
attempt to pre-select the proper data from the database. This function is called once the field selection has been validated.
The pre-fill data are then passed through to the part selection form.
""" """
q_idx = self.getColumnIndex('Quantity') q_idx = self.getColumnIndex('Quantity')
@ -823,13 +825,15 @@ class BomUpload(FormView):
pass pass
if p_idx >= 0: if p_idx >= 0:
p_val = row['data'][p_idx] part_name = row['data'][p_idx]
row['part_name'] = part_name
# Fuzzy match the values and see what happends # Fuzzy match the values and see what happends
matches = [] matches = []
for part in self.allowed_parts: for part in self.allowed_parts:
ratio = fuzz.partial_ratio(part.name + part.description, p_val) ratio = fuzz.partial_ratio(part.name + part.description, part_name)
matches.append({'part': part, 'match': ratio}) matches.append({'part': part, 'match': ratio})
if len(matches) > 0: if len(matches) > 0: