Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- `POST /entry` saves the day's `observation` (it was silently dropped) and `GET /entry/<date>` returns it. A request without the field keeps the note already saved.

## [2.0.1] - 2026-10-03

### Changed
Expand Down
26 changes: 11 additions & 15 deletions app/routes/manual_entry.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime
from typing import Any, Dict, Optional, cast

from flask import Blueprint, jsonify, redirect, request, url_for
from flask_babel import gettext as _

from app.auth import current_employee_id
from app.db.database import db
from app.models.models import AbsenceCode, Employee, ScheduleEntry
from app.models.models import AbsenceCode, ScheduleEntry
from app.utils.time_calculator import calculate_daily_hours
from app.utils.validators import validate_date, validate_entries

Expand Down Expand Up @@ -58,19 +57,15 @@ def save_entry():

entries = data.get("entries", [])

if existing_entry:
existing_entry.entries = [] if absence_code else entries
existing_entry.absence_code = absence_code
db.session.commit()
else:
schedule_entry = ScheduleEntry(
employee_id=employee_id,
date=entry_date,
entries=[] if absence_code else entries,
absence_code=absence_code,
)
db.session.add(schedule_entry)
db.session.commit()
if existing_entry is None:
existing_entry = ScheduleEntry(employee_id=employee_id, date=entry_date)
db.session.add(existing_entry)
existing_entry.entries = [] if absence_code else entries
existing_entry.absence_code = absence_code
# A request without the key keeps the note already saved for the day.
if "observation" in data:
existing_entry.observation = (data["observation"] or "").strip() or None
db.session.commit()

if absence_code is None:
hours = calculate_daily_hours(entries)
Expand All @@ -94,6 +89,7 @@ def get_entry(date):
{
"entries": entry.entries,
"absence_code": entry.absence_code,
"observation": entry.observation,
"hours": (
calculate_daily_hours(entry.entries)
if not entry.absence_code
Expand Down
27 changes: 27 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,33 @@ def test_manual_entry_update_existing(self):
self.assertEqual(len(entry.entries), 1)
self.assertEqual(entry.entries[0]["exit"], "13:00")

def test_manual_entry_saves_observation(self):
entry_data = {
"date": "2025-03-20",
"entries": [{"entry": "09:00", "exit": "17:00"}],
"observation": " Dentist at noon ",
}
self.client.post(
"/entry", data=json.dumps(entry_data), content_type="application/json"
)
data = json.loads(self.client.get("/entry/2025-03-20").data)
self.assertEqual(data["observation"], "Dentist at noon")

# Without the key the note is kept; an empty string clears it.
entry_data.pop("observation")
self.client.post(
"/entry", data=json.dumps(entry_data), content_type="application/json"
)
data = json.loads(self.client.get("/entry/2025-03-20").data)
self.assertEqual(data["observation"], "Dentist at noon")

entry_data["observation"] = ""
self.client.post(
"/entry", data=json.dumps(entry_data), content_type="application/json"
)
data = json.loads(self.client.get("/entry/2025-03-20").data)
self.assertIsNone(data["observation"])

def test_get_entry_not_found(self):
response = self.client.get("/entry/2025-01-01")
self.assertEqual(response.status_code, 200)
Expand Down
Loading