Skip to content

[codex] Align reader and staff loans with the server calendar - #58

Merged
fabiodalez-dev merged 1 commit into
mainfrom
fix/calendar-loan-alignment
Nov 4, 2026
Merged

fabiodalez-dev merged 1 commit into
mainfrom
fix/calendar-loan-alignment

Conversation

@fabiodalez-dev

Copy link
Copy Markdown
Owner

A loan whose original due day was later closed can still be on time on its first usable return day. The app previously showed the stored deadline and raw status, so reader groups and staff badges could disagree with the calendar and the actions offered by the server.

Read the additive effective_due_at and nullable is_overdue fields from reader and staff loan responses. Lists, badges and loan details follow those server facts; edit forms retain the stored due_at. Older servers continue to use the previous date/status fallback, and returned loans and uncollected requests retain their own timeline. Backend counterpart: fabiodalez-dev/Pinakes#521.

Validation:

  • 702 JVM tests pass, including 9 new calendar-alignment tests.
  • :app:assembleDebug and :app:lintDebug pass.
  • 2 new emulator UI flows pass: renewal on the first open day and recall without renewal on a genuinely overdue loan.

Final review covered serialization compatibility, reader grouping, staff badges, dates, available actions and preservation of the nominal edit date. No additional actionable findings remain in this diff.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c6f3878-4b27-49ea-926a-4d550af26b07
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@fabiodalez-dev
fabiodalez-dev marked this pull request as ready for review November 4, 2026 09:10
@fabiodalez-dev
fabiodalez-dev merged commit 2634c84 into main Nov 4, 2026
3 checks passed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The offline loan cache drops effective_due_at and is_overdue. When offline, the reader's Library tab goes back to the raw status and the stored due date, which is the bug this PR fixes.

Reviewed changes

This review covers the single commit that adds the server calendar facts to reader and staff loan models and passes them through the status, grouping and date helpers.

  • Model fields: LoanItem and StaffLoan decode nullable effective_due_at / is_overdue and expose displayDueAt = effectiveDueAt ?: dueAt.
  • Status mapping: StatusMapping.calendarStatus swaps only in_corso and in_ritardo based on a non-null is_overdue. The new loan(LoanItem), loan(StaffLoan) and loanGroup(LoanItem) overloads now drive loanNeedsAttention and loanDate.
  • Reader UI: LibraryScreen groups rows and picks the chip through the calendar-aware overloads.
  • Staff UI: loanChip, loanDateLine and the loan detail "Due" line use the server decision and displayDueAt. The edit form still starts from the stored dueAt.
  • Tests: 9 JVM tests in CalendarLoanAlignmentTest and 2 desk flows in CalendarLoanAlignmentFlowTest.

⚠️ Offline Library view goes back to the stale status and date

LibraryRepository.loans() writes each successful response to Room through LoanItem.toCached. CachedLoan has no columns for the new fields, so toCached/toLoanItem silently drop them. When offline, loansCached() rebuilds LoanItems with isOverdue == null and effectiveDueAt == null. A loan whose due day fell on a closure then shows in red under "Overdue" with the stored date, while the same screen online shows "On loan" with the first open day.

Technical details
# Persist calendar facts in the offline loan cache

## Affected sites
- app/src/main/java/com/pinakes/app/data/local/LibraryCache.kt:16-37 — `CachedLoan` has no `effectiveDueAt` / `isOverdue` columns
- app/src/main/java/com/pinakes/app/data/local/LibraryCache.kt:75-85 — `LoanItem.toCached` / `CachedLoan.toLoanItem` don't carry them
- app/src/main/java/com/pinakes/app/data/local/AppDatabase.kt:17 — schema `version = 3`

## Required outcome
- A loan rebuilt from the cache gives the same `StatusMapping.loanGroup` / `loan` / `loanDate` results as the network `LoanItem` it came from.
- Room schema bumped so existing installs rebuild the table. `fallbackToDestructiveMigration` is already set and the cache rebuilds from the server.

## Suggested approach
- Add `val effectiveDueAt: String? = null` and `val isOverdue: Boolean? = null` to `CachedLoan`, map both ways, and bump `AppDatabase` to version 4.
- Add a round-trip assertion (`LoanItem` → `toCached` → `toLoanItem`) for the closure case to the existing cache tests.

ℹ️ Copy-scan sheet still shows the stored due date

StaffCopyScanScreen.kt:366 renders loan.dueAt for a StaffLoan. The chip just above it now comes from the calendar-aware loanChip. After a closure, the scan sheet can show an "On loan" chip next to a due date that has already passed. Switching it to loan.displayDueAt would match StaffLoanDetailScreen and loanDateLine.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

fabiodalez-dev added a commit that referenced this pull request Nov 6, 2026
…ting

Release 1.12.0: the same-day handover switch, with the server calendar loans (#58)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant