mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge remote-tracking branch 'upstream/master' into bom-import-export
This commit is contained in:
commit
7349b396ca
@ -1357,7 +1357,7 @@ class PartParameter(models.Model):
|
||||
class BomItem(models.Model):
|
||||
""" A BomItem links a part to its component items.
|
||||
A part can have a BOM (bill of materials) which defines
|
||||
which parts are required (and in what quatity) to make it.
|
||||
which parts are required (and in what quantity) to make it.
|
||||
|
||||
Attributes:
|
||||
part: Link to the parent part (the part that will be produced)
|
||||
|
@ -62,6 +62,11 @@
|
||||
</button>
|
||||
|
||||
<select class='select bomselect' id='select_part_{{ row.index }}' name='part_{{ row.index }}'>
|
||||
{% if row.part_match %}
|
||||
{% with row.part_match as part %}
|
||||
<option value='{{ part.id }}'{% if part.id == row.part.id %} selected='selected'{% endif %}>{{ part.full_name }} - {{ part.description }}</option>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
<option value=''>---------</option>
|
||||
{% for part in row.part_options %}
|
||||
<option value='{{ part.id }}'{% if part.id == row.part.id %} selected='selected'{% endif %}>{{ part.full_name }} - {{ part.description }}</option>
|
||||
|
@ -847,6 +847,7 @@ class BomUpload(FormView):
|
||||
rows.append({
|
||||
'index': row.get('index', -1),
|
||||
'data': data,
|
||||
'part_match': row.get('part_match', None),
|
||||
'part_options': row.get('part_options', self.allowed_parts),
|
||||
|
||||
# User-input (passed between client and server)
|
||||
@ -949,6 +950,7 @@ class BomUpload(FormView):
|
||||
|
||||
q_idx = self.getColumnIndex('Quantity')
|
||||
p_idx = self.getColumnIndex('Part')
|
||||
i_idx = self.getColumnIndex('IPN')
|
||||
d_idx = self.getColumnIndex('Description')
|
||||
r_idx = self.getColumnIndex('Reference')
|
||||
n_idx = self.getColumnIndex('Notes')
|
||||
@ -971,7 +973,7 @@ class BomUpload(FormView):
|
||||
|
||||
row['part_name'] = part_name
|
||||
|
||||
# Fuzzy match the values and see what happends
|
||||
# Fuzzy match the values and see what happens
|
||||
matches = []
|
||||
|
||||
for part in self.allowed_parts:
|
||||
@ -981,6 +983,9 @@ class BomUpload(FormView):
|
||||
if len(matches) > 0:
|
||||
matches = sorted(matches, key=lambda item: item['match'], reverse=True)
|
||||
|
||||
if i_idx >= 0:
|
||||
row['part_ipn'] = row['data'][i_idx]
|
||||
|
||||
if d_idx >= 0:
|
||||
row['description'] = row['data'][d_idx]
|
||||
|
||||
@ -991,6 +996,32 @@ class BomUpload(FormView):
|
||||
row['notes'] = row['data'][n_idx]
|
||||
|
||||
row['quantity'] = quantity
|
||||
|
||||
# Part selection using IPN
|
||||
try:
|
||||
if row['part_ipn']:
|
||||
part_matches = [part for part in self.allowed_parts if row['part_ipn'] == part.IPN]
|
||||
part_options = [part for part in self.allowed_parts if part not in part_matches]
|
||||
|
||||
# Check for single match
|
||||
if len(part_matches) == 1:
|
||||
row['part_match'] = part_matches[0]
|
||||
|
||||
row['part_options'] = part_options
|
||||
|
||||
continue
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# Part selection using Part Name
|
||||
match_limit = 100
|
||||
part_matches = [m['part'] for m in matches if m['match'] >= match_limit]
|
||||
|
||||
# Check for single match
|
||||
if len(part_matches) == 1:
|
||||
row['part_match'] = part_matches[0]
|
||||
row['part_options'] = [m['part'] for m in matches if m['match'] < match_limit]
|
||||
else:
|
||||
row['part_options'] = [m['part'] for m in matches]
|
||||
|
||||
def extractDataFromFile(self, bom):
|
||||
|
Loading…
Reference in New Issue
Block a user