diff --git a/app/crud/augmented_part.py b/app/crud/augmented_part.py index 5e72984..0faa807 100644 --- a/app/crud/augmented_part.py +++ b/app/crud/augmented_part.py @@ -57,9 +57,14 @@ async def get_by_sku(db: AsyncSession, sku: str) -> AugmentedPart | None: return result.scalars().first() -async def list_all(db: AsyncSession, skip: int = 0, limit: int = 100) -> list[AugmentedPart]: +async def list_all( + db: AsyncSession, skip: int = 0, limit: int = 100 +) -> list[AugmentedPart]: result = await db.execute( - select(AugmentedPart).order_by(AugmentedPart.description).offset(skip).limit(limit) + select(AugmentedPart) + .order_by(AugmentedPart.description) + .offset(skip) + .limit(limit) ) return list(result.scalars().all()) @@ -88,7 +93,9 @@ async def list_filtered( q = select(AugmentedPart) if description.strip(): term = f"%{description.strip()}%" - q = q.where(or_(AugmentedPart.description.ilike(term), AugmentedPart.sku.ilike(term))) + q = q.where( + or_(AugmentedPart.description.ilike(term), AugmentedPart.sku.ilike(term)) + ) if colour_id is not None: q = q.where(AugmentedPart.colour_id == colour_id) if manufacturer_id is not None: @@ -118,7 +125,9 @@ async def count_filtered( q = select(func.count()).select_from(AugmentedPart) if description.strip(): term = f"%{description.strip()}%" - q = q.where(or_(AugmentedPart.description.ilike(term), AugmentedPart.sku.ilike(term))) + q = q.where( + or_(AugmentedPart.description.ilike(term), AugmentedPart.sku.ilike(term)) + ) if colour_id is not None: q = q.where(AugmentedPart.colour_id == colour_id) if manufacturer_id is not None: @@ -141,13 +150,17 @@ async def get_unlinked_imported_parts_filtered( limit: int = 50, ) -> list[ImportedPart]: q = select(ImportedPart).where( - ImportedPart.InventoryID.not_in(select(augmented_part_imported_parts.c.imported_part_id)) + ImportedPart.InventoryID.not_in( + select(augmented_part_imported_parts.c.imported_part_id) + ) ) if description.strip(): q = q.where(ImportedPart.Description.ilike(f"%{description.strip()}%")) if colour.strip(): q = q.where(ImportedPart.TBXColour.ilike(f"%{colour.strip()}%")) - result = await db.execute(q.order_by(ImportedPart.InventoryID).offset(skip).limit(limit)) + result = await db.execute( + q.order_by(ImportedPart.InventoryID).offset(skip).limit(limit) + ) return list(result.scalars().all()) diff --git a/app/crud/imported_part.py b/app/crud/imported_part.py index 0add65d..58a65c6 100644 --- a/app/crud/imported_part.py +++ b/app/crud/imported_part.py @@ -63,7 +63,10 @@ async def list_filtered( if description.strip(): term = f"%{description.strip()}%" q = q.where( - or_(ImportedPart.Description.ilike(term), ImportedPart.InventoryID.ilike(term)) + or_( + ImportedPart.Description.ilike(term), + ImportedPart.InventoryID.ilike(term), + ) ) q = _apply_sort(q, sort, direction) result = await db.execute(q.offset(skip).limit(limit)) @@ -93,7 +96,10 @@ async def count_filtered(db: AsyncSession, description: str = "") -> int: if description.strip(): term = f"%{description.strip()}%" q = q.where( - or_(ImportedPart.Description.ilike(term), ImportedPart.InventoryID.ilike(term)) + or_( + ImportedPart.Description.ilike(term), + ImportedPart.InventoryID.ilike(term), + ) ) result = await db.execute(q) return result.scalar_one() diff --git a/app/services/scope_import.py b/app/services/scope_import.py index 0116711..038519e 100644 --- a/app/services/scope_import.py +++ b/app/services/scope_import.py @@ -138,11 +138,15 @@ def parse_workbook(data: bytes) -> list[dict]: wb.close() -async def _static_ap(db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float): +async def _static_ap( + db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float +): """Create an attachment point carrying a StaticConnection for ``od_mm``.""" sc = await static_connection_crud.get_by_od_mm(db, od_mm) if sc is None: - sc = await static_connection_crud.create(db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH) + sc = await static_connection_crud.create( + db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH + ) apn = await apn_crud.get_by_name(db, label) if apn is None: apn = await apn_crud.create(db, name=label) @@ -154,7 +158,9 @@ async def _static_ap(db: AsyncSession, *, augmented_part_id: int, label: str, od ) -async def _thread_ap(db: AsyncSession, *, augmented_part_id: int, label: str, spec: str): +async def _thread_ap( + db: AsyncSession, *, augmented_part_id: int, label: str, spec: str +): """Create an attachment point for a parsed ISO/UNC thread, or None.""" parsed = _parse_thread_attribute(spec) if parsed is None: @@ -217,7 +223,9 @@ async def _link_fit( target_ap = target_aps[0] existing = await fit_crud.get_by_attachment_points(db, scope_ap, target_ap) if existing is None: - await fit_crud.create(db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE) + await fit_crud.create( + db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE + ) async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult: @@ -261,7 +269,9 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult manufacturer = await manufacturer_crud.get_by_name(db, manufacturer_name) if manufacturer is None: - manufacturer = await manufacturer_crud.create(db, name=manufacturer_name, url="") + manufacturer = await manufacturer_crud.create( + db, name=manufacturer_name, url="" + ) model_name = _text(row.get("model")) url = _text(row.get("url")) @@ -323,7 +333,9 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult # Rebuild attachment points from scratch so re-imports stay idempotent # (cascades delete any fits that referenced the old points). - for old_ap in await attachment_point_crud.list_for_augmented_part(db, part.id): + for old_ap in await attachment_point_crud.list_for_augmented_part( + db, part.id + ): await attachment_point_crud.delete(db, old_ap) ocular_ap = None diff --git a/scripts/seed.py b/scripts/seed.py index 58136ab..2f985ca 100644 --- a/scripts/seed.py +++ b/scripts/seed.py @@ -113,7 +113,9 @@ async def seed() -> None: for name, description in PERMISSIONS: perm = await role_crud.get_permission_by_name(db, name) if perm is None: - perm = await role_crud.create_permission(db, name=name, description=description) + perm = await role_crud.create_permission( + db, name=name, description=description + ) perms[name] = perm # Roles @@ -151,10 +153,14 @@ async def seed() -> None: if pt is not None: for spt_name in spt_names: if ( - await sub_part_type_crud.get_by_name_and_part_type(db, spt_name, pt.id) + await sub_part_type_crud.get_by_name_and_part_type( + db, spt_name, pt.id + ) is None ): - await sub_part_type_crud.create(db, name=spt_name, part_type_id=pt.id) + await sub_part_type_crud.create( + db, name=spt_name, part_type_id=pt.id + ) # Superuser existing = await user_crud.get_by_email(db, settings.first_superuser_email) diff --git a/tests/test_danger_zone.py b/tests/test_danger_zone.py index 5edd2ad..381463d 100644 --- a/tests/test_danger_zone.py +++ b/tests/test_danger_zone.py @@ -55,8 +55,12 @@ async def _seed_domain_data(db): db.add_all([scope, cover]) await db.flush() - db.add(AugmentedPartNote(augmented_part_id=scope.id, username="tester", body="note")) - db.add(ScopeInfo(augmented_part_id=scope.id, magnification_min=3, magnification_max=18)) + db.add( + AugmentedPartNote(augmented_part_id=scope.id, username="tester", body="note") + ) + db.add( + ScopeInfo(augmented_part_id=scope.id, magnification_min=3, magnification_max=18) + ) ap_s = AttachmentPoint( augmented_part_id=scope.id, @@ -85,7 +89,9 @@ async def _seed_domain_data(db): imported = ImportedPart(InventoryID="INV-1", Description="Alpha 3-18x50") db.add(imported) - config = ImportedPartConfig(id=1, odata_url="https://example.test/odata", username="svc") + config = ImportedPartConfig( + id=1, odata_url="https://example.test/odata", username="svc" + ) db.add(config) await db.commit()