wv_bom: fix bom columns
This commit is contained in:
parent
720fce3a37
commit
60abe071a2
@ -36,18 +36,18 @@ def partnumbers2list(
|
|||||||
|
|
||||||
def bom_list(bom, restrict_printed_lengths=True, filter_entries=False):
|
def bom_list(bom, restrict_printed_lengths=True, filter_entries=False):
|
||||||
entries_as_dict = []
|
entries_as_dict = []
|
||||||
|
bom_columns = []
|
||||||
|
has_content = set()
|
||||||
# First pass, get all bom dict and identify filled columns
|
# First pass, get all bom dict and identify filled columns
|
||||||
for entry in bom.values():
|
for entry in bom.values():
|
||||||
entry.restrict_printed_lengths = restrict_printed_lengths
|
entry.restrict_printed_lengths = restrict_printed_lengths
|
||||||
entries_as_dict.append(entry.bom_dict)
|
entry_as_dict = entry.bom_dict_pretty_column
|
||||||
|
entries_as_dict.append(entry_as_dict)
|
||||||
has_content = {}
|
for k in entry_as_dict:
|
||||||
bom_columns = list(entries_as_dict[0].keys())
|
if k not in bom_columns:
|
||||||
has_content = {
|
bom_columns.append(k)
|
||||||
k
|
if entry_as_dict[k] is not None and entry_as_dict[k] != "":
|
||||||
for k in bom_columns
|
has_content.add(k)
|
||||||
if any(e[k] for e in entries_as_dict)
|
|
||||||
}
|
|
||||||
|
|
||||||
headers = bom_columns
|
headers = bom_columns
|
||||||
if filter_entries:
|
if filter_entries:
|
||||||
@ -55,7 +55,12 @@ def bom_list(bom, restrict_printed_lengths=True, filter_entries=False):
|
|||||||
|
|
||||||
entries_as_list = []
|
entries_as_list = []
|
||||||
for entry in entries_as_dict:
|
for entry in entries_as_dict:
|
||||||
entries_as_list.append([v for k, v in entry.items() if k in headers])
|
entries_as_list.append([entry.get(k, "") for k in headers])
|
||||||
|
|
||||||
|
# sanity check
|
||||||
|
expected_length = len(entries_as_list[0])
|
||||||
|
for e in entries_as_list:
|
||||||
|
assert len(e) == expected_length, f'entries {e} length is not {expected_length}'
|
||||||
|
|
||||||
table = [headers] + entries_as_list
|
table = [headers] + entries_as_list
|
||||||
|
|
||||||
|
|||||||
@ -342,15 +342,19 @@ class BomEntry:
|
|||||||
if not isinstance(self.qty_multiplier, str):
|
if not isinstance(self.qty_multiplier, str):
|
||||||
self.qty *= float(self.qty_multiplier)
|
self.qty *= float(self.qty_multiplier)
|
||||||
|
|
||||||
|
def restrict_length(data, max_len):
|
||||||
|
return f"{data[:max_len]} ..."
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def description_str(self):
|
def description_str(self):
|
||||||
description = self.description
|
description = self.description
|
||||||
if (
|
if (
|
||||||
self.restrict_printed_lengths
|
not self.restrict_printed_lengths or
|
||||||
and len(description) > self.MAX_PRINTED_DESCRIPTION
|
'href' in description or
|
||||||
|
len(description) < self.MAX_PRINTED_DESCRIPTION
|
||||||
):
|
):
|
||||||
description = f"{description[:self.MAX_PRINTED_DESCRIPTION]} (...)"
|
|
||||||
return description
|
return description
|
||||||
|
return f"{description[:self.MAX_PRINTED_DESCRIPTION]} (...)"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def designators_str(self):
|
def designators_str(self):
|
||||||
@ -406,6 +410,10 @@ class BomEntry:
|
|||||||
return self.partnumbers.BOM_KEY_TO_COLUMNS[key]
|
return self.partnumbers.BOM_KEY_TO_COLUMNS[key]
|
||||||
raise ValueError(f"key '{key}' not found in bom keys")
|
raise ValueError(f"key '{key}' not found in bom keys")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bom_dict_pretty_column(self):
|
||||||
|
return {self.bom_column(k): v for k, v in self.bom_dict.items()}
|
||||||
|
|
||||||
def scale_per_harness(self, qty_multipliers):
|
def scale_per_harness(self, qty_multipliers):
|
||||||
if self.scaled_per_harness:
|
if self.scaled_per_harness:
|
||||||
logging.warn("{self}: Already scaled")
|
logging.warn("{self}: Already scaled")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user