mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Move the export_bom function to the part model
This commit is contained in:
parent
b8e28c003d
commit
9e5eed5d5e
@ -278,6 +278,38 @@ class Part(models.Model):
|
||||
# Return the number of supplier parts available for this part
|
||||
return self.supplier_parts.count()
|
||||
|
||||
def export_bom(self, file_format='csv'):
|
||||
# TODO - Allow other file formats
|
||||
|
||||
lines = []
|
||||
|
||||
# Construct header line
|
||||
header = []
|
||||
header.append('Part')
|
||||
header.append('Description')
|
||||
header.append('Quantity')
|
||||
|
||||
lines.append(header)
|
||||
|
||||
for it in self.bom_items.all():
|
||||
line = []
|
||||
|
||||
line.append(it.sub_part.name)
|
||||
line.append(it.sub_part.description)
|
||||
line.append(it.quantity)
|
||||
|
||||
lines.append([str(x) for x in line])
|
||||
|
||||
# TODO - Choice of formatters goes here?
|
||||
out = ''
|
||||
|
||||
for line in lines:
|
||||
print(line)
|
||||
out += ','.join(line)
|
||||
out += '\n'
|
||||
|
||||
return out
|
||||
|
||||
"""
|
||||
@property
|
||||
def projects(self):
|
||||
|
@ -131,15 +131,7 @@ class BomExport(AjaxView):
|
||||
# Placeholder to test file export
|
||||
filename = '"' + part.name + '_BOM.' + export_format + '"'
|
||||
|
||||
filedata = "Part,Quantity,Available\n"
|
||||
|
||||
for bom_item in part.bom_items.all():
|
||||
filedata += bom_item.sub_part.name
|
||||
filedata += ","
|
||||
filedata += str(bom_item.quantity)
|
||||
filedata += ","
|
||||
filedata += str(bom_item.sub_part.available_stock)
|
||||
filedata += "\n"
|
||||
filedata = part.export_bom()
|
||||
|
||||
return DownloadFile(filedata, filename)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user