Fixed the use of component.ref_suffix

This is an string and can be '?' or a number.
This commit is contained in:
Salvador E. Tropea 2020-08-01 14:34:56 -03:00
parent 6c26bd4ec6
commit 107c1c1267
1 changed files with 6 additions and 2 deletions

View File

@ -140,6 +140,10 @@ class Joiner:
return refstr return refstr
def _suffix_to_num(suffix):
return 0 if suffix == '?' else int(suffix)
class ComponentGroup(object): class ComponentGroup(object):
""" A row in the BoM """ """ A row in the BoM """
def __init__(self, cfg): def __init__(self, cfg):
@ -193,7 +197,7 @@ class ComponentGroup(object):
def sort_components(self): def sort_components(self):
""" Sort the components in correct order (by reference). """ Sort the components in correct order (by reference).
First priority is the prefix, second the number (as integer) """ First priority is the prefix, second the number (as integer) """
self.components = sorted(self.components, key=lambda c: [c.ref_prefix, int(c.ref_suffix)]) self.components = sorted(self.components, key=lambda c: [c.ref_prefix, _suffix_to_num(c.ref_suffix)])
def get_refs(self): def get_refs(self):
""" Return a list of the components """ """ Return a list of the components """
@ -203,7 +207,7 @@ class ComponentGroup(object):
""" Alternative list of references using ranges """ """ Alternative list of references using ranges """
S = Joiner() S = Joiner()
for n in self.components: for n in self.components:
P, N = (n.ref_prefix, n.ref_suffix) P, N = (n.ref_prefix, _suffix_to_num(n.ref_suffix))
S.add(P, N) S.add(P, N)
return S.flush(' ') return S.flush(' ')