From ea4906c9a583a01b5904dfd0b19545670371d09a Mon Sep 17 00:00:00 2001 From: "Jeremy Ruhland (hatchery)" Date: Sun, 11 Dec 2022 18:19:38 -0800 Subject: [PATCH 1/3] Add unpopulated option to additional components qty multiplier --- docs/syntax.md | 1 + src/wireviz/DataClasses.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/syntax.md b/docs/syntax.md index 39e56aba..de672847 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -408,6 +408,7 @@ Parts can be added to a connector or cable in the section ` i return self.pincount elif qty_multiplier == "populated": return sum(self.visible_pins.values()) + elif qty_multiplier == 'unpopulated': + return (self.pincount - sum(self.visible_pins.values())) else: raise ValueError( f"invalid qty multiplier parameter for connector {qty_multiplier}" From 42c89ca6661a742b86a16ab8a855444d444eb99f Mon Sep 17 00:00:00 2001 From: "Jeremy Ruhland (hatchery)" Date: Sun, 11 Dec 2022 23:59:32 -0800 Subject: [PATCH 2/3] Hide qty 0 additional components from BOM --- src/wireviz/wv_bom.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 6689d79a..a233eca8 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -35,7 +35,8 @@ def get_additional_component_table( rows = [] if component.additional_components: rows.append(["Additional components"]) - for part in component.additional_components: + # Ignore components that have qty 0 + for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]: common_args = { "qty": part.qty * component.get_qty_multiplier(part.qty_multiplier), "unit": part.unit, @@ -63,7 +64,8 @@ def get_additional_component_table( def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]: """Return a list of BOM entries with additional components.""" bom_entries = [] - for part in component.additional_components: + # Ignore components that have qty 0 + for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]: bom_entries.append( { "description": part.description, From 24e02f5cfd2cd2d2f68b78e12e75617d0cec70a0 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 16 Apr 2024 13:43:31 +0200 Subject: [PATCH 3/3] Do not allow negative `qty_multiplier` Co-authored-by: kvid --- src/wireviz/DataClasses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 47bffc83..1980e1b3 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -233,7 +233,7 @@ def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> i elif qty_multiplier == "populated": return sum(self.visible_pins.values()) elif qty_multiplier == 'unpopulated': - return (self.pincount - sum(self.visible_pins.values())) + return max(0, self.pincount - sum(self.visible_pins.values())) else: raise ValueError( f"invalid qty multiplier parameter for connector {qty_multiplier}"