Skip to content

Commit

Permalink
fix 500 error due to no headers, fix part bom export on home page issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkasp committed Oct 26, 2020
1 parent 6af5fea commit 7664686
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bom/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,11 @@ def clean(self):
headers = [h.lower() for h in next(reader)]

# Handle utf-8-sig encoding
if "\ufeff" in headers[0]:
if len(headers) > 0 and "\ufeff" in headers[0]:
reader = csv.reader(codecs.iterdecode(file, 'utf-8-sig'), dialect)
headers = [h.lower() for h in next(reader)]
elif len(headers) == 0:
self.warnings.append("No headers found in CSV file.")

csv_headers = BOMIndentedCSVHeaders()

Expand Down
3 changes: 3 additions & 0 deletions bom/part_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def append_item_and_update(self, item):

def update_bom_for_part(self, bom_part):
if bom_part.do_not_load:
bom_part.order_quantity = 0
bom_part.order_cost = 0
return

if bom_part.seller_part:
Expand Down Expand Up @@ -124,6 +126,7 @@ def extended_cost(self):

def out_of_pocket_cost(self):
try:
print(self.order_quantity, self.seller_part.unit_cost)
return self.order_quantity * self.seller_part.unit_cost
except (AttributeError, TypeError) as err:
logger.log(logging.INFO, '[part_bom.py] ' + str(err))
Expand Down
4 changes: 2 additions & 2 deletions bom/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ def part_export_bom(request, part_id=None, part_revision_id=None, flat=False, so
return HttpResponseRedirect(request.META.get('HTTP_REFERER'), '/')

response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="{}_indabom_parts_indented.csv"'.format(
part.full_part_number())
filename = f'indabom_export_{part.full_part_number()}_{"flat" if flat else "indented"}'
response['Content-Disposition'] = f'attachment; filename="{filename}.csv'

qty_cache_key = str(part_id) + '_qty'
qty = cache.get(qty_cache_key, 1000)
Expand Down

0 comments on commit 7664686

Please sign in to comment.