aboutsummaryrefslogtreecommitdiff
path: root/src/ee/digikey
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/digikey
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/digikey')
-rw-r--r--src/ee/digikey/bom.py19
1 files changed, 12 insertions, 7 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])