Added `extra_info_display` to the Specs.

This commit is contained in:
Salvador E. Tropea 2021-10-27 15:58:33 -03:00
parent ccfb6ce734
commit 103a338ece
4 changed files with 32 additions and 7 deletions

View File

@ -745,6 +745,7 @@ Next time you need this list just use an alias, like this:
- `kicost`: [boolean=false] Enable KiCost worksheet creation.
- `kicost_api_disable`: [string|list(string)=''] List of KiCost APIs to disable.
- `kicost_api_enable`: [string|list(string)=''] List of KiCost APIs to enable.
- `kicost_dist_desc`: [boolean=false] Used to add a column with the distributor's description. So you can chek this is the right component.
- `logo`: [string|boolean=''] PNG file to use as logo, use false to remove.
- `logo_scale`: [number=2] Scaling factor for the logo. Note that this value isn't honored by all spreadsheet software.
- `max_col_width`: [number=60] [20,999] Maximum column width (characters).
@ -752,6 +753,8 @@ Next time you need this list just use an alias, like this:
Works with only some KiCost APIs.
- `specs_columns`: [list(dict)|list(string)] Which columns are included in the Specs worksheet. Use `References` for the references,
'Row' for the order and 'Sep' to separate groups at the same level. By default all are included.
Column names are distributor specific, the following aren't: '_desc', '_value', '_tolerance', '_footprint',
'_power', '_current', '_voltage', '_frequency', '_temp_coeff', '_manf', '_size'.
* Valid keys:
- `comment`: [string=''] Used as explanation for this column. The XLSX output uses it.
- `field`: [string=''] Name of the field to use for this column.

View File

@ -216,6 +216,8 @@ outputs:
kicost_api_disable: ''
# [string|list(string)=''] List of KiCost APIs to enable
kicost_api_enable: ''
# [boolean=false] Used to add a column with the distributor's description. So you can chek this is the right component
kicost_dist_desc: false
# [string|boolean=''] PNG file to use as logo, use false to remove
logo: ''
# [number=2] Scaling factor for the logo. Note that this value isn't honored by all spreadsheet software
@ -226,7 +228,9 @@ outputs:
# Works with only some KiCost APIs
specs: false
# [list(dict)|list(string)] Which columns are included in the Specs worksheet. Use `References` for the references,
# 'Row' for the order and 'Sep' to separate groups at the same level. By default all are included
# 'Row' for the order and 'Sep' to separate groups at the same level. By default all are included.
# Column names are distributor specific, the following aren't: '_desc', '_value', '_tolerance', '_footprint',
# '_power', '_current', '_voltage', '_frequency', '_temp_coeff', '_manf', '_size'
specs_columns:
# [string=''] Used as explanation for this column. The XLSX output uses it
- comment: ''

View File

@ -248,6 +248,17 @@ def create_color_ref(workbook, col_colors, hl_empty, fmt_cols, do_kicost, kicost
worksheet.write_string(row, 0, label, format)
def get_spec(part, name):
if name[0] != '_':
return part.specs.get(name, ['', ''])
name = name[1:]
for k, v in part.dd.items():
val = v.extra_info.get(name, None)
if val:
return [name, val]
return ['', '']
def create_meta(workbook, name, columns, parts, fmt_head, fmt_cols, max_w, rename, levels, comments, join):
worksheet = workbook.add_worksheet(name)
col_w = []
@ -274,7 +285,7 @@ def create_meta(workbook, name, columns, parts, fmt_head, fmt_cols, max_w, renam
if col_l == 'sep':
col_w[c] = 0
continue
v = part.specs.get(col_l, ['', ''])
v = get_spec(part, col_l)
text = v[1]
# Append text from other fields
if join:
@ -474,7 +485,7 @@ def compute_qtys(cfg, g):
return [str(g.get_count(sch.name)) for sch in cfg.aggregate]
def create_meta_sheets(workbook, used_parts, fmt_head, fmt_cols, cfg):
def create_meta_sheets(workbook, used_parts, fmt_head, fmt_cols, cfg, ss):
if cfg.xlsx.specs:
meta_names = ['Specs', 'Specs (DNF)']
for ws in range(2):
@ -500,8 +511,9 @@ def create_meta_sheets(workbook, used_parts, fmt_head, fmt_cols, cfg):
# Inform about missing columns
for c in columns:
col = c.lower()
if col not in spec_cols_l and col not in SPECS_GENERATED:
logger.warning(W_BADFIELD+'Invalid Specs column name `{}`'.format(c))
if ((col[0] == '_' and col[1:] not in ss.extra_info_display) or
(col[0] != '_' and col not in spec_cols_l and col not in SPECS_GENERATED)):
logger.warning(W_BADFIELD+'Invalid Specs column name `{}` {}'.format(c, col[1:]))
create_meta(workbook, meta_names[ws], columns, parts, fmt_head, fmt_cols, cfg.xlsx.max_col_width,
cfg.xlsx.s_rename, cfg.xlsx.s_levels, cfg.xlsx.s_comments, cfg.xlsx.s_join)
@ -632,7 +644,7 @@ def _create_kicost_sheet(workbook, groups, image_data, fmt_title, fmt_info, fmt_
wks.merge_range(0, col1, 0, ss.globals_width, cfg.xlsx.title, fmt_title)
used_parts.append(parts)
# Specs sheets
create_meta_sheets(workbook, used_parts, fmt_head, fmt_cols, cfg)
create_meta_sheets(workbook, used_parts, fmt_head, fmt_cols, cfg, ss)
colors = {}
colors['Best price'] = ss.wrk_formats['best_price']
colors['No manufacturer or distributor code'] = ss.wrk_formats['not_manf_codes']

View File

@ -174,7 +174,9 @@ class BoMXLSX(BoMLinkable):
Works with only some KiCost APIs """
self.specs_columns = BoMColumns
""" [list(dict)|list(string)] Which columns are included in the Specs worksheet. Use `References` for the references,
'Row' for the order and 'Sep' to separate groups at the same level. By default all are included """
'Row' for the order and 'Sep' to separate groups at the same level. By default all are included.
Column names are distributor specific, the following aren't: '_desc', '_value', '_tolerance', '_footprint',
'_power', '_current', '_voltage', '_frequency', '_temp_coeff', '_manf', '_size' """
self.logo_scale = 2
""" Scaling factor for the logo. Note that this value isn't honored by all spreadsheet software """
@ -194,6 +196,8 @@ class BoMXLSX(BoMLinkable):
new_col_l = new_col.lower()
level = 0
comment = ''
if new_col_l[0] == '_':
column_rename[new_col_l] = new_col_l[1:].capitalize()
else:
# A complete entry
new_col = col.field
@ -201,6 +205,8 @@ class BoMXLSX(BoMLinkable):
# A column rename
if col.name:
column_rename[new_col_l] = col.name
elif new_col_l[0] == '_':
column_rename[new_col_l] = new_col_l[1:].capitalize()
# Attach other columns
if col.join:
join.append(col.join)