From a23595c28db179c764ba43428b2a1f930c276955 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 29 Jun 2019 19:56:04 +1000 Subject: [PATCH] Improve data importing - Automatically prune empty rows - prevent automatic conversion of integers to floats --- InvenTree/part/bom.py | 27 ++++++++++++++++--- .../part/bom_upload/select_fields.html | 1 + InvenTree/part/views.py | 9 +++---- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/InvenTree/part/bom.py b/InvenTree/part/bom.py index 3b6a7fe928..70cea0601b 100644 --- a/InvenTree/part/bom.py +++ b/InvenTree/part/bom.py @@ -121,7 +121,6 @@ class BomUploadManager: return matches[0]['header'] return None - def get_headers(self): """ Return a list of headers for the thingy """ @@ -157,13 +156,33 @@ class BomUploadManager: 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 = { - 'data': self.get_row_data(i), + 'data': data, 'index': i } - if row: - rows.append(row) + rows.append(row) return rows diff --git a/InvenTree/part/templates/part/bom_upload/select_fields.html b/InvenTree/part/templates/part/bom_upload/select_fields.html index ee4a61fc0f..ad90530ad8 100644 --- a/InvenTree/part/templates/part/bom_upload/select_fields.html +++ b/InvenTree/part/templates/part/bom_upload/select_fields.html @@ -44,6 +44,7 @@ + {% for col in bom_cols %}