aboutsummaryrefslogtreecommitdiff
path: root/src/ee/part
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-08-23 13:13:06 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-08-23 13:14:53 +0200
commit9ebdc35df067d63297376814f0bba981246fa44f (patch)
tree225dc4461ea800c0c5dfc8b486915799b3e88f7a /src/ee/part
parent6b7c6e96c727d8f1885b0653cdcbc21730eaf3cb (diff)
downloadee-python-9ebdc35df067d63297376814f0bba981246fa44f.tar.gz
ee-python-9ebdc35df067d63297376814f0bba981246fa44f.tar.bz2
ee-python-9ebdc35df067d63297376814f0bba981246fa44f.tar.xz
ee-python-9ebdc35df067d63297376814f0bba981246fa44f.zip
ee.part.bom: Creating a proper Bom class to keep BomLines.
digikey-create-bom: Adding support for --quantity.
Diffstat (limited to 'src/ee/part')
-rw-r--r--src/ee/part/bom.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/ee/part/bom.py b/src/ee/part/bom.py
index 0bf284a..fe0bb12 100644
--- a/src/ee/part/bom.py
+++ b/src/ee/part/bom.py
@@ -25,19 +25,30 @@ class BomLine(object):
def __init__(self, uri, part: Part):
self.uri = uri
self.part = part
- self.refs = []
+ self.refs: List[str] = []
- def add_ref(self, ref):
+ def add_ref(self, ref: str):
self.refs.append(ref)
def __lt__(self, other):
return self.uri < other.uri
-class BomItem(object):
- def __init__(self, references, part: Part):
- self.references = references
- self.part = part
+class Bom(object):
+ def __init__(self):
+ self._lines: MutableMapping[str, BomLine] = {}
+
+ def add_part(self, part_uri, supplier_part, reference):
+ if part_uri not in self._lines:
+ self._lines[part_uri] = line = BomLine(part_uri, supplier_part)
+ else:
+ line = self._lines[part_uri]
+
+ line.add_ref(reference)
+
+ @property
+ def lines(self) -> List[BomLine]:
+ return sorted(self._lines.values())
def load_bom(bom_path: Path, part_files: List[Path]) -> (ObjDb[Part](), ObjDb[Part]()):
@@ -67,12 +78,10 @@ def check_bom(bom: ObjDb[Part](), parts: ObjDb[Part]()):
pass
-def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb[Part], group_by_ref=True) -> \
- Optional[List[BomLine]]:
- lines: MutableMapping[str, BomLine] = {}
-
+def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb[Part]) -> Optional[Bom]:
uri_idx = supplier_parts.index("uri")
+ bom = Bom()
for part in bom_parts.values:
pr = part.get_only_part_reference()
@@ -85,15 +94,11 @@ def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb
part_uri = pr.part_uriProp
- if part_uri not in lines:
- supplier_part = uri_idx.get_single(part_uri)
- lines[part_uri] = line = BomLine(part_uri, supplier_part)
- else:
- line = lines[part_uri]
-
- line.add_ref(part.get_exactly_one_schematic_reference().referenceProp)
+ supplier_part = uri_idx.get_single(part_uri)
+ reference = part.get_exactly_one_schematic_reference().referenceProp
+ bom.add_part(part_uri, supplier_part, reference)
- return sorted(lines.values())
+ return bom
def split_ref(ref):