mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Skeletong for exporting BOM in different formats
This commit is contained in:
parent
29f33a8eec
commit
c706f00733
@ -281,40 +281,81 @@ class Part(models.Model):
|
|||||||
# Return the number of supplier parts available for this part
|
# Return the number of supplier parts available for this part
|
||||||
return self.supplier_parts.count()
|
return self.supplier_parts.count()
|
||||||
|
|
||||||
def export_bom(self, file_format='csv'):
|
def export_bom(self, **kwargs):
|
||||||
# TODO - Allow other file formats
|
|
||||||
|
|
||||||
lines = []
|
# Construct the export data
|
||||||
|
|
||||||
# Construct header line
|
|
||||||
header = []
|
header = []
|
||||||
header.append('Part')
|
header.append('Part')
|
||||||
header.append('Description')
|
header.append('Description')
|
||||||
header.append('Quantity')
|
header.append('Quantity')
|
||||||
header.append('Note')
|
header.append('Note')
|
||||||
|
|
||||||
lines.append(header)
|
rows = []
|
||||||
|
|
||||||
for it in self.bom_items.all():
|
for it in self.bom_items.all():
|
||||||
line = []
|
line = []
|
||||||
|
|
||||||
line.append(it.sub_part.name)
|
line.append(it.sub_part.name)
|
||||||
line.append(it.sub_part.description)
|
line.append(it.sub_part.description)
|
||||||
line.append(it.quantity)
|
line.append(it.quantity)
|
||||||
line.append(it.note)
|
line.append(it.note)
|
||||||
|
|
||||||
lines.append([str(x) for x in line])
|
rows.append([str(x) for x in line])
|
||||||
|
|
||||||
|
file_format = kwargs.get('file_format', 'csv').lower()
|
||||||
|
|
||||||
|
kwargs['header'] = header
|
||||||
|
kwargs['rows'] = rows
|
||||||
|
|
||||||
|
if file_format == 'csv':
|
||||||
|
return self.export_bom_csv(**kwargs)
|
||||||
|
elif file_format in ['xls', 'xlsx']:
|
||||||
|
return self.export_bom_xls(**kwargs)
|
||||||
|
elif file_format == 'xml':
|
||||||
|
return self.export_bom_xml(**kwargs)
|
||||||
|
elif file_format in ['htm', 'html']:
|
||||||
|
return self.export_bom_htm(**kwargs)
|
||||||
|
elif file_format == 'pdf':
|
||||||
|
return self.export_bom_pdf(**kwargs)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def export_bom_csv(self, **kwargs):
|
||||||
|
|
||||||
|
# Construct header line
|
||||||
|
header = kwargs.get('header')
|
||||||
|
rows = kwargs.get('rows')
|
||||||
|
|
||||||
# TODO - Choice of formatters goes here?
|
# TODO - Choice of formatters goes here?
|
||||||
out = ''
|
out = ','.join(header)
|
||||||
|
|
||||||
for line in lines:
|
for row in rows:
|
||||||
print(line)
|
|
||||||
out += ','.join(line)
|
|
||||||
out += '\n'
|
out += '\n'
|
||||||
|
out += ','.join(row)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def export_bom_xls(self, **kwargs):
|
||||||
|
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def export_bom_xml(self, **kwargs):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def export_bom_htm(self, **kwargs):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def export_bom_pdf(self, **kwargs):
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@property
|
@property
|
||||||
def projects(self):
|
def projects(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user