mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Match each part to the list of available parts
- Order selections based on "best" match
This commit is contained in:
parent
f251620917
commit
a6da3ed4a4
@ -49,12 +49,11 @@
|
|||||||
{% if item.column.guess == 'Part' %}
|
{% if item.column.guess == 'Part' %}
|
||||||
<select class='select bomselect' id='id_part_{{ row.index }}' name='part_select_{{ row.index }}'>
|
<select class='select bomselect' id='id_part_{{ row.index }}' name='part_select_{{ row.index }}'>
|
||||||
<option value=''>---------</option>
|
<option value=''>---------</option>
|
||||||
{% for part in allowed_parts_list %}
|
{% for part in row.part_options %}
|
||||||
<option value='{{ part.id }}'>{{ part.full_name }} - {{ part.description }}</option>
|
<option value='{{ part.id }}'>{{ part.full_name }} - <i>{{ part.description }}</i></option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<br>
|
<i>{{ item.cell }}</i>
|
||||||
{{ item.cell }}
|
|
||||||
{% elif item.column.guess == 'Quantity' %}
|
{% elif item.column.guess == 'Quantity' %}
|
||||||
<input class='numberinput' type='number' min='1' value='{{ row.quantity }}'/>
|
<input class='numberinput' type='number' min='1' value='{{ row.quantity }}'/>
|
||||||
{% elif item.editable %}
|
{% elif item.editable %}
|
||||||
@ -76,6 +75,9 @@
|
|||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
$('.bomselect').select2();
|
$('.bomselect').select2({
|
||||||
|
dropdownAutoWidth: true,
|
||||||
|
matcher: partialMatcher,
|
||||||
|
});
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -14,6 +14,8 @@ from django.views.generic.edit import FormMixin
|
|||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from django.forms import HiddenInput, CheckboxInput
|
from django.forms import HiddenInput, CheckboxInput
|
||||||
|
|
||||||
|
from fuzzywuzzy import fuzz
|
||||||
|
|
||||||
from .models import PartCategory, Part, PartAttachment
|
from .models import PartCategory, Part, PartAttachment
|
||||||
from .models import BomItem
|
from .models import BomItem
|
||||||
from .models import match_part_names
|
from .models import match_part_names
|
||||||
@ -697,6 +699,7 @@ class BomUpload(FormView):
|
|||||||
'index': row.get('index', -1),
|
'index': row.get('index', -1),
|
||||||
'data': data,
|
'data': data,
|
||||||
'quantity': row.get('quantity', None),
|
'quantity': row.get('quantity', None),
|
||||||
|
'part_options': row.get('part_options', [])
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx['part'] = self.part
|
ctx['part'] = self.part
|
||||||
@ -782,21 +785,40 @@ class BomUpload(FormView):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
q_idx = -1
|
q_idx = -1
|
||||||
|
|
||||||
|
try:
|
||||||
|
p_idx = list(self.column_selections.values()).index('Part')
|
||||||
|
except ValueError:
|
||||||
|
p_idx = -1
|
||||||
|
|
||||||
for row in self.bom_rows:
|
for row in self.bom_rows:
|
||||||
|
|
||||||
quantity = 0
|
quantity = 0
|
||||||
|
part = None
|
||||||
|
|
||||||
if q_idx >= 0:
|
if q_idx >= 0:
|
||||||
print(row)
|
|
||||||
q_val = row['data'][q_idx]
|
q_val = row['data'][q_idx]
|
||||||
print("row:", row['index'], "q:", q_val)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
quantity = int(q_val)
|
quantity = int(q_val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if p_idx >= 0:
|
||||||
|
p_val = row['data'][p_idx]
|
||||||
|
|
||||||
|
# Fuzzy match the values and see what happends
|
||||||
|
matches = []
|
||||||
|
|
||||||
|
for part in self.allowed_parts:
|
||||||
|
ratio = fuzz.partial_ratio(part.name + part.description, p_val)
|
||||||
|
matches.append({'part': part, 'match': ratio})
|
||||||
|
|
||||||
|
if len(matches) > 0:
|
||||||
|
matches = sorted(matches, key=lambda item: item['match'], reverse=True)
|
||||||
|
|
||||||
|
row['part'] = part
|
||||||
row['quantity'] = quantity
|
row['quantity'] = quantity
|
||||||
|
row['part_options'] = [m['part'] for m in matches]
|
||||||
|
|
||||||
|
|
||||||
def extractDataFromFile(self, bom):
|
def extractDataFromFile(self, bom):
|
||||||
|
@ -77,6 +77,10 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bomselect {
|
||||||
|
max-width: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Part image icons with full-display on mouse hover */
|
/* Part image icons with full-display on mouse hover */
|
||||||
|
|
||||||
.hover-img-thumb {
|
.hover-img-thumb {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user