Swaped internal and public bom field names to the shorter names.
Also update BOM header generation to support specific headers for fields were capitalize produces unwanted output.
This commit is contained in:
parent
1f94298af6
commit
89bd88d9d6
@ -349,7 +349,7 @@ class Harness:
|
||||
conn_color = f', {shared.color}' if shared.color else ''
|
||||
name = f'Connector{conn_type}{conn_subtype}{conn_pincount}{conn_color}'
|
||||
item = {'item': name, 'qty': len(designators), 'unit': '', 'designators': designators if shared.show_name else '',
|
||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.mpn, 'part number': shared.pn}
|
||||
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||
bom_connectors.append(item)
|
||||
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
||||
bom.extend(bom_connectors)
|
||||
@ -368,7 +368,7 @@ class Harness:
|
||||
shield_name = ' shielded' if shared.shield else ''
|
||||
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}'
|
||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.mpn, 'part number': shared.pn}
|
||||
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||
bom_cables.append(item)
|
||||
# bundles (ignores wirecount)
|
||||
wirelist = []
|
||||
@ -379,10 +379,10 @@ class Harness:
|
||||
for index, color in enumerate(bundle.colors, 0):
|
||||
wirelist.append({'type': bundle.type, 'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name,
|
||||
'manufacturer': index_if_list(bundle.manufacturer, index),
|
||||
'manufacturer part number': index_if_list(bundle.mpn, index),
|
||||
'part number': index_if_list(bundle.pn, index)})
|
||||
'mpn': index_if_list(bundle.mpn, index),
|
||||
'pn': index_if_list(bundle.pn, index)})
|
||||
# join similar wires from all the bundles to a single BOM item
|
||||
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['manufacturer part number'], w['part number'])
|
||||
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['mpn'], w['pn'])
|
||||
for group in Counter([wire_group(v) for v in wirelist]):
|
||||
items = [v for v in wirelist if wire_group(v) == group]
|
||||
shared = items[0]
|
||||
@ -395,7 +395,7 @@ class Harness:
|
||||
gauge_color = f', {shared["color"]}' if 'color' in shared != '' else ''
|
||||
name = f'Wire{wire_type}{gauge_name}{gauge_color}'
|
||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||
'manufacturer': shared['manufacturer'], 'manufacturer part number': shared['manufacturer part number'], 'part number': shared['part number']}
|
||||
'manufacturer': shared['manufacturer'], 'mpn': shared['mpn'], 'pn': shared['pn']}
|
||||
bom_cables.append(item)
|
||||
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||
bom.extend(bom_cables)
|
||||
@ -405,7 +405,7 @@ class Harness:
|
||||
if isinstance(item.get('designators', None), List):
|
||||
item['designators'].sort() # sort designators if a list is provided
|
||||
item = {'item': name, 'qty': item.get('qty', None), 'unit': item.get('unit', None), 'designators': item.get('designators', None),
|
||||
'manufacturer': item.get('manufacturer', None), 'manufacturer part number': item.get('mpn', None), 'part number': item.get('pn', None)}
|
||||
'manufacturer': item.get('manufacturer', None), 'mpn': item.get('mpn', None), 'pn': item.get('pn', None)}
|
||||
bom_extra.append(item)
|
||||
bom_extra = sorted(bom_extra, key=lambda k: k['item'])
|
||||
bom.extend(bom_extra)
|
||||
@ -414,11 +414,16 @@ class Harness:
|
||||
def bom_list(self):
|
||||
bom = self.bom()
|
||||
keys = ['item', 'qty', 'unit', 'designators'] # these BOM columns will always be included
|
||||
for fieldname in ['part number', 'manufacturer', 'manufacturer part number']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
||||
for fieldname in ['pn', 'manufacturer', 'mpn']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
||||
if any(fieldname in x and x.get(fieldname, None) for x in bom):
|
||||
keys.append(fieldname)
|
||||
bom_list = []
|
||||
bom_list.append([k.capitalize() for k in keys]) # create header row with keys
|
||||
# list of staic bom header names, headers not specified here are generated by capitilising the internal name
|
||||
bom_headings = {
|
||||
"pn": "P/N",
|
||||
"mpn": "MPN"
|
||||
}
|
||||
bom_list.append([(bom_headings[k] if k in bom_headings else k.capitalize()) for k in keys]) # create header row with keys
|
||||
for item in bom:
|
||||
item_list = [item.get(key, '') for key in keys] # fill missing values with blanks
|
||||
item_list = [', '.join(subitem) if isinstance(subitem, List) else subitem for subitem in item_list] # convert any lists into comma separated strings
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user