Simplify deduplication and sorting of collected designators
This commit is contained in:
parent
d2f8034961
commit
e1d7babf63
@ -108,10 +108,8 @@ def generate_bom(harness):
|
|||||||
for group_entry in group_entries:
|
for group_entry in group_entries:
|
||||||
d = group_entry.get('designators')
|
d = group_entry.get('designators')
|
||||||
designators.extend(d if isinstance(d, List) else [d] if d else [])
|
designators.extend(d if isinstance(d, List) else [d] if d else [])
|
||||||
designators = list(dict.fromkeys(designators)) # remove duplicates
|
|
||||||
designators.sort()
|
|
||||||
total_qty = sum(entry['qty'] for entry in group_entries)
|
total_qty = sum(entry['qty'] for entry in group_entries)
|
||||||
bom.append({**group_entries[0], 'qty': round(total_qty, 3), 'designators': designators})
|
bom.append({**group_entries[0], 'qty': round(total_qty, 3), 'designators': sorted(set(designators))})
|
||||||
|
|
||||||
bom = sorted(bom, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
bom = sorted(bom, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user