refactor(status): introduce OrderStatus enum, replace string literals
Centralized order status values in api/app/constants.py via a str-valued Enum so comparisons keep working. Replaced literals in: - services: sync_service, sqlite_service, retry_service - routers: sync, dashboard - templates: dashboard.html, logs.html - static JS: shared (ORDER_STATUS mirror), dashboard, logs - tests: requirements, order_items_overwrite, business_rules MALFORMED intentionally NOT added — introduced in follow-up PR2 (per-order failure isolation). Full test suite: 231 unit + 33 e2e pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import logging
|
||||
import tempfile
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from ..constants import OrderStatus
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -70,7 +72,7 @@ async def _download_and_reimport(order_number: str, order_date_str: str, custome
|
||||
order_number=order_number,
|
||||
order_date=order_date_str,
|
||||
customer_name=customer_name,
|
||||
status="ERROR",
|
||||
status=OrderStatus.ERROR.value,
|
||||
error_message=f"Retry failed: {e}",
|
||||
)
|
||||
return {"success": False, "message": f"Eroare import: {e}"}
|
||||
@@ -103,7 +105,7 @@ async def _download_and_reimport(order_number: str, order_date_str: str, custome
|
||||
order_number=order_number,
|
||||
order_date=order_date_str,
|
||||
customer_name=customer_name,
|
||||
status="IMPORTED",
|
||||
status=OrderStatus.IMPORTED.value,
|
||||
id_comanda=result.get("id_comanda"),
|
||||
id_partener=result.get("id_partener"),
|
||||
error_message=None,
|
||||
@@ -116,7 +118,7 @@ async def _download_and_reimport(order_number: str, order_date_str: str, custome
|
||||
)
|
||||
await sqlite_service.add_order_items(order_number, order_items_data)
|
||||
logger.info(f"Retry successful for order {order_number} → IMPORTED ({len(order_items_data)} items)")
|
||||
return {"success": True, "message": "Comanda reimportata cu succes", "status": "IMPORTED"}
|
||||
return {"success": True, "message": "Comanda reimportata cu succes", "status": OrderStatus.IMPORTED.value}
|
||||
else:
|
||||
error = result.get("error", "Unknown error")
|
||||
await sqlite_service.upsert_order(
|
||||
@@ -124,11 +126,11 @@ async def _download_and_reimport(order_number: str, order_date_str: str, custome
|
||||
order_number=order_number,
|
||||
order_date=order_date_str,
|
||||
customer_name=customer_name,
|
||||
status="ERROR",
|
||||
status=OrderStatus.ERROR.value,
|
||||
error_message=f"Retry: {error}",
|
||||
)
|
||||
await sqlite_service.add_order_items(order_number, order_items_data)
|
||||
return {"success": False, "message": f"Import esuat: {error}", "status": "ERROR"}
|
||||
return {"success": False, "message": f"Import esuat: {error}", "status": OrderStatus.ERROR.value}
|
||||
|
||||
|
||||
async def retry_single_order(order_number: str, app_settings: dict) -> dict:
|
||||
@@ -157,7 +159,7 @@ async def retry_single_order(order_number: str, app_settings: dict) -> dict:
|
||||
|
||||
order_data = detail["order"]
|
||||
status = order_data.get("status", "")
|
||||
if status not in ("ERROR", "SKIPPED", "DELETED_IN_ROA"):
|
||||
if status not in (OrderStatus.ERROR.value, OrderStatus.SKIPPED.value, OrderStatus.DELETED_IN_ROA.value):
|
||||
return {"success": False, "message": f"Retry permis doar pentru ERROR/SKIPPED/DELETED_IN_ROA (status actual: {status})"}
|
||||
|
||||
order_date_str = order_data.get("order_date", "")
|
||||
@@ -196,7 +198,7 @@ async def resync_single_order(order_number: str, app_settings: dict) -> dict:
|
||||
status = order_data.get("status", "")
|
||||
id_comanda = order_data.get("id_comanda")
|
||||
|
||||
if status not in ("IMPORTED", "ALREADY_IMPORTED") or not id_comanda:
|
||||
if status not in (OrderStatus.IMPORTED.value, OrderStatus.ALREADY_IMPORTED.value) or not id_comanda:
|
||||
return {"success": False, "message": f"Resync permis doar pentru IMPORTED/ALREADY_IMPORTED cu id_comanda (status actual: {status})"}
|
||||
|
||||
# Invoice safety gate
|
||||
@@ -269,7 +271,7 @@ async def delete_single_order(order_number: str) -> dict:
|
||||
status = order_data.get("status", "")
|
||||
id_comanda = order_data.get("id_comanda")
|
||||
|
||||
if status not in ("IMPORTED", "ALREADY_IMPORTED") or not id_comanda:
|
||||
if status not in (OrderStatus.IMPORTED.value, OrderStatus.ALREADY_IMPORTED.value) or not id_comanda:
|
||||
return {"success": False, "message": f"Stergere permisa doar pentru IMPORTED/ALREADY_IMPORTED cu id_comanda (status actual: {status})"}
|
||||
|
||||
# Invoice safety gate
|
||||
|
||||
Reference in New Issue
Block a user