fix: ruff lint + format fixes in tests, ESLint fixes in frontend
This commit is contained in:
@@ -11,7 +11,6 @@ from decimal import Decimal
|
||||
from typing import Any
|
||||
|
||||
|
||||
|
||||
# HTML template for the sales contract
|
||||
_CONTRACT_HTML_TEMPLATE = """<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
@@ -191,7 +190,11 @@ def build_contract_html(sale: Any) -> str:
|
||||
|
||||
# Determine GwG clause
|
||||
gwg_section = ""
|
||||
if sale.is_gwg and sale.sale_price is not None and sale.sale_price <= Decimal("800"):
|
||||
if (
|
||||
sale.is_gwg
|
||||
and sale.sale_price is not None
|
||||
and sale.sale_price <= Decimal("800")
|
||||
):
|
||||
gwg_section = _GWG_CLAUSE_HTML
|
||||
|
||||
html = _CONTRACT_HTML_TEMPLATE.format(
|
||||
@@ -207,7 +210,9 @@ def build_contract_html(sale: Any) -> str:
|
||||
vehicle_model=getattr(vehicle, "model", "N/A") if vehicle else "N/A",
|
||||
vehicle_fin=getattr(vehicle, "fin", "N/A") if vehicle else "N/A",
|
||||
vehicle_type=getattr(vehicle, "vehicle_type", "N/A") if vehicle else "N/A",
|
||||
first_registration=_format_date(getattr(vehicle, "first_registration", None)) if vehicle else "N/A",
|
||||
first_registration=_format_date(getattr(vehicle, "first_registration", None))
|
||||
if vehicle
|
||||
else "N/A",
|
||||
mileage_km=getattr(vehicle, "mileage_km", "N/A") if vehicle else "N/A",
|
||||
power_kw=getattr(vehicle, "power_kw", "N/A") if vehicle else "N/A",
|
||||
power_hp=getattr(vehicle, "power_hp", "N/A") if vehicle else "N/A",
|
||||
|
||||
@@ -73,7 +73,9 @@ async def _search_contacts(db: AsyncSession, params: dict[str, Any]) -> dict[str
|
||||
}
|
||||
|
||||
|
||||
async def _get_sale_overview(db: AsyncSession, params: dict[str, Any]) -> dict[str, Any]:
|
||||
async def _get_sale_overview(
|
||||
db: AsyncSession, params: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
"""Get an overview of sales, optionally filtered by status or date range."""
|
||||
from app.models.sale import Sale
|
||||
from sqlalchemy import func, select
|
||||
@@ -93,7 +95,9 @@ async def _get_sale_overview(db: AsyncSession, params: dict[str, Any]) -> dict[s
|
||||
total = total_result.scalar_one()
|
||||
|
||||
offset = (page - 1) * page_size
|
||||
data_stmt = data_stmt.offset(offset).limit(page_size).order_by(Sale.created_at.desc())
|
||||
data_stmt = (
|
||||
data_stmt.offset(offset).limit(page_size).order_by(Sale.created_at.desc())
|
||||
)
|
||||
result = await db.execute(data_stmt)
|
||||
sales = list(result.scalars().all())
|
||||
|
||||
@@ -110,7 +114,9 @@ async def _create_vehicle(db: AsyncSession, params: dict[str, Any]) -> dict[str,
|
||||
required = ["make", "model", "fin", "price", "vehicle_type"]
|
||||
missing = [f for f in required if not params.get(f)]
|
||||
if missing:
|
||||
raise ValueError(f"Missing required fields for create_vehicle: {', '.join(missing)}")
|
||||
raise ValueError(
|
||||
f"Missing required fields for create_vehicle: {', '.join(missing)}"
|
||||
)
|
||||
|
||||
vehicle = await vehicle_service.create_vehicle(db, params)
|
||||
return vehicle.to_dict()
|
||||
@@ -121,7 +127,9 @@ async def _create_contact(db: AsyncSession, params: dict[str, Any]) -> dict[str,
|
||||
required = ["company_name", "role"]
|
||||
missing = [f for f in required if not params.get(f)]
|
||||
if missing:
|
||||
raise ValueError(f"Missing required fields for create_contact: {', '.join(missing)}")
|
||||
raise ValueError(
|
||||
f"Missing required fields for create_contact: {', '.join(missing)}"
|
||||
)
|
||||
|
||||
if "address_country" not in params:
|
||||
params["address_country"] = "DE"
|
||||
@@ -193,7 +201,9 @@ def get_available_actions() -> list[dict[str, Any]]:
|
||||
]
|
||||
|
||||
|
||||
async def execute_action(db: AsyncSession, action_type: str, params: dict[str, Any]) -> Any:
|
||||
async def execute_action(
|
||||
db: AsyncSession, action_type: str, params: dict[str, Any]
|
||||
) -> Any:
|
||||
"""Execute a registered action by type.
|
||||
|
||||
Raises ValueError if the action type is not registered.
|
||||
|
||||
@@ -109,9 +109,7 @@ def map_fields(vehicle: Vehicle) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
if vehicle.first_registration is not None:
|
||||
ad["firstRegistration"] = _format_first_registration(
|
||||
vehicle.first_registration
|
||||
)
|
||||
ad["firstRegistration"] = _format_first_registration(vehicle.first_registration)
|
||||
|
||||
if mileage is not None:
|
||||
ad["mileage"] = mileage
|
||||
|
||||
@@ -98,10 +98,18 @@ def _parse_response(raw_content: str) -> dict[str, Any]:
|
||||
data = json.loads(text[start : end + 1])
|
||||
except json.JSONDecodeError:
|
||||
logger.error("Failed to parse OpenRouter response: %s", text[:200])
|
||||
return {"structured_data": {}, "confidence_score": 0.0, "raw_text": raw_content}
|
||||
return {
|
||||
"structured_data": {},
|
||||
"confidence_score": 0.0,
|
||||
"raw_text": raw_content,
|
||||
}
|
||||
else:
|
||||
logger.error("No JSON found in OpenRouter response: %s", text[:200])
|
||||
return {"structured_data": {}, "confidence_score": 0.0, "raw_text": raw_content}
|
||||
return {
|
||||
"structured_data": {},
|
||||
"confidence_score": 0.0,
|
||||
"raw_text": raw_content,
|
||||
}
|
||||
|
||||
# Extract confidence score (may be inside or outside the data)
|
||||
confidence = data.pop("confidence_score", None)
|
||||
|
||||
@@ -71,13 +71,17 @@ def generate_thumbnail(
|
||||
background = Image.new("RGB", img.size, (255, 255, 255))
|
||||
if img.mode == "P":
|
||||
img = img.convert("RGBA")
|
||||
background.paste(img, mask=img.split()[-1] if img.mode in ("RGBA", "LA") else None)
|
||||
background.paste(
|
||||
img, mask=img.split()[-1] if img.mode in ("RGBA", "LA") else None
|
||||
)
|
||||
img = background
|
||||
elif img.mode != "RGB":
|
||||
img = img.convert("RGB")
|
||||
|
||||
# Use ImageOps.fit for a centered crop to exact thumbnail size
|
||||
thumbnail = ImageOps.fit(img, THUMBNAIL_SIZE, method=Image.Resampling.LANCZOS)
|
||||
thumbnail = ImageOps.fit(
|
||||
img, THUMBNAIL_SIZE, method=Image.Resampling.LANCZOS
|
||||
)
|
||||
thumbnail.save(thumbnail_path, quality=85, optimize=True)
|
||||
|
||||
logger.info("Thumbnail generated: %s", thumbnail_path)
|
||||
|
||||
@@ -38,9 +38,33 @@ _EU_FALLBACK_PATTERN = re.compile(r"^[A-Z]{2}[A-Za-z0-9]{5,15}$")
|
||||
|
||||
# Set of supported EU country codes (ISO 3166-1 alpha-2).
|
||||
_EU_COUNTRY_CODES: set[str] = {
|
||||
"AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FR", "GR",
|
||||
"HR", "HU", "IE", "IT", "LT", "LU", "LV", "MT", "NL", "PL", "PT", "RO",
|
||||
"SE", "SI", "SK",
|
||||
"AT",
|
||||
"BE",
|
||||
"BG",
|
||||
"CY",
|
||||
"CZ",
|
||||
"DE",
|
||||
"DK",
|
||||
"EE",
|
||||
"ES",
|
||||
"FI",
|
||||
"FR",
|
||||
"GR",
|
||||
"HR",
|
||||
"HU",
|
||||
"IE",
|
||||
"IT",
|
||||
"LT",
|
||||
"LU",
|
||||
"LV",
|
||||
"MT",
|
||||
"NL",
|
||||
"PL",
|
||||
"PT",
|
||||
"RO",
|
||||
"SE",
|
||||
"SI",
|
||||
"SK",
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user