@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.lab.dto.ration import RationSnapshot
|
||||
|
||||
|
||||
def ration_to_api(snapshot: RationSnapshot) -> dict[str, Any]:
|
||||
return {
|
||||
"recipeId": snapshot.recipe_id,
|
||||
"recipeName": snapshot.recipe_name,
|
||||
"rationType": snapshot.ration_type,
|
||||
"headsPerTrip": snapshot.heads_per_trip,
|
||||
"exists": snapshot.exists,
|
||||
"animalProfileId": snapshot.animal_profile_id,
|
||||
"params": snapshot.params,
|
||||
"norms": snapshot.norms,
|
||||
"normsProfileKey": snapshot.norms_profile_key,
|
||||
"legacyNormsRemapped": snapshot.legacy_norms_remapped,
|
||||
"rationResults": snapshot.ration_results,
|
||||
"compoundResults": snapshot.compound_results,
|
||||
"calculatedAt": snapshot.calculated_at,
|
||||
"lines": [
|
||||
{
|
||||
"id": line.id,
|
||||
"componentId": line.component_id,
|
||||
"ingredientName": line.ingredient_name,
|
||||
"rowIndex": line.row_index,
|
||||
"dailyKg": line.daily_kg,
|
||||
"inRation": line.in_ration,
|
||||
"inCompound": line.in_compound,
|
||||
"dryMatter": line.dry_matter,
|
||||
"pricePerKg": line.price_per_kg,
|
||||
}
|
||||
for line in snapshot.lines
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def diff_to_api(diff: dict[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
"hasChanges": diff.get("has_changes", False),
|
||||
"lines": [
|
||||
{
|
||||
"componentId": row.get("component_id"),
|
||||
"masterKg": row.get("master_kg"),
|
||||
"executionKg": row.get("execution_kg"),
|
||||
"reasons": row.get("reasons", []),
|
||||
}
|
||||
for row in diff.get("lines", [])
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user