Sort BOM by category, assign BOM IDs
This commit is contained in:
parent
d549c1e460
commit
1d99889175
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum, IntEnum
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
import tabulate as tabulate_module
|
import tabulate as tabulate_module
|
||||||
@ -18,7 +18,7 @@ BomHashList = namedtuple("BomHashList", BOM_HASH_FIELDS)
|
|||||||
PartNumberInfo = namedtuple("PartNumberInfo", "pn manufacturer mpn supplier spn")
|
PartNumberInfo = namedtuple("PartNumberInfo", "pn manufacturer mpn supplier spn")
|
||||||
|
|
||||||
|
|
||||||
BomCategory = Enum(
|
BomCategory = IntEnum( # to enforce ordering in BOM
|
||||||
"BomEntry", "CONNECTOR CABLE WIRE ADDITIONAL_INSIDE ADDITIONAL_OUTSIDE"
|
"BomEntry", "CONNECTOR CABLE WIRE ADDITIONAL_INSIDE ADDITIONAL_OUTSIDE"
|
||||||
)
|
)
|
||||||
QtyMultiplierConnector = Enum(
|
QtyMultiplierConnector = Enum(
|
||||||
@ -65,14 +65,14 @@ def print_bom_debug(bom):
|
|||||||
# fill rows
|
# fill rows
|
||||||
for hash, entry in bom.items():
|
for hash, entry in bom.items():
|
||||||
cells = [
|
cells = [
|
||||||
0,
|
entry["id"],
|
||||||
entry["qty"],
|
entry["qty"],
|
||||||
hash.qty_unit,
|
hash.qty_unit,
|
||||||
hash.description,
|
hash.description,
|
||||||
hash.amount.number if hash.amount else None,
|
hash.amount.number if hash.amount else None,
|
||||||
hash.amount.unit if hash.amount else None,
|
hash.amount.unit if hash.amount else None,
|
||||||
", ".join(sorted(entry["designators"])),
|
", ".join(sorted(entry["designators"])),
|
||||||
entry["category"],
|
f"{entry['category']} ({entry['category'].name})",
|
||||||
]
|
]
|
||||||
rows.append(cells)
|
rows.append(cells)
|
||||||
# remove empty columns
|
# remove empty columns
|
||||||
|
|||||||
@ -499,7 +499,7 @@ class WireClass:
|
|||||||
else:
|
else:
|
||||||
_hash = BomHash(
|
_hash = BomHash(
|
||||||
description=self.description,
|
description=self.description,
|
||||||
qty_unit=1,
|
qty_unit=None,
|
||||||
amount=self.length,
|
amount=self.length,
|
||||||
partnumbers=self.partnumbers,
|
partnumbers=self.partnumbers,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from typing import List
|
|||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
|
|
||||||
import wireviz.wv_colors
|
import wireviz.wv_colors
|
||||||
from wireviz.wv_bom import BomEntry, print_bom_debug
|
from wireviz.wv_bom import BomEntry, print_bom_debug, BomCategory
|
||||||
from wireviz.wv_dataclasses import (
|
from wireviz.wv_dataclasses import (
|
||||||
AUTOGENERATED_PREFIX,
|
AUTOGENERATED_PREFIX,
|
||||||
AdditionalComponent,
|
AdditionalComponent,
|
||||||
@ -90,6 +90,18 @@ class Harness:
|
|||||||
for item in self.additional_bom_items:
|
for item in self.additional_bom_items:
|
||||||
self._add_to_internal_bom(item)
|
self._add_to_internal_bom(item)
|
||||||
|
|
||||||
|
# sort BOM by category first, then alphabetically by description within category
|
||||||
|
self.bom = dict(
|
||||||
|
sorted(
|
||||||
|
self.bom.items(),
|
||||||
|
key=lambda x: (x[1]["category"], x[0].description)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# assign BOM IDs
|
||||||
|
for id, key in enumerate(self.bom.keys(), 1):
|
||||||
|
self.bom[key]["id"] = id
|
||||||
|
|
||||||
print_bom_debug(self.bom)
|
print_bom_debug(self.bom)
|
||||||
|
|
||||||
def _add_to_internal_bom(self, item: Component):
|
def _add_to_internal_bom(self, item: Component):
|
||||||
@ -118,12 +130,12 @@ class Harness:
|
|||||||
|
|
||||||
if isinstance(item, TopLevelGraphicalComponent):
|
if isinstance(item, TopLevelGraphicalComponent):
|
||||||
if isinstance(item, Connector):
|
if isinstance(item, Connector):
|
||||||
cat = "connector"
|
cat = BomCategory.CONNECTOR
|
||||||
elif isinstance(item, Cable):
|
elif isinstance(item, Cable):
|
||||||
if item.category == "bundle":
|
if item.category == "bundle":
|
||||||
cat = "wire"
|
cat = BomCategory.WIRE
|
||||||
else:
|
else:
|
||||||
cat = "cable"
|
cat = BomCategory.CABLE
|
||||||
else:
|
else:
|
||||||
cat = ""
|
cat = ""
|
||||||
|
|
||||||
@ -153,10 +165,10 @@ class Harness:
|
|||||||
hash=comp.bom_hash,
|
hash=comp.bom_hash,
|
||||||
designator=item.designator,
|
designator=item.designator,
|
||||||
qty=comp.bom_qty,
|
qty=comp.bom_qty,
|
||||||
category=f"{cat}_additional",
|
category=BomCategory.ADDITIONAL_INSIDE,
|
||||||
)
|
)
|
||||||
elif isinstance(item, AdditionalComponent):
|
elif isinstance(item, AdditionalComponent):
|
||||||
cat = "additional"
|
cat = BomCategory.ADDITIONAL_OUTSIDE
|
||||||
_add(
|
_add(
|
||||||
hash=item.bom_hash,
|
hash=item.bom_hash,
|
||||||
qty=item.bom_qty,
|
qty=item.bom_qty,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user