Adding post-import adjustments

This commit is contained in:
Ian Roddis committed 2026-07-02 13:12:09 -03:00
1 parent c320595423
commit 87019ff2af
6 files changed
+170 -3

No files matched your search

+45
View File
@@ -32,6 +32,51 @@ from app.models.part_type import PartType
from app.schemas.augmented_part import AugmentedPartSyncResult
async def sync_one(
db: AsyncSession,
*,
inventory_id: str,
part_type_id: int,
sub_part_type_id: int | None,
) -> AugmentedPart:
"""Create an AugmentedPart for a single ImportedPart with manually supplied type."""
ip = await db.get(ImportedPart, inventory_id)
if ip is None:
raise ValueError(f"ImportedPart {inventory_id!r} not found")
description = (ip.Description or "").strip() or ip.InventoryID
colour_name = (ip.TBXColour or "").strip() or "Unknown"
colour = await part_colour_crud.get_by_name(db, colour_name)
if colour is None:
colour = await part_colour_crud.create(db, name=colour_name)
manufacturer = await manufacturer_crud.get_by_name(db, "Armament")
if manufacturer is None:
manufacturer = await manufacturer_crud.create(db, name="Armament", url="")
ap = AugmentedPart(
sku=None,
description=description,
colour_id=colour.id,
manufacturer_id=manufacturer.id,
scope_model_id=None,
part_type_id=part_type_id,
sub_part_type_id=sub_part_type_id,
)
db.add(ap)
await db.flush()
await db.execute(
augmented_part_imported_parts.insert().values(
augmented_part_id=ap.id,
imported_part_id=ip.InventoryID,
)
)
await db.commit()
return ap
def _infer_part_type(description: str, part_types: list[PartType]) -> PartType | None:
"""Return the best-matching PartType or None.