feat(app): scan-mode sync, confirmation-gated documents, single-pass product classification
Fixes reported from APK field testing: DO/Product scan mode was inconsistent between the camera drawer and documents screen (now one shared provider, with an orange/green color cue); unconfirmed scans leaked into history with placeholder data before the user tapped confirm (backend now gates GET /documents on a new `confirmed` column, flipped only by PUT); and Product Scan ran the GPU classifier twice, once at upload and again on review (now a single pass at upload, persisted and read directly by the editor). Also removes the unused "Hubungkan ke PO" field and fabricated PO/SO/DO placeholder values from the Product Scan flow, closes out the per-document-polling and save-recovery tasks (6.1/6.3), and splits several touched files to stay under the repo's 256-line guideline. Full detail in docs/iteration-log.md and backend/docs/iteration-log.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2febe0c886
commit
ada6488592
67 files changed
+5705
-1142
No files matched your search
+314
-31
@@ -1,4 +1,4 @@
|
||||
# Next Enhancements (Flutter)
|
||||
# Next Enhancements (Flutter)
|
||||
|
||||
This file is the working backlog driven by the `e`/`enhance` and `n`/`next` triggers
|
||||
defined in [AGENTS.md](../AGENTS.md), which now scopes this kit's automated
|
||||
@@ -7,15 +7,15 @@ Sections seeded 2026-07-08 from the real module structure of `app-pfm-ocr-v2` (s
|
||||
AGENTS.md's Adaptation Notes); tasks populated the same day via `e`/`enhance`,
|
||||
grounded in a direct read of each module's current code rather than invented work.
|
||||
|
||||
> `backend/` has its own, independent copy of this kit —
|
||||
> `backend/` has its own, independent copy of this kit —
|
||||
> [backend/plans/next-enhancements.md](../backend/plans/next-enhancements.md), driven
|
||||
> by `backend/AGENTS.md` Part B. This file no longer tracks backend work at all —
|
||||
> by `backend/AGENTS.md` Part B. This file no longer tracks backend work at all —
|
||||
> the backend sections that briefly lived here (5-8, from the one backend-scoped `e`
|
||||
> run before the kit split) were removed 2026-07-08 now that the backend copy is the
|
||||
> sole active backlog for that subtree.
|
||||
|
||||
> Note: this repo already has an unrelated, pre-existing `plans/next-enhancement-plan.md`
|
||||
> (singular) — a `[DONE]` QA verification checklist. It is not part of this workflow
|
||||
> (singular) — a `[DONE]` QA verification checklist. It is not part of this workflow
|
||||
> and is left as-is; this file (plural) is the one `e`/`n` reads and writes.
|
||||
|
||||
## Format
|
||||
@@ -32,7 +32,7 @@ section gets exactly 3 tasks:
|
||||
```
|
||||
|
||||
When a task is picked up via `n`/`next`, its clarified acceptance criteria (from
|
||||
AGENTS.md §2a) are appended directly under it as a short note, e.g.:
|
||||
AGENTS.md §2a) are appended directly under it as a short note, e.g.:
|
||||
|
||||
```
|
||||
- **1.1** [TODO] <description>
|
||||
@@ -44,84 +44,367 @@ When complete, the status flips to `[DONE]` and the feature is logged in
|
||||
|
||||
---
|
||||
|
||||
## Sections (seeded from real modules — run `e` / `enhance` to fill in tasks)
|
||||
## Sections (seeded from real modules — run `e` / `enhance` to fill in tasks)
|
||||
|
||||
### 1. Flutter — Auth & Splash
|
||||
### 1. Flutter — Auth & Splash
|
||||
`lib/features/auth/`, `lib/features/splash/`
|
||||
|
||||
- **1.1** [TODO] Validate the stored token before treating the user as logged in. `AuthNotifier.checkLoginState()` (`lib/features/auth/auth_provider.dart:11-20`) only checks that a token string exists in `SharedPreferences` — it never checks expiry or pings the server — so a stale/revoked token shows the camera screen and only fails later, silently, on the first real API call.
|
||||
- **1.1** [TODO] Harden the token validation that now exists. *(Description refreshed 2026-07-10 — the original claim "never pings the server" is stale: `checkLoginState()` now calls `GET /auth/me` and logs out on 401.)* Remaining gap (see [docs/api-contract-map.md](../docs/api-contract-map.md) **G9**): 401 detection is `e.toString().contains('401')` (`auth_provider.dart:30`) instead of reading `ApiException.from(e).statusCode`, and any non-401 failure (timeout, 500, dead tunnel) silently treats the user as logged in with a possibly-stale cached profile. Use the structured exception, and decide/handle the offline-start case explicitly.
|
||||
- **1.2** [TODO] Add a global 401/403 response interceptor to the Dio client that force-logs-out and redirects to `/login`, so an expired/revoked token surfaces as a clear re-login prompt instead of failing whatever screen happens to make the next API call.
|
||||
- **1.3** [TODO] Warn before logout if the in-memory pending documents queue (`pendingDocumentsProvider`, `lib/features/documents/pending_documents_provider.dart`) has unsynced items. Today `CameraScreen`'s drawer logout (`camera_screen.dart:367-370`) calls `logout()` unconditionally, silently orphaning any in-flight uploads or unsent items.
|
||||
- **1.3** [DONE 2026-07-10] Warn before logout if the pending documents queue (`pendingDocumentsProvider`) has unsynced items. *(File reference corrected: the drawer now lives in `lib/features/camera/camera_drawer.dart`, not `camera_screen.dart` — extracted in a later commit.)* Acceptance: if the queue is non-empty when Logout is tapped, show a confirm dialog ("Ada Dokumen Belum Tersinkron" / item count / Batal-or-Ya-Logout) before calling `logout()`; if empty, logout proceeds immediately as before. Implemented in `CameraDrawer._handleLogout()` (`camera_drawer.dart`). See docs/feature-list.md.
|
||||
|
||||
### 2. Flutter — Camera Capture & Geotagging
|
||||
### 2. Flutter — Camera Capture & Geotagging
|
||||
`lib/features/camera/`
|
||||
|
||||
- **2.1** [TODO] Surface actionable, user-visible feedback when location can't be determined, instead of only logging it. Every failure path in `LocationService.determinePosition()` (`lib/core/location/location_service.dart`) — services disabled, permission denied, `deniedForever`, or all four GPS-fix strategies failing — only calls `debugPrint` and returns `null`; the driver gets no on-screen prompt (e.g. "enable location" / "open app settings") and the document just uploads without a GPS tag.
|
||||
- **2.2** [TODO] Show a location-fix quality/staleness indicator on the capture screen before the shutter is pressed. `_currentPosition` in `CameraScreen` (`camera_screen.dart:22,37-62`) is used whatever its age or accuracy, with no on-screen warning when no fix has landed yet or the fix is old — a document can silently upload with a poor or missing GPS tag.
|
||||
- **2.3** [TODO] Replace the static "posisikan seluruh halaman dokumen di dalam foto" instructional text with a live document-alignment overlay during capture. `CameraScreen` only launches the OS's native camera app via `ImagePicker(source: ImageSource.camera)` (`camera_screen.dart:69-74`) — there's no in-app camera preview, so the framing guideline is shown once beforehand and then unavailable during the actual shot.
|
||||
- **2.1** [TODO] Surface actionable, user-visible feedback when location can't be determined, instead of only logging it. Every failure path in `LocationService.determinePosition()` (`lib/core/location/location_service.dart`) — services disabled, permission denied, `deniedForever`, or all four GPS-fix strategies failing — only calls `debugPrint` and returns `null`; the driver gets no on-screen prompt (e.g. "enable location" / "open app settings") and the document just uploads without a GPS tag.
|
||||
- **2.2** [TODO] Show a location-fix quality/staleness indicator on the capture screen before the shutter is pressed. `_currentPosition` in `CameraScreen` (`camera_screen.dart:22,37-62`) is used whatever its age or accuracy, with no on-screen warning when no fix has landed yet or the fix is old — a document can silently upload with a poor or missing GPS tag.
|
||||
- **2.3** [TODO] Replace the static "posisikan seluruh halaman dokumen di dalam foto" instructional text with a live document-alignment overlay during capture. `CameraScreen` only launches the OS's native camera app via `ImagePicker(source: ImageSource.camera)` (`camera_screen.dart:69-74`) — there's no in-app camera preview, so the framing guideline is shown once beforehand and then unavailable during the actual shot.
|
||||
|
||||
### 3. Flutter — Pending Documents Queue
|
||||
### 3. Flutter — Pending Documents Queue
|
||||
`lib/features/documents/`
|
||||
|
||||
- **3.1** [DONE] Persisted the pending documents queue to disk via a new Hive box (`LocalStorage.pendingDocumentsBox`/`savePendingDocument`/`removePendingDocument`/`getAllPendingDocuments`, `lib/core/storage/local_storage.dart`). `PendingDocumentsNotifier` now hydrates from disk on construction and resumes anything not yet terminal: a persisted `uploading` item (fresh capture, or a `retryUpload` interrupted mid-flight) re-runs `_uploadAndProcess` from scratch — safe because the upload endpoint dedupes by file hash server-side — and a persisted `processing` item resumes polling via the newly extracted `_pollUntilParsed`/`_resumePolling` instead of re-uploading. `retrySync`'s own transient flip to `uploading` is deliberately kept in-memory-only (`_updateItemInMemory`) so an interrupted sync-retry resumes as "resend the PUT," not "redo the whole upload." Storage failures are caught and swallowed everywhere (`hydrate`, `_persistPendingDocument`, `_removePersistedPendingDocument`) so a Hive error degrades to the old in-memory-only behavior rather than crashing the queue. Verified via `flutter analyze` (clean) and `flutter test` (no new failures vs. the pre-existing 3-test baseline). Completed 2026-07-08.
|
||||
- **3.2** [TODO] Add a persistent "pending/syncing count" badge visible from the camera screen (not just the `/documents` list), reflecting `pendingDocumentsProvider` state — today a driver who navigates away from `/documents` gets no visibility into background uploads still in progress or stuck in `error`/`syncFailed`.
|
||||
- **3.3** [TODO] Add explicit Dio request timeouts to the upload and poll calls in `_uploadAndProcess` (`pending_documents_provider.dart:112-162`). The 2s-interval/130-retry poll loop is intentional and bounded, but the underlying `apiClient.client.post`/`.get` calls themselves have no explicit connect/receive timeout, so a genuinely hung connection (not a slow-but-alive OCR pass) can leave an item stuck in `uploading` indefinitely.
|
||||
- **3.1** [DONE] Persisted the pending documents queue to disk via a new Hive box (`LocalStorage.pendingDocumentsBox`/`savePendingDocument`/`removePendingDocument`/`getAllPendingDocuments`, `lib/core/storage/local_storage.dart`). `PendingDocumentsNotifier` now hydrates from disk on construction and resumes anything not yet terminal: a persisted `uploading` item (fresh capture, or a `retryUpload` interrupted mid-flight) re-runs `_uploadAndProcess` from scratch — safe because the upload endpoint dedupes by file hash server-side — and a persisted `processing` item resumes polling via the newly extracted `_pollUntilParsed`/`_resumePolling` instead of re-uploading. `retrySync`'s own transient flip to `uploading` is deliberately kept in-memory-only (`_updateItemInMemory`) so an interrupted sync-retry resumes as "resend the PUT," not "redo the whole upload." Storage failures are caught and swallowed everywhere (`hydrate`, `_persistPendingDocument`, `_removePersistedPendingDocument`) so a Hive error degrades to the old in-memory-only behavior rather than crashing the queue. Verified via `flutter analyze` (clean) and `flutter test` (no new failures vs. the pre-existing 3-test baseline). Completed 2026-07-08.
|
||||
- **3.2** [TODO] Add a persistent "pending/syncing count" badge visible from the camera screen (not just the `/documents` list), reflecting `pendingDocumentsProvider` state — today a driver who navigates away from `/documents` gets no visibility into background uploads still in progress or stuck in `error`/`syncFailed`.
|
||||
- **3.3** [TODO] Right-size per-request timeouts. *(Description refreshed 2026-07-10 — the original claim "no explicit connect/receive timeout" is stale: `ApiClient` now sets `connectTimeout` 10s / `receiveTimeout` 240s globally, `api_client.dart:14-19`.)* Remaining gap: the 240s receive timeout is sized for the upload's synchronous OCR pass but is inherited by *every* call — a hung 2s-interval poll `GET /documents` can stall one iteration for up to 4 minutes, and login/list calls hang far longer than useful. Pass tighter per-request `Options(receiveTimeout: ...)` on the poll/list/login paths, keeping the long timeout only where the slow parse justifies it. Coordinate with 5.1 (failover needs fast failure).
|
||||
|
||||
### 4. Flutter — Document Editor & PDF Receipt
|
||||
### 4. Flutter — Document Editor & PDF Receipt
|
||||
`lib/features/editor/`
|
||||
|
||||
- **4.1** [TODO] Add an unsaved-changes guard when navigating away from `EditorScreen` with edited-but-unsaved field values. There is currently no `PopScope`/back-navigation interception, so a back-swipe or system back button silently discards manual corrections to OCR'd header/item fields.
|
||||
- **4.2** [TODO] Block save when a line item's SKU isn't in the master registry, instead of only relabeling it for display. The SKU listener in `_addItem` (`editor_screen.dart:108-115`) sets the item name to "SKU Tidak Terdaftar" for an unrecognized SKU but doesn't stop form submission, so a document with an unregistered/mistyped SKU can still be saved and its receipt printed.
|
||||
- **4.3** [TODO] Include the captured GPS coordinates on the printed PDF receipt. `PdfService.generateAndPrintReceipt` (`pdf_service.dart:36-52`) prints header/shipment/item fields but never includes `document.latitude`/`longitude`, even though the editor captures and displays them (`_latitudeCtrl`/`_longitudeCtrl`) — the geotag exists in the data model but isn't part of the audit-trail document a store keeps.
|
||||
- **4.3** [TODO] Include the captured GPS coordinates on the printed PDF receipt. `PdfService.generateAndPrintReceipt` (`pdf_service.dart:36-52`) prints header/shipment/item fields but never includes `document.latitude`/`longitude`, even though the editor captures and displays them (`_latitudeCtrl`/`_longitudeCtrl`) — the geotag exists in the data model but isn't part of the audit-trail document a store keeps.
|
||||
|
||||
### 5. Flutter — Connectivity & Endpoint Resolution
|
||||
### 5. Flutter — Connectivity & Endpoint Resolution
|
||||
`lib/config/app_config.dart`, `lib/core/network/api_client.dart`
|
||||
|
||||
Added 2026-07-08 via a user-directed `e` run ("dual endpoint: local first, public
|
||||
ngrok fallback"). **Current-state audit**: the requested dual-endpoint fallback
|
||||
*already exists at startup* — `AppConfig.initializeApiBaseUrl()`
|
||||
*already exists at startup* — `AppConfig.initializeApiBaseUrl()`
|
||||
(`app_config.dart:32-49`) probes the LAN URL first, falls back to the reserved
|
||||
ngrok domain, and validates each probe is a *real* backend (checks the
|
||||
`ngrok-error-code` header, JSON content-type, and 502/503/504) with the
|
||||
`ngrok-skip-browser-warning` header set. (Root `CLAUDE.md` describes this order
|
||||
backwards — tracked as a doc fix in backend task 5.1d.) These tasks close what's
|
||||
backwards — tracked as a doc fix in backend task 5.1d.) These tasks close what's
|
||||
actually missing:
|
||||
|
||||
- **5.1** [TODO] **Mid-session endpoint failover.** Resolution runs exactly once at
|
||||
startup, and `ApiClient` freezes `baseUrl` at construction of a singleton
|
||||
(`api_client.dart:13`, `apiClientProvider`) — a phone that resolves LAN on Wi-Fi
|
||||
(`api_client.dart:13`, `apiClientProvider`) — a phone that resolves LAN on Wi-Fi
|
||||
and then leaves the building fails every subsequent call with no path back to
|
||||
the ngrok endpoint (and vice versa) until an app restart. Add a Dio interceptor
|
||||
that, on *connectivity-class* failures only (`connectionTimeout`/
|
||||
`connectionError` — not HTTP-level errors), re-runs endpoint resolution and
|
||||
`connectionError` — not HTTP-level errors), re-runs endpoint resolution and
|
||||
retries the request once against the newly resolved endpoint. Implementation
|
||||
notes: the frozen-at-construction `baseUrl` must become dynamic (set
|
||||
`_dio.options.baseUrl` on re-resolution, or read `AppConfig.apiBaseUrl` in the
|
||||
existing `onRequest` interceptor); retry-once is safe for the upload path
|
||||
because the backend dedups by `file_hash` (backend task 1.1), but audit other
|
||||
POST/PUT call sites before blanket-retrying. Coordinate with 3.3 (explicit Dio
|
||||
timeouts) — a hung connection must fail fast enough for failover to matter.
|
||||
timeouts) — a hung connection must fail fast enough for failover to matter.
|
||||
- **5.2** [TODO] **Endpoint status visibility + manual re-probe.** Show which
|
||||
endpoint the app is on (LAN / Public / unreachable) as a small persistent
|
||||
indicator (camera screen or drawer) with a tap-to-re-probe action, so a driver
|
||||
or tester can see and fix "wrong/stale endpoint" in the field without reading
|
||||
logs — a stale tunnel is the documented first failure point for login/upload
|
||||
logs — a stale tunnel is the documented first failure point for login/upload
|
||||
(root `CLAUDE.md`). Re-probe reuses 5.1's resolution path.
|
||||
- **5.3** [TODO] **Make both endpoint URLs configurable without a code edit.**
|
||||
`_lanBaseUrl` and `_ngrokBaseUrl` are compile-time consts — the LAN one is
|
||||
`_lanBaseUrl` and `_ngrokBaseUrl` are compile-time consts — the LAN one is
|
||||
regex-patched by `start-dev-tunnel.ps1` (which breaks silently if the const is
|
||||
renamed/moved; the script warns but the app still ships the stale IP), the ngrok
|
||||
one requires a manual source edit if the reserved domain ever changes. Add a
|
||||
runtime override (e.g. long-press-hidden settings sheet writing to
|
||||
`SharedPreferences`, seeded from the compiled defaults) so a field device can be
|
||||
repointed without rebuilding the APK. Keep the script's patch working (or teach
|
||||
it to fail loudly — backend task 4.3 covers verifying the tunnel end). Once
|
||||
it to fail loudly — backend task 4.3 covers verifying the tunnel end). Once
|
||||
backend task 1.6 ships `GET /api/v1/health`, switch `_isBackendReachable`'s
|
||||
probe to it — probing `POST /auth/login` with an empty body works but couples
|
||||
probe to it — probing `POST /auth/login` with an empty body works but couples
|
||||
reachability to the login route's error shape.
|
||||
|
||||
### 6. Flutter — API Contract & Sync Integrity (DO flow)
|
||||
`lib/features/documents/`, `lib/models/document_model.dart`, `lib/core/network/`
|
||||
|
||||
Added 2026-07-10 via a user-directed `e` run auditing the full frontend↔backend
|
||||
request/response contract. **Read [docs/api-contract-map.md](../docs/api-contract-map.md)
|
||||
first** — it maps every Flutter call site to its backend route, documents both
|
||||
envelopes and the DO document lifecycle, and defines the gap IDs (G1-G10) cited
|
||||
below. Backend counterparts live in `backend/plans/next-enhancements.md` §9 and
|
||||
generally must ship first.
|
||||
|
||||
- **6.1** [DONE 2026-07-10] **Poll a single document with a real parse status
|
||||
instead of scanning the whole list** (G1, G10 client half; unblocked once
|
||||
backend 9.1 shipped `GET /api/v1/documents/:id`). `_pollUntilParsed`
|
||||
(`pending_documents_provider.dart`) now calls `GET /documents/:id` every 2s
|
||||
for the specific pending item's own id instead of fetching and scanning the
|
||||
entire `GET /documents` list — one row + one `ocr_items` query per poll,
|
||||
flat regardless of history size, instead of the old N+1 across the whole
|
||||
list. Added a `parseStatus` field to `DocumentModel` (nullable, populated
|
||||
only by this endpoint) and extracted the branching decision into a new pure
|
||||
function, `resolvePollOutcome()` in
|
||||
`lib/features/documents/poll_outcome.dart` (no Flutter/network imports,
|
||||
mirroring task 6.2's `document_sync_merge.dart` / task 7.1's
|
||||
`product_scan_response_parser.dart` pattern): `parseStatus: "done"` ->
|
||||
success with the fetched document; `"failed"` -> immediate error with an
|
||||
explicit message instead of waiting out the full 260s timeout; `"pending"`
|
||||
or absent (legacy/cached response) -> keep polling. Deleted the old
|
||||
object-identity match trick (`found != doc`). Tests:
|
||||
`test/poll_outcome_test.dart` (4 cases: done/failed/pending/legacy-null).
|
||||
Verified live against the running backend: logged in as a real store
|
||||
account, confirmed `GET /api/v1/documents/:id` for a real document returns
|
||||
exactly the shape `DocumentModel.fromJson`/`resolvePollOutcome` expect
|
||||
(`parseStatus`, `docType`, full header/shipment/items), and that a
|
||||
nonexistent id 404s (handled by the existing catch, polling continues, same
|
||||
as before). See docs/feature-list.md.
|
||||
- **6.2** [DONE 2026-07-10] **Stop wiping locally-saved-but-unsynced documents on
|
||||
refresh** (G6). Acceptance (resolved without a Grill-Me pass — the task's own
|
||||
description already specified the approach): a document with a `syncFailed`
|
||||
pending entry keeps its corrected local version in the history list — visibly
|
||||
flagged, not silently reverted to the server's stale pre-edit copy or dropped.
|
||||
Implemented via a pure, unit-tested merge function,
|
||||
`mergeDocumentsWithUnsyncedOverrides()` in the new
|
||||
`lib/features/documents/document_sync_merge.dart` (deliberately a plain-Dart
|
||||
file with no Flutter/network imports, so the merge rule itself is testable
|
||||
without mocking Dio): for each server-fetched document, a matching
|
||||
`pendingDocumentsProvider` entry with `status == syncFailed` overrides it with
|
||||
the locally-corrected copy (and is kept even if the server list omits that id
|
||||
entirely). `documents_screen._loadDocuments` now persists the *merged* list
|
||||
instead of the raw server list, and tracks which ids were overridden in
|
||||
`_unsyncedDocIds`. `DocumentCard` gained an `isUnsynced` param that swaps its
|
||||
previously-hardcoded "Terkonfirmasi" badge for "Belum Tersinkron" (deepOrange)
|
||||
when set. Tests: `test/document_sync_merge_test.dart` (3 cases: override wins,
|
||||
no-op passthrough, local-only doc kept though absent server-side),
|
||||
`test/document_card_unsynced_badge_test.dart` (2 cases: default vs. flagged
|
||||
badge). See docs/feature-list.md.
|
||||
- **6.3** [DONE 2026-07-10] **Never PUT to a client-generated ID** (G5).
|
||||
- Acceptance (resolved via Grill-Me): when no resolved server document is
|
||||
available, auto-recover by re-uploading the pending item's local image to
|
||||
get a real server-assigned id (safe: server dedups by `file_hash`), then
|
||||
PUT the corrected fields to that real id — rather than blocking outright.
|
||||
G8 (moving `pendingId` off `GoRoute`'s `state.extra`) is explicitly kept
|
||||
out of scope for this pass; it stays open as its own future task.
|
||||
- Both editors previously built
|
||||
`finalDoc.id = _document?.id ?? widget.pendingId ?? now-ms`
|
||||
(`editor_screen.dart` save, `product_editor_logic.dart`); when `_document`
|
||||
was null the PUT targeted `/documents/<13-digit-timestamp>`, which can
|
||||
never match the int4 `documents.id` — the item looped in `syncFailed`
|
||||
forever with no path to recovery.
|
||||
- Extracted the guard into a new pure decision function,
|
||||
`resolveDocumentSaveAction()` in
|
||||
`lib/features/editor/document_save_action.dart` (no Flutter/network
|
||||
imports, same pattern as task 6.1's `poll_outcome.dart`): a resolved
|
||||
`existingDocument` -> PUT to its real id (unchanged happy path); no
|
||||
document but a local image path -> `reuploadThenPut` (re-upload via the
|
||||
same multipart pattern used elsewhere, then PUT); no document *and* no
|
||||
local image -> `blocked` with an explicit user-facing message instead of
|
||||
silently fabricating an id. Both `editor_screen.dart`'s
|
||||
`_submitDocument()` and `product_editor_logic.dart`'s `_submit()` now
|
||||
call this function and branch on its result identically.
|
||||
- **§3 file-size compliance**: touching `editor_screen.dart` (381 lines)
|
||||
and `product_editor_logic.dart` (296 lines) put both over the 256-line
|
||||
threshold, so both were split as part of this change (AGENTS.md §3 binds
|
||||
touched files, not just new ones). `editor_screen.dart` was split into a
|
||||
widget-only file (150 lines) plus a new `editor_logic.dart` mixin
|
||||
(238 lines, `EditorLogic on ConsumerState<EditorScreen>`), mirroring the
|
||||
part-file pattern the product editor already used.
|
||||
`product_editor_logic.dart` itself was replaced by two smaller part
|
||||
files along the same seam it already had internally (data-loading vs.
|
||||
submit): `product_editor_data_logic.dart` (171 lines,
|
||||
`ProductEditorDataLogic`) and `product_editor_submit_logic.dart`
|
||||
(128 lines, `ProductEditorSubmitLogic on ProductEditorDataLogic`).
|
||||
- Tests: `test/document_save_action_test.dart` (3 cases: putExisting,
|
||||
reuploadThenPut, blocked). Verified live against the running backend: ran
|
||||
the full recovery sequence by hand (multipart re-upload of a real test
|
||||
image -> real server id returned -> PUT corrected fields to that id ->
|
||||
GET confirms the correction persisted), proving the recovery path is a
|
||||
genuine save, not a dead end. See docs/feature-list.md.
|
||||
|
||||
### 7. Flutter — Product Scan Review Flow
|
||||
`lib/features/editor/product_editor_screen.dart` + `product_editor_logic.dart` + `widgets/product_*`, `lib/features/camera/scan_mode_provider.dart`
|
||||
|
||||
Added 2026-07-10, same contract audit (gap IDs from
|
||||
[docs/api-contract-map.md](../docs/api-contract-map.md)). The product review flow
|
||||
shipped 2026-07-09 works on the happy path but is wired to non-production
|
||||
endpoints and placeholder data.
|
||||
|
||||
- **7.1** [DONE 2026-07-10] **Move the product editor onto the authenticated
|
||||
`/api/v1/*` surface** (G2). `_fetchClassificationAndSkus` now calls `GET
|
||||
AppConfig.masterSkusEndpoint` (`/master/skus`) and `POST
|
||||
AppConfig.scanProductEndpoint` (`/scan-product`) — both new endpoint
|
||||
constants in `app_config.dart` — instead of string-hacking the base URL to
|
||||
reach the classic unauthenticated `/api/skus`/`/api/scan-pfm` dev routes.
|
||||
The `Authorization` header is attached automatically by `ApiClient`'s
|
||||
existing request interceptor (`api_client.dart:32-41`), same as every other
|
||||
v1 call site. Also switched the classification call from a base64 JSON body
|
||||
to multipart (`FormData`/`MultipartFile`, the same pattern already used for
|
||||
DO uploads in `pending_documents_provider.dart`) — backend 9.3 was built to
|
||||
prefer this specifically to avoid shipping a multi-MB base64 payload.
|
||||
Extracted the "unwrap the v1 `{status,data}` envelope" logic into a new pure
|
||||
file, `lib/features/editor/product_scan_response_parser.dart`
|
||||
(`parseSkuMasterList`/`parseScanProductResponse`), mirroring task 6.2's
|
||||
`document_sync_merge.dart` pattern so the parsing logic is unit-testable
|
||||
without mocking Dio. Tests: `test/product_scan_response_parser_test.dart`
|
||||
(6 cases covering both envelope shapes, empty lists, and missing `ocr`).
|
||||
Verified live against the running backend stack: a real store account's
|
||||
token succeeds against `GET /api/v1/master/skus` (232 real SKUs, matching
|
||||
envelope shape) and `POST /api/v1/scan-product` (multipart, real
|
||||
classification + top-5 matches) — see backend docs/iteration-log.md's task
|
||||
9.3 entry for the matching server-side verification. Full `flutter test`
|
||||
suite (36 tests) and `flutter analyze lib` clean, no regressions. See
|
||||
docs/feature-list.md.
|
||||
- **7.2** [DONE 2026-07-10] **Classify each product photo once, not twice**
|
||||
(G3). Resolved via user feedback ("kenapa harus dilakukan dua kali... GPU
|
||||
tidak 2x kerja") after noticing Product Scan's editor took visibly longer
|
||||
to open than DO Scan's -- decision matched this task's own "consume the
|
||||
stored parse result" option (the other, "skip classification at upload,"
|
||||
was rejected: the user explicitly wants Product Scan's editor to open the
|
||||
same way DO's does -- instantly, from already-complete data).
|
||||
- Backend counterpart (see `backend/plans/next-enhancements.md` §11):
|
||||
`api/parse/route.ts`'s Product branch now calls the same shared
|
||||
`classifyAndMatchProduct()` util `POST /api/v1/scan-product` already
|
||||
used (task 9.3), instead of its own poorer inline classify call that only
|
||||
kept `top1_name`/`extracted_sku`. The full result -- top-5
|
||||
`possibleMatches` and OCR `extractedExpiryDate` -- is now persisted in
|
||||
`documents.metadata.productScan` (JSONB, no migration) and surfaced by
|
||||
`document-mapper.ts` on every GET response.
|
||||
- `lib/models/document_model.dart` gained `productScanMatches`/
|
||||
`productScanExtractedExpiryDate`, parsed from the new `productScan` key
|
||||
(empty defaults for DO documents or pre-fix Product documents).
|
||||
- `product_editor_data_logic.dart`'s `_fetchClassificationAndSkus()` no
|
||||
longer re-uploads the image to `/scan-product` at all -- it reads
|
||||
`_document.productScanMatches`/`productScanExtractedExpiryDate`
|
||||
synchronously (mirrors `EditorScreen._loadDocumentData()`'s instant
|
||||
local-state read exactly), and only falls back to a *cheap* `GET
|
||||
/master/skus` (a plain DB read, no GPU) when the document has zero
|
||||
stored matches (e.g. a pre-fix document, or nothing scored above the
|
||||
match threshold). `_loading` no longer starts `true` -- no spinner on the
|
||||
happy path.
|
||||
- Tests: `test/document_product_scan_field_test.dart` (3 cases, the new
|
||||
`DocumentModel` fields), `test/product_editor_no_double_classify_test.dart`
|
||||
(proves a document with stored matches renders immediately with no
|
||||
network call -- seeds a raw pending-queue JSON blob with `productScan`
|
||||
already populated and asserts the SKU/confidence UI appears without
|
||||
hitting the sandboxed-test-network 400 path that would fire if a second
|
||||
classify call were attempted). `test/product_editor_classification_failure_test.dart`
|
||||
(pre-existing) continues to pass unchanged -- a `pendingId: null` document
|
||||
has no stored matches, so it now exercises the *fallback* path instead of
|
||||
the old always-on classify path, hitting the same sandboxed 400 and
|
||||
showing the same retry state. Full suite 63/63 pass, `flutter analyze`
|
||||
clean.
|
||||
- Verified live against the running backend: uploaded a genuinely fresh
|
||||
image/store combination as Product Scan -- took 9s (one real GPU
|
||||
classify+match pass, confirmed not a dedup hit via the response's
|
||||
"Document uploaded successfully" message) -- then `GET /documents/:id`
|
||||
immediately returned 5 real `possibleMatches` and the extracted expiry
|
||||
date, before any editor interaction. See docs/iteration-log.md.
|
||||
- **7.3** [DONE 2026-07-10] **Replace magic-string typing and silent
|
||||
mock data** (G4 client half + G7). Split into two independent halves at pickup
|
||||
(per the Grill-Me step — the two halves have different blockers):
|
||||
- **G7 half — DONE 2026-07-10, no backend dependency.** The editor silently
|
||||
fabricated data in three places, all presented as if it were real AI/OCR
|
||||
output: three hardcoded SKU "matches" with fake confidences on any total
|
||||
fetch failure (old `product_editor_logic.dart:116-126`); fake batch dates
|
||||
`'15/12/2026'/'20/04/2027'` whenever OCR extracted no expiry (old line 103);
|
||||
and — found during this pass, same bug class, same screen —
|
||||
`ProductExpiryCard`'s "OCR Confidence Score" was a **literal hardcoded
|
||||
92.4%**, unconditional, not derived from any real signal at all (there
|
||||
is none - `classify_ocr_server.py`'s OCR result has no confidence field
|
||||
for the expiry extraction). Fixed by: distinguishing "SKU master list
|
||||
itself failed to load" (the one truly-blocking failure, now surfaced as
|
||||
an explicit "Gagal Memuat Klasifikasi Produk" + Coba Lagi retry state,
|
||||
`ProductEditorScreen._buildFailureState()`) from "classification call
|
||||
failed but the master list loaded fine" (now degrades to manual
|
||||
SKU selection from the master list, flagged via new `_hasAutoMatch`,
|
||||
with the fake confidence UI replaced by an honest "Tidak ada rekomendasi
|
||||
otomatis" notice in `ProductDropdownCard`); no expiry match no longer
|
||||
seeds fake dates, instead forcing `_isManualDate = true`
|
||||
(`_updateBatchOptions()`); and `ProductExpiryCard`'s fake 92.4% was
|
||||
replaced with a real, honest label ("Tanggal terdeteksi otomatis dari
|
||||
OCR" vs "Tanggal diinput manual") since there's no real confidence value
|
||||
to show. Tests: `test/product_dropdown_card_test.dart`,
|
||||
`test/product_expiry_card_test.dart`,
|
||||
`test/product_editor_classification_failure_test.dart`. See
|
||||
docs/feature-list.md.
|
||||
- **G4 half — DONE 2026-07-10, unblocked by backend 9.1 shipping (verified
|
||||
against the actual code, not assumed - `backend/pfm-web-app/src/utils/
|
||||
document-mapper.ts`'s `mapDocumentRow()` now returns `docType`/
|
||||
`parseStatus`, and all three v1 document routes use it).** Added a real
|
||||
`docType` field to `DocumentModel` (`lib/models/document_model.dart`),
|
||||
read from the backend's `docType` in `fromJson`, falling back to the
|
||||
legacy `orderUntuk == 'PRODUCT SCAN'` sentinel only for responses/cached
|
||||
Hive rows that predate the column (mirrors the backend's own fallback).
|
||||
Replaced every `orderUntuk == 'PRODUCT SCAN'` type check with
|
||||
`docType == 'Product'`: `document_card.dart`, `documents_screen.dart`
|
||||
(tab filter), `pdf_service.dart` (receipt layout),
|
||||
`product_editor_logic.dart` (`_loadDoDocs` PO-candidate filter, and the
|
||||
product-scan `_submit()` now explicitly sets `docType: 'Product'` instead
|
||||
of relying on the `orderUntuk` display string alone). Editing the
|
||||
`orderUntuk` display field can no longer move a document between tabs.
|
||||
Test: `test/document_doctype_test.dart` (3 `fromJson` cases + 1 widget
|
||||
regression test specifically reproducing the old bug's trigger - a doc
|
||||
with `docType: 'Product'` but an edited, non-matching `orderUntuk` still
|
||||
renders as Product). See docs/feature-list.md.
|
||||
|
||||
### 8. Flutter — Scan Mode UX & Confirmation Gate
|
||||
`lib/features/camera/scan_mode_provider.dart`, `lib/features/documents/`, `lib/config/app_config.dart`, `lib/models/document_model.dart`
|
||||
|
||||
Added 2026-07-10 from user testing feedback on the release APK
|
||||
([`twinkly-riding-mitten.md`](../../../Users/rafha/.claude/plans/twinkly-riding-mitten.md)).
|
||||
Three issues found: (1) `scanModeProvider` and `DocumentsScreen._selectedTab` are
|
||||
independent, causing mode desync across screens; (2) documents appear in history
|
||||
before the user taps "Simpan & Konfirmasi" because `parsed=true` is set at OCR
|
||||
completion not at user confirmation; (3) Product Scan stores fabricated PO/SO/DO
|
||||
placeholder values. Backend §10.1/§10.2 shipped 2026-07-10, unblocking 8.2.
|
||||
See [docs/api-contract-map.md](../docs/api-contract-map.md) **G11**, **G12** for
|
||||
root-cause documentation. §8 is now fully `[DONE]`.
|
||||
|
||||
- **8.1** [DONE] **Global scan-mode state + DO/Product color cue.** Make
|
||||
`scanModeProvider` the single source of truth bidirectionally: remove
|
||||
`_selectedTab` from `DocumentsScreen` entirely (replace reads with
|
||||
`ref.watch(scanModeProvider)`, replace writes with
|
||||
`ref.read(scanModeProvider.notifier).state = tab`). Formalize the existing
|
||||
ad-hoc `Colors.orange.shade700` in `document_card.dart:28` as
|
||||
`AppConfig.doModeColor`, then apply it as the active-state color in
|
||||
`DocumentsTabSwitcher._buildTabItem` (DO tab) and in the camera drawer's
|
||||
DO segment decoration (was `primaryColor` for both segments). Product stays
|
||||
`AppConfig.primaryColor`. Scope: Flutter-only, no backend dependency.
|
||||
- Tests: (a) widget test that tapping "Product Scan" tab updates
|
||||
`scanModeProvider` (read via `ProviderContainer`, not local widget state);
|
||||
(b) widget test that tab switcher active color = `doModeColor` when `'DO'`,
|
||||
`primaryColor` when `'Product'`; (c) widget test camera drawer DO segment
|
||||
decoration = `doModeColor` when provider = `'DO'`.
|
||||
- **Follow-up (same day)**: user clarified the icon should carry the mode
|
||||
color too, not just the button/text, while explicitly leaving default
|
||||
chrome (tooltips, etc.) untouched. Added `Icons.description`/
|
||||
`Icons.inventory_2` to `DocumentsTabSwitcher` (matching
|
||||
`CameraDrawerModeToggle`'s existing vocabulary), colored identically to
|
||||
the tab's text. Tests added to `test/scan_mode_color_test.dart` (3 new
|
||||
cases: DO active icon color, Product active icon color, inactive icon
|
||||
stays neutral gray).
|
||||
|
||||
- **8.2** [DONE 2026-07-10] **Flutter half of confirmation-gated document
|
||||
visibility.** Backend §10.1 shipped first (adds `confirmed` column + filters
|
||||
list to `confirmed = true`). Added optional `bool confirmed` (default
|
||||
`true`) to `DocumentModel`, read from `json['confirmed']` with the same
|
||||
default-true fallback pattern as `docType`/`parseStatus` — so a
|
||||
legacy/cached response without the field behaves as before. No other
|
||||
Flutter changes needed, verified rather than assumed:
|
||||
`mergeDocumentsWithUnsyncedOverrides()` (task 6.2) already keeps `syncFailed`
|
||||
local copies visible even when the server list omits them (which it now
|
||||
legitimately will for unconfirmed docs), and
|
||||
`pending_documents_provider.dart`'s "Tertunda & Diproses" section already
|
||||
shows in-flight items from local state regardless of server confirm status.
|
||||
- Tests: `test/document_confirmed_field_test.dart` (3 cases: reads a real
|
||||
`confirmed: false` from JSON, defaults to `true` when the key is absent,
|
||||
defaults to `true` via the plain constructor too) — same shape as
|
||||
`test/document_doctype_test.dart`. Full suite 58/58 pass, `flutter
|
||||
analyze` clean. Live-verified against the real backend response shape
|
||||
(see backend `docs/iteration-log.md`'s task 10.1/10.2 entry).
|
||||
|
||||
---
|
||||
|
||||
*Sections 1-5 (Flutter) are the only sections this file tracks. Backend
|
||||
*Sections 1-8 (Flutter) are the only sections this file tracks. Backend
|
||||
enhancements (formerly sections 5-8 here, removed 2026-07-08) now live
|
||||
exclusively in [backend/plans/next-enhancements.md](../backend/plans/next-enhancements.md).*
|
||||
exclusively in [backend/plans/next-enhancements.md](../backend/plans/next-enhancements.md);
|
||||
that file's §9 holds the backend counterparts to this file's §6-7, and §10
|
||||
holds the backend counterparts to this file's §8 (see
|
||||
[docs/api-contract-map.md](../docs/api-contract-map.md) for the shared gap IDs).*
|
||||
|
||||
Reference in new issue
Block a user