Remove brackets arround if statements and shorten bom dict opperatiions
This commit is contained in:
parent
b7f184e79c
commit
715fe36116
@ -202,7 +202,7 @@ class Harness:
|
|||||||
wirehtml.append(' </table>')
|
wirehtml.append(' </table>')
|
||||||
wirehtml.append(' </td>')
|
wirehtml.append(' </td>')
|
||||||
wirehtml.append(' </tr>')
|
wirehtml.append(' </tr>')
|
||||||
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
if cable.category == 'bundle': # for bundles individual wires can have part information
|
||||||
# create a list of wire parameters
|
# create a list of wire parameters
|
||||||
wireidentification = []
|
wireidentification = []
|
||||||
if isinstance(cable.pn, list):
|
if isinstance(cable.pn, list):
|
||||||
@ -213,7 +213,7 @@ class Harness:
|
|||||||
if manufacturer_info:
|
if manufacturer_info:
|
||||||
wireidentification.append(html_line_breaks(manufacturer_info))
|
wireidentification.append(html_line_breaks(manufacturer_info))
|
||||||
# print parameters into a table row under the wire
|
# print parameters into a table row under the wire
|
||||||
if(len(wireidentification) > 0):
|
if len(wireidentification) > 0 :
|
||||||
wirehtml.append(' <tr><td colspan="3">')
|
wirehtml.append(' <tr><td colspan="3">')
|
||||||
wirehtml.append(' <table border="0" cellspacing="0" cellborder="0"><tr>')
|
wirehtml.append(' <table border="0" cellspacing="0" cellborder="0"><tr>')
|
||||||
for attrib in wireidentification:
|
for attrib in wireidentification:
|
||||||
@ -341,7 +341,7 @@ class Harness:
|
|||||||
rows.append(["Additional components"])
|
rows.append(["Additional components"])
|
||||||
for extra in component.additional_components:
|
for extra in component.additional_components:
|
||||||
qty = extra.qty * component.get_qty_multiplier(extra.qty_multiplier)
|
qty = extra.qty * component.get_qty_multiplier(extra.qty_multiplier)
|
||||||
if(self.mini_bom_mode):
|
if self.mini_bom_mode:
|
||||||
id = self.get_bom_index(extra.description, extra.unit, extra.manufacturer, extra.mpn, extra.pn)
|
id = self.get_bom_index(extra.description, extra.unit, extra.manufacturer, extra.mpn, extra.pn)
|
||||||
rows.append(component_table_entry(f'#{id} ({extra.type.capitalize()})', qty, extra.unit))
|
rows.append(component_table_entry(f'#{id} ({extra.type.capitalize()})', qty, extra.unit))
|
||||||
else:
|
else:
|
||||||
@ -352,17 +352,15 @@ class Harness:
|
|||||||
bom_entries = []
|
bom_entries = []
|
||||||
for part in component.additional_components:
|
for part in component.additional_components:
|
||||||
qty = part.qty * component.get_qty_multiplier(part.qty_multiplier)
|
qty = part.qty * component.get_qty_multiplier(part.qty_multiplier)
|
||||||
bom_entries.append(
|
bom_entries.append({
|
||||||
{
|
'item': part.description,
|
||||||
'item': part.description,
|
'qty': qty,
|
||||||
'qty': qty,
|
'unit': part.unit,
|
||||||
'unit': part.unit,
|
'manufacturer': part.manufacturer,
|
||||||
'manufacturer': part.manufacturer,
|
'mpn': part.mpn,
|
||||||
'mpn': part.mpn,
|
'pn': part.pn,
|
||||||
'pn': part.pn,
|
'designators': component.name if component.show_name else None
|
||||||
'designators': component.name if component.show_name else None
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
return(bom_entries)
|
return(bom_entries)
|
||||||
|
|
||||||
def bom(self):
|
def bom(self):
|
||||||
@ -428,7 +426,6 @@ class Harness:
|
|||||||
bom_types_group = lambda bt: (bt['item'], bt['unit'], bt['manufacturer'], bt['mpn'], bt['pn'])
|
bom_types_group = lambda bt: (bt['item'], bt['unit'], bt['manufacturer'], bt['mpn'], bt['pn'])
|
||||||
for group in Counter([bom_types_group(v) for v in bom_entries]):
|
for group in Counter([bom_types_group(v) for v in bom_entries]):
|
||||||
group_entries = [v for v in bom_entries if bom_types_group(v) == group]
|
group_entries = [v for v in bom_entries if bom_types_group(v) == group]
|
||||||
shared = group_entries[0]
|
|
||||||
designators = []
|
designators = []
|
||||||
for group_entry in group_entries:
|
for group_entry in group_entries:
|
||||||
if group_entry.get('designators'):
|
if group_entry.get('designators'):
|
||||||
@ -438,24 +435,19 @@ class Harness:
|
|||||||
designators.append(group_entry['designators'])
|
designators.append(group_entry['designators'])
|
||||||
designators = list(dict.fromkeys(designators)) # remove duplicates
|
designators = list(dict.fromkeys(designators)) # remove duplicates
|
||||||
designators.sort()
|
designators.sort()
|
||||||
total_qty = sum(i['qty'] for i in group_entries)
|
total_qty = sum(entry['qty'] for entry in group_entries)
|
||||||
self._bom.append({
|
self._bom.append({**group_entries[0], 'qty': round(total_qty, 3), 'designators': designators})
|
||||||
'item': shared['item'], 'qty': round(total_qty, 3), 'unit': shared['unit'], 'designators': designators,
|
|
||||||
'manufacturer': shared['manufacturer'], 'mpn': shared['mpn'], 'pn': shared['pn']
|
|
||||||
})
|
|
||||||
|
|
||||||
self._bom = sorted(self._bom, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
self._bom = sorted(self._bom, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||||
# add index
|
|
||||||
index = 1
|
# add an incrementing id to each bom item
|
||||||
for item in self._bom:
|
self._bom = [{**entry, 'id': index} for index, entry in enumerate(self._bom, 1)]
|
||||||
item["id"] = index
|
|
||||||
index += 1
|
|
||||||
return self._bom
|
return self._bom
|
||||||
|
|
||||||
def get_bom_index(self, item, unit, manufacturer, mpn, pn):
|
def get_bom_index(self, item, unit, manufacturer, mpn, pn):
|
||||||
for bom_item in self.bom():
|
for entry in self.bom():
|
||||||
if((bom_item['item'], bom_item['unit'], bom_item['manufacturer'], bom_item['mpn'], bom_item['pn']) == (item, unit, manufacturer, mpn, pn)):
|
if(entry['item'], entry['unit'], entry['manufacturer'], entry['mpn'], entry['pn']) == (item, unit, manufacturer, mpn, pn):
|
||||||
return bom_item['id']
|
return entry['id']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def bom_list(self):
|
def bom_list(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user