Ripristino delle quote già misurate nel ciclo in corso dopo un reload (#40)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -595,6 +595,40 @@ def api_task_progress(task_id: int):
|
||||
return jsonify(row), 200
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Route: quotes already measured in the current cycle (#40)
|
||||
# ---------------------------------------------------------------------------
|
||||
@measure_bp.route("/api/current-cycle/<int:task_id>", methods=["GET"])
|
||||
@login_required
|
||||
@role_required("MeasurementTec")
|
||||
def api_current_cycle(task_id: int):
|
||||
"""Proxy: quotes of this task already measured in the cycle under way.
|
||||
|
||||
The run comes from _current_run_id(), like the rest of the page. Outside a
|
||||
production there is no cycle to restore and the answer is an empty list.
|
||||
"""
|
||||
task_resp = api_client.get(f"/api/tasks/{task_id}")
|
||||
if isinstance(task_resp, dict) and task_resp.get("error"):
|
||||
return jsonify(task_resp), task_resp.get("status_code", 500)
|
||||
|
||||
recipe_id = task_resp.get("recipe_id")
|
||||
if recipe_id and not _recipe_allowed_at_station(recipe_id):
|
||||
abort(403, description=_("Ricetta non assegnata a questa stazione"))
|
||||
|
||||
run_id = _current_run_id()
|
||||
if not run_id:
|
||||
return jsonify({"measurements": []}), 200
|
||||
|
||||
resp = api_client.get(
|
||||
"/api/measurements/current-cycle",
|
||||
params={"production_run_id": run_id, "task_id": task_id},
|
||||
)
|
||||
if not isinstance(resp, dict) or resp.get("error"):
|
||||
# Never fatal: without the restore the screen behaves as it always did.
|
||||
return jsonify({"measurements": []}), 200
|
||||
return jsonify(resp), 200
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Routes: Out-of-tolerance authorisation (point 5)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user