Adjusting default product name
This commit is contained in:
1 parent
9a9ebab7c8
commit
34d538f9a0
1 file changed
+33
-19
@@ -138,15 +138,11 @@ def parse_workbook(data: bytes) -> list[dict]:
|
|||||||
wb.close()
|
wb.close()
|
||||||
|
|
||||||
|
|
||||||
async def _static_ap(
|
async def _static_ap(db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float):
|
||||||
db: AsyncSession, *, augmented_part_id: int, label: str, od_mm: float
|
|
||||||
):
|
|
||||||
"""Create an attachment point carrying a StaticConnection for ``od_mm``."""
|
"""Create an attachment point carrying a StaticConnection for ``od_mm``."""
|
||||||
sc = await static_connection_crud.get_by_od_mm(db, od_mm)
|
sc = await static_connection_crud.get_by_od_mm(db, od_mm)
|
||||||
if sc is None:
|
if sc is None:
|
||||||
sc = await static_connection_crud.create(
|
sc = await static_connection_crud.create(db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH)
|
||||||
db, od_mm=od_mm, od_in=od_mm / MM_PER_INCH
|
|
||||||
)
|
|
||||||
apn = await apn_crud.get_by_name(db, label)
|
apn = await apn_crud.get_by_name(db, label)
|
||||||
if apn is None:
|
if apn is None:
|
||||||
apn = await apn_crud.create(db, name=label)
|
apn = await apn_crud.create(db, name=label)
|
||||||
@@ -158,9 +154,7 @@ async def _static_ap(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _thread_ap(
|
async def _thread_ap(db: AsyncSession, *, augmented_part_id: int, label: str, spec: str):
|
||||||
db: AsyncSession, *, augmented_part_id: int, label: str, spec: str
|
|
||||||
):
|
|
||||||
"""Create an attachment point for a parsed ISO/UNC thread, or None."""
|
"""Create an attachment point for a parsed ISO/UNC thread, or None."""
|
||||||
parsed = _parse_thread_attribute(spec)
|
parsed = _parse_thread_attribute(spec)
|
||||||
if parsed is None:
|
if parsed is None:
|
||||||
@@ -223,9 +217,7 @@ async def _link_fit(
|
|||||||
target_ap = target_aps[0]
|
target_ap = target_aps[0]
|
||||||
existing = await fit_crud.get_by_attachment_points(db, scope_ap, target_ap)
|
existing = await fit_crud.get_by_attachment_points(db, scope_ap, target_ap)
|
||||||
if existing is None:
|
if existing is None:
|
||||||
await fit_crud.create(
|
await fit_crud.create(db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE)
|
||||||
db, ap_a=scope_ap, ap_b=target_ap, label=FitLabel.POSSIBLE
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult:
|
async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult:
|
||||||
@@ -247,7 +239,21 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
# +2: 1-based, and the header occupies row 1.
|
# +2: 1-based, and the header occupies row 1.
|
||||||
row_num = offset + 2
|
row_num = offset + 2
|
||||||
model_suffix = _text(row.get("model_suffix"))
|
model_suffix = _text(row.get("model_suffix"))
|
||||||
default_product_number = f"{_text(row.get('model'))} {row.get('magnification_min')}-{row.get('magnification_max')}x{row.get('objective_lens_diameter_mm')} {row.get('model_suffix')}".strip()
|
model = _text(row.get("model"))
|
||||||
|
magnification_min = _num(row.get("magnification_min"))
|
||||||
|
magnification_max = _num(row.get("magnification_max"))
|
||||||
|
objective_lens_diameter_mm = _num(row.get("objective_lens_diameter_mm")) or _num(
|
||||||
|
row.get("objective_lens")
|
||||||
|
)
|
||||||
|
|
||||||
|
# Construct the model number
|
||||||
|
default_product_number = model
|
||||||
|
if magnification_min:
|
||||||
|
default_product_number += f" {magnification_min}-{magnification_max}"
|
||||||
|
if objective_lens_diameter_mm:
|
||||||
|
default_product_number += f"x{objective_lens_diameter_mm}"
|
||||||
|
if model_suffix:
|
||||||
|
default_product_number += " {model_suffix}"
|
||||||
product_number = _text(row.get("product_number")) or default_product_number
|
product_number = _text(row.get("product_number")) or default_product_number
|
||||||
result = ScopeImportRowResult(
|
result = ScopeImportRowResult(
|
||||||
row=row_num, product_number=product_number, status="skipped", messages=[]
|
row=row_num, product_number=product_number, status="skipped", messages=[]
|
||||||
@@ -269,9 +275,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
|
|
||||||
manufacturer = await manufacturer_crud.get_by_name(db, manufacturer_name)
|
manufacturer = await manufacturer_crud.get_by_name(db, manufacturer_name)
|
||||||
if manufacturer is None:
|
if manufacturer is None:
|
||||||
manufacturer = await manufacturer_crud.create(
|
manufacturer = await manufacturer_crud.create(db, name=manufacturer_name, url="")
|
||||||
db, name=manufacturer_name, url=""
|
|
||||||
)
|
|
||||||
|
|
||||||
model_name = _text(row.get("model"))
|
model_name = _text(row.get("model"))
|
||||||
url = _text(row.get("url"))
|
url = _text(row.get("url"))
|
||||||
@@ -333,9 +337,7 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
|
|
||||||
# Rebuild attachment points from scratch so re-imports stay idempotent
|
# Rebuild attachment points from scratch so re-imports stay idempotent
|
||||||
# (cascades delete any fits that referenced the old points).
|
# (cascades delete any fits that referenced the old points).
|
||||||
for old_ap in await attachment_point_crud.list_for_augmented_part(
|
for old_ap in await attachment_point_crud.list_for_augmented_part(db, part.id):
|
||||||
db, part.id
|
|
||||||
):
|
|
||||||
await attachment_point_crud.delete(db, old_ap)
|
await attachment_point_crud.delete(db, old_ap)
|
||||||
|
|
||||||
ocular_ap = None
|
ocular_ap = None
|
||||||
@@ -377,6 +379,12 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
try:
|
try:
|
||||||
ocular_fit = _text(row.get("ocular_fit"))
|
ocular_fit = _text(row.get("ocular_fit"))
|
||||||
if ocular_fit:
|
if ocular_fit:
|
||||||
|
fits = ocular_fit
|
||||||
|
if "/" in fits:
|
||||||
|
fits = [x.strip() for x in fits.split("/")]
|
||||||
|
else:
|
||||||
|
fits = [fits]
|
||||||
|
for ocular_fit in fits:
|
||||||
await _link_fit(
|
await _link_fit(
|
||||||
db,
|
db,
|
||||||
scope_ap=ocular_ap,
|
scope_ap=ocular_ap,
|
||||||
@@ -387,6 +395,12 @@ async def import_scopes(db: AsyncSession, rows: list[dict]) -> ScopeImportResult
|
|||||||
)
|
)
|
||||||
objective_fit = _text(row.get("objective_fit"))
|
objective_fit = _text(row.get("objective_fit"))
|
||||||
if objective_fit:
|
if objective_fit:
|
||||||
|
fits = objective_fit
|
||||||
|
if "/" in fits:
|
||||||
|
fits = [x.strip() for x in fits.split("/")]
|
||||||
|
else:
|
||||||
|
fits = [fits]
|
||||||
|
for objective_fit in fits:
|
||||||
await _link_fit(
|
await _link_fit(
|
||||||
db,
|
db,
|
||||||
scope_ap=objective_ap,
|
scope_ap=objective_ap,
|
||||||
|
|||||||
Reference in new issue
Block a user