mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Improve data importing
- Automatically prune empty rows - prevent automatic conversion of integers to floats
This commit is contained in:
parent
b089a61f74
commit
a23595c28d
@ -121,7 +121,6 @@ class BomUploadManager:
|
|||||||
return matches[0]['header']
|
return matches[0]['header']
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_headers(self):
|
def get_headers(self):
|
||||||
""" Return a list of headers for the thingy """
|
""" Return a list of headers for the thingy """
|
||||||
@ -157,13 +156,33 @@ class BomUploadManager:
|
|||||||
|
|
||||||
for i in range(self.row_count()):
|
for i in range(self.row_count()):
|
||||||
|
|
||||||
|
data = [item for item in self.get_row_data(i)]
|
||||||
|
|
||||||
|
# Is the row completely empty? Skip!
|
||||||
|
empty = True
|
||||||
|
|
||||||
|
for idx, item in enumerate(data):
|
||||||
|
if len(str(item).strip()) > 0:
|
||||||
|
empty = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Excel import casts number-looking-items into floats, which is annoying
|
||||||
|
if item == int(item) and not str(item) == str(int(item)):
|
||||||
|
print("converting", item, "to", int(item))
|
||||||
|
data[idx] = int(item)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if empty:
|
||||||
|
print("Empty - continuing")
|
||||||
|
continue
|
||||||
|
|
||||||
row = {
|
row = {
|
||||||
'data': self.get_row_data(i),
|
'data': data,
|
||||||
'index': i
|
'index': i
|
||||||
}
|
}
|
||||||
|
|
||||||
if row:
|
rows.append(row)
|
||||||
rows.append(row)
|
|
||||||
|
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td></td>
|
||||||
{% for col in bom_cols %}
|
{% for col in bom_cols %}
|
||||||
<td>
|
<td>
|
||||||
<select class='select' id='id_col_{{ forloop.counter0 }}' name='col_select_{{ forloop.counter0 }}'>
|
<select class='select' id='id_col_{{ forloop.counter0 }}' name='col_select_{{ forloop.counter0 }}'>
|
||||||
|
@ -520,7 +520,6 @@ class PartDetail(DetailView):
|
|||||||
else:
|
else:
|
||||||
context['editing_enabled'] = 0
|
context['editing_enabled'] = 0
|
||||||
|
|
||||||
|
|
||||||
context['starred'] = part.isStarredBy(self.request.user)
|
context['starred'] = part.isStarredBy(self.request.user)
|
||||||
context['disabled'] = not part.active
|
context['disabled'] = not part.active
|
||||||
|
|
||||||
@ -744,7 +743,7 @@ class BomUpload(AjaxView, FormMixin):
|
|||||||
|
|
||||||
self.ajax_template_name = 'part/bom_upload/select_fields.html'
|
self.ajax_template_name = 'part/bom_upload/select_fields.html'
|
||||||
|
|
||||||
# Map the columns
|
# Map the columns
|
||||||
column_names = {}
|
column_names = {}
|
||||||
column_selections = {}
|
column_selections = {}
|
||||||
|
|
||||||
@ -780,7 +779,7 @@ class BomUpload(AjaxView, FormMixin):
|
|||||||
row_id = int(s[1])
|
row_id = int(s[1])
|
||||||
col_id = int(s[3])
|
col_id = int(s[3])
|
||||||
|
|
||||||
if not row_id in row_data:
|
if row_id not in row_data:
|
||||||
row_data[row_id] = {}
|
row_data[row_id] = {}
|
||||||
|
|
||||||
row_data[row_id][col_id] = value
|
row_data[row_id][col_id] = value
|
||||||
@ -812,7 +811,7 @@ class BomUpload(AjaxView, FormMixin):
|
|||||||
missing = []
|
missing = []
|
||||||
|
|
||||||
for col in BomUploadManager.REQUIRED_HEADERS:
|
for col in BomUploadManager.REQUIRED_HEADERS:
|
||||||
if not col in column_selections.values():
|
if col not in column_selections.values():
|
||||||
missing.append(col)
|
missing.append(col)
|
||||||
|
|
||||||
# Re-construct the data table
|
# Re-construct the data table
|
||||||
@ -823,7 +822,7 @@ class BomUpload(AjaxView, FormMixin):
|
|||||||
items = []
|
items = []
|
||||||
for col_idx in sorted(row.keys()):
|
for col_idx in sorted(row.keys()):
|
||||||
|
|
||||||
if not col_idx in column_selections.keys():
|
if col_idx not in column_selections.keys():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
value = row[col_idx]
|
value = row[col_idx]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user