From 9ebdc35df067d63297376814f0bba981246fa44f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Aug 2019 13:13:06 +0200 Subject: ee.part.bom: Creating a proper Bom class to keep BomLines. digikey-create-bom: Adding support for --quantity. --- src/ee/digikey/bom.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/ee/digikey') 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]) -- cgit v1.2.3