aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ee/digikey/bom.py19
-rw-r--r--src/ee/part/bom.py41
-rw-r--r--src/ee/tools/digikey_create_bom.py4
3 files changed, 38 insertions, 26 deletions
diff --git a/src/ee/digikey/bom.py b/src/ee/digikey/bom.py
index 398e03b..cb02f05 100644
--- a/src/ee/digikey/bom.py
+++ b/src/ee/digikey/bom.py
@@ -1,4 +1,5 @@
import csv
+from math import ceil
from pathlib import Path
from typing import List
@@ -7,18 +8,22 @@ from ee.part.bom import load_bom, check_bom, generate_bom, join_refs
__all__ = ["create_bom"]
-def create_bom(bom_path: Path, part_files: List[Path], out_path: Path, allow_incomplete):
+def create_bom(bom_path: Path, part_files: List[Path], out_path: Path, allow_incomplete, quantity: float):
bom_parts, supplier_parts = load_bom(bom_path, part_files)
check_bom(bom_parts, supplier_parts)
- lines = generate_bom(allow_incomplete, bom_parts, supplier_parts)
+ bom = generate_bom(allow_incomplete, bom_parts, supplier_parts)
- if lines is None:
+ if bom is None:
return
with out_path.open("w") as f:
w = csv.writer(f)
- w.writerow(["Quantity", "Digi-Key Part Number", "Customer Reference"])
-
- for line in lines:
- w.writerows([str(len(line.refs)), line.part.get_exactly_one_spn().valueProp, join_refs(line.refs)])
+ w.writerow(["Digi-Key Part Number", "Quantity", "Reference Designator"])
+
+ for line in bom.lines:
+ line = [
+ line.part.get_exactly_one_spn().valueProp,
+ int(ceil(len(line.refs) * quantity)),
+ join_refs(line.refs)]
+ w.writerow([str(cell) for cell in line])
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):
diff --git a/src/ee/tools/digikey_create_bom.py b/src/ee/tools/digikey_create_bom.py
index eaea121..ed32578 100644
--- a/src/ee/tools/digikey_create_bom.py
+++ b/src/ee/tools/digikey_create_bom.py
@@ -23,7 +23,9 @@ parser.add_argument("--part-db",
parser.add_argument("--allow-incomplete",
action="store_true")
+parser.add_argument("--quantity", default=1, type=float)
+
args = parser.parse_args()
ee.tools.process_default_argparse_group(args)
-create_bom(Path(args.bom), [Path(p) for p in args.part_db], Path(args.out), args.allow_incomplete)
+create_bom(Path(args.bom), [Path(p) for p in args.part_db], Path(args.out), args.allow_incomplete, args.quantity)