OPN · Stock Opname
A stock opname (a stock count) is a session in which a checker scans the cars on a pool's floor, and the system compares the scans with the list of cars it took when the count started (D75, D93). v1 already holds it: one session and 111 expected cars on the copy of 2026-10-23, and a third table, stock_opname_scans, with no rows. v2 no longer rebuilds it as v1 has it: D93 gives it one mode, scanning the floor against the list, keeps every scan, and makes each missing car an alert until the checker team rechecks it. The tables and the permission codes come first, in the data phase (timeline rows 0g and 0k); the snapshot, scanning, finishing, voiding, rechecking and the page with its alerts are M5's. A scanned car that wasn't on the list is extra, never "unchecked", which is a car status (glossary). Code OPN.
Answered questions
Section titled “Answered questions”- What Stock Opname is (#320, question 1): a session counts the cars expected at a place, and each expected car is scanned or not. zuki: "it's as you read", with
opname:readadded. - Rebuilt in M5, with
opname:readandopname:write(questions 2 to 4): D75; the codes are R-ACC-88 and R-ACC-89 on the Access page. - Stock Opname as a new flow (#416, #321): answered by D93. The questions that stood here close with it:
- The scans table and the extra count: the scans table comes back, and a session counts extra cars, known and unknown, from it (R-OPN-06, R-OPN-08, R-OPN-16, R-OPN-17).
- A session's statuses: open, finished and void, as R-OPN-02 proposed; D93 says what each means.
- v1's mode: a session has no mode (R-OPN-01). v1's
list_to_flooris still read, so a new v1 mode stops the night (R-OPN-11, R-MIG-02). - Who started and who scanned: v1's
started_bystays text and stays signed as ignored (R-OPN-14, R-MIG-10). v1 has no scan, so itsscanned_byloads nothing; a v2 scan records its member (R-OPN-06). - What the assignee is: a session may have one, a member, or none (R-OPN-01); v1's
assignedis empty and signed as ignored (R-OPN-14). Who is assigned when is M5's.
R-OPN-01 · A stock opname session belongs to one pool, with an optional assignee, deadline and note
Section titled “R-OPN-01 · A stock opname session belongs to one pool, with an optional assignee, deadline and note”- Status: built
- Example: given pool PML, when a session is started there, then it belongs to PML, and is readable and writable only by members holding opname:read or opname:write at PML (R-ACC-09, R-OPN-09, R-OPN-10). It has no mode. It may have no assignee, deadline or note, as v1's one session has none.
- Refusal: none: not_null_violation (23502) on a session with no pool.
- Who: every writer.
- Source: D75; D93 (one mode, so the mode column is dropped; #585); #320 (assignee, deadline); the shapes on #262 (BE-DP-20). The pool is v2's: v1 has none.
R-OPN-02 · A session is open, finished or void
Section titled “R-OPN-02 · A session is open, finished or void”- Status: built
- Example: given a session just started, then it is open; once finished it is finished, and once abandoned it is void. A fourth status is refused.
- Refusal: none: invalid_text_representation (22P02) on a status outside the enum.
- Who: every writer.
- Source: D75; D93 (open while counting, finished when the checker closes it, void when it is abandoned, with a reason); v1's one session is void. The three statuses were the proposal on #321.
R-OPN-03 · A session that is finished or void has a finish time, and an open one has none
Section titled “R-OPN-03 · A session that is finished or void has a finish time, and an open one has none”- Status: built
- Example: given an open session, when it is saved with a finish time, then it is refused; given a void session, when it is saved with none, then it is refused. v1's void session has a finish time.
- Refusal: none: check_violation (23514).
- Who: every writer.
- Source: D75; the shapes on #262 (finished_at is set on the one session).
R-OPN-04 · A car is expected at most once in a session
Section titled “R-OPN-04 · A car is expected at most once in a session”- Status: built
- Example: given session S lists car U-3 as expected, when U-3 is added to S again, then it is refused; it can be expected in another session.
- Refusal: none: unique_violation (23505).
- Who: every writer.
- Source: D75; #320 (each expected row is a car).
R-OPN-05 · An expected car records the car's status when the session was made, as a vehicle status
Section titled “R-OPN-05 · An expected car records the car's status when the session was made, as a vehicle status”- Status: built
- Example: given car U-3 is ready when session S is made, when S lists it as expected, then the expected row says ready, and U-3 becoming rented later does not change it. A car under repair is recorded as maintenance and a car back without its BASTK as unchecked (D91, D92); a status outside the vehicle statuses is refused.
- Refusal: none: invalid_text_representation (22P02).
- Who: every writer; the module's function that starts a session fills it.
- Source: D75; the shapes on #262: v1's expected rows hold the car's status label ("4. Ready"), the labels the vehicles step already maps onto vehicle_status (R-VEH-28).
R-OPN-06 · A scan records what it read, whether it was typed, whether it is a recheck, who scanned it and when
Section titled “R-OPN-06 · A scan records what it read, whether it was typed, whether it is a recheck, who scanned it and when”- Status: built
- Example: given an open session at PML, when a checker scans car U-3's QR code, then a scan row holds the unit code read, not typed, not a recheck, the checker and the time. When a QR code can't be read and the checker types the plate B1234XYZ, the row holds the plate and is marked typed, so the counts say how many were typed (R-OPN-08). A scan with nothing read, or with no member or time, is refused, and so is one whose read is empty or only spaces. For an app user (auth.uid() is set), the member and time are stamped by the database from auth.uid() and now(), whatever the writer sends; the migration and service_role keep what they send.
- Refusal: none: not_null_violation (23502) on a missing read, member or time; check_violation (23514) on a blank read.
- Who: every writer; the module's scan function fills it (M5).
- Source: D93 (the scans table comes back: per scan, the code or plate, whether it was typed, the car, the expected row, whether it is a recheck, who and when; #585). It replaces the scan columns of the expected row (scanned, scanned_at, scanned_by), which go.
R-OPN-07 · A scan is a recheck exactly when its session is finished
Section titled “R-OPN-07 · A scan is a recheck exactly when its session is finished”- Status: built
- Example: given session S is finished, when a checker saves a scan on it that isn't a recheck, then it is refused; a recheck scan on S is accepted. Given session T is open, a scan that isn't a recheck is accepted and a recheck scan is refused, as no car is missing until the count finishes (R-OPN-20).
- Refusal: opname.session_finished on a scan that isn't a recheck in a finished session; opname.recheck_not_finished on a recheck scan in an open session, the key of R-OPN-20.
- Who: every writer, the module's scan function included.
- Source: D93 (a finished count's numbers are final, and it takes recheck scans only; #585); zuki, 2026-11-16, in the session on #584: an open session refuses a recheck scan. Replaces "an expected car of a finished or void session can't be scanned", whose void half is R-OPN-18.
R-OPN-08 · A session's counts are computed from its expected cars and its scans that aren't rechecks, never stored
Section titled “R-OPN-08 · A session's counts are computed from its expected cars and its scans that aren't rechecks, never stored”- Status: built
- Example: given a finished session with 111 expected cars, of which 100 were scanned (3 of them by a typed plate), and scans of 2 cars from another pool and of 1 code that finds no car, then it reads 111 expected, 100 matched, 11 missing, 2 extra known, 1 extra unknown and 3 typed. A car scanned twice counts once, and so do extra known cars: each is a distinct car. Extra unknown counts each distinct read once, so a code read twice is 1. Typed counts the matched cars none of whose scans read the QR code: a car scanned once by its QR and once by a typed plate is not typed. A recheck scan that finds a missing car changes none of these (R-OPN-19 records it); while the session is open, a car not yet scanned counts as missing, and scanning it changes the counts at once, with nothing to update.
- Refusal: none.
- Who: the view or function that reads a session (M5); the reconcile's computed counts (R-OPN-13).
- Source: D32 (a derived fact is computed); D93 (matched, missing, extra known car and extra unknown; recheck scans don't change the count's own numbers; #585); #320; v1 stores the counts, which the reconcile compares (R-OPN-13). The screens call both extra outcomes extra, never "unchecked".
R-OPN-09 · Reading a session, its expected cars and its scans needs opname:read at the session's pool
Section titled “R-OPN-09 · Reading a session, its expected cars and its scans needs opname:read at the session's pool”- Status: built
- Example: given a viewer holding opname:read at PML, when they read PML's sessions, their expected cars and their scans, then those come back; a member without opname:read gets none, and nobody reads another pool's.
- Refusal: none: hidden.
- Who: super_admin, admin, admin_fleet, checker and viewer hold opname:read (R-ACC-88).
- Source: D75; R-ACC-09 and R-ACC-11 (an expected car and a scan are scoped by their session's pool); D93 (the scans table).
R-OPN-10 · Starting, changing, scanning and rechecking a session needs opname:write at the session's pool
Section titled “R-OPN-10 · Starting, changing, scanning and rechecking a session needs opname:write at the session's pool”- Status: built
- Example: given a viewer holding only opname:read at PML, when they start a session, scan a car or confirm a car missing, then it is refused; a checker holding opname:write at PML can. A scan once saved is never changed or deleted by an app user, whatever they hold: app users insert and read scans only.
- Refusal: none: insufficient_privilege (42501) on a row-level write, or no effect; an update or delete of a scan has no effect.
- Who: super_admin, admin, admin_fleet and checker hold opname:write (R-ACC-89).
- Source: D75; R-ACC-10.
R-OPN-11 · The operations step loads each v1 session and its expected cars as history, keyed by v1's ids
Section titled “R-OPN-11 · The operations step loads each v1 session and its expected cars as history, keyed by v1's ids”- Status: built
- Example: given v1's one session with 111 expected rows, when the operations step has run twice, then v2 holds one session and 111 expected cars, with the same ids both times (R-MIG-03). The session keeps its v1 status and finish time, so a void one stays void. v1's mode is read through value_map only to check it is list_to_floor, and stored nowhere, as a session has no mode (R-OPN-01); a mode with no value_map row stops the step (R-MIG-02), so a new v1 mode is never loaded as if it meant the same.
- Refusal: none.
- Who: the data phase's operations step (#304), after Stock Opname's tables (timeline row 0g).
- Source: D75; #320 (v1's session and expected rows load as history in the operations step); R-MIG-03; D93 (v1's mode is still read; #585). The example widens; the ID and the rule stay. If the session is a trial, zuki signs it out as an accepted difference (R-MIG-06).
R-OPN-12 · A v1 expected row whose car can't be found is an unmatched row
Section titled “R-OPN-12 · A v1 expected row whose car can't be found is an unmatched row”- Status: built
- Example: given a v1 expected row whose unit_id finds no car in id_map, and whose plate finds none either (R-VEH-30), when the operations step runs, then the row is listed in migration.unmatched with its reason (R-MIG-04) and no expected car is made for it; the rest of the session loads. A row whose unit_id finds a car loads against that car.
- Refusal: none.
- Who: the data phase's operations step.
- Source: R-MIG-04; R-VEH-28 and R-VEH-30 (a car is found by its unit_id, then by any plate it has carried). Which of the two wins when they name different cars is not decided here; BE counts such rows on #304 (counts only).
R-OPN-13 · The reconcile compares each loaded session's stored counts with v1's
Section titled “R-OPN-13 · The reconcile compares each loaded session's stored counts with v1's”- Status: built
- Example: given v1's session says 111 expected, 0 matched and 0 missing (its stored missing count on the copy of 2026-11-03; 111 on the earlier copy of 2026-10-29), when the reconcile runs, then it compares them with the counts computed from the loaded expected cars (R-OPN-08), and lists a session whose counts differ, unless zuki signed the difference (R-MIG-05, R-MIG-06): the 111 missing it computes against v1's 0 is listed under
operations stock opname counts, and zuki on #304 (2026-11-03) signed it. - Refusal: none.
- Who: the operations step's reconcile check.
- Source: D18; D32 (v2 doesn't store the counts v1 stored).
R-OPN-14 · The one v1 session's 111 expected cars load unscanned, and v2 computes 111 expected, 0 matched and 111 missing from them
Section titled “R-OPN-14 · The one v1 session's 111 expected cars load unscanned, and v2 computes 111 expected, 0 matched and 111 missing from them”- Status: built
- Example: given v1's void session with 111 expected cars on the earlier copy of 2026-10-29, all of which find their unit and their plate (111 of 111) and all of which are in Jakarta (v1's service_area, the pool jakarta, named Jakarta in master data), when the step runs, then the session loads at the pool Jakarta, the home pool its cars share (the pool is v2's choice, as v1 has none, R-OPN-01), R-OPN-12 lists none, 111 expected cars load with no scan and no recheck outcome (R-OPN-06, R-OPN-19), and the counts computed from them read 111 expected, 0 matched and 111 missing, with no extra (R-OPN-08). v1's stored counts were the same on the earlier copy, but by the copy of 2026-11-03 its stored missing count had changed to 0 (111, 0 and 0), so the reconcile lists the difference under
operations stock opname counts(R-OPN-13), and zuki on #304 (2026-11-03) signed it (R-MIG-06). v1's stock_opname_scans has no row, so no scan loads (D93); a v1 expected row marked scanned loads unscanned and is listed in migration.unmatched as scanned in v1 by text that isn't a member (R-MIG-04). The session'sstarted_byandassignedand the expected cars'vehicleare text, not members or cars, and are not read: the car is found by its unit (R-OPN-12), and the three columns are signed as ignored (R-MIG-10; zuki on #439 (2026-11-03)). - Refusal: none.
- Who: the data phase's operations step (#304)
- Source: #356; the CTO's reading of BE-DP-35 on #356 (2026-10-30: one void session, 111 expected cars, all found, 0 scans); R-OPN-06, R-OPN-11, R-OPN-12, R-OPN-13. The missing count's difference: zuki on #304 (2026-11-03), signed; R-MIG-06.
R-OPN-15 · A pool has at most one open session
Section titled “R-OPN-15 · A pool has at most one open session”- Status: built
- Example: given an open session at PML, when a second session is started at PML, then it is refused; once the first is finished or void, a new one is accepted, and a session at SBY is accepted meanwhile. v1's one session is void, so the load is untouched.
- Refusal: none: unique_violation (23505).
- Who: every writer.
- Source: D93 (one open count per pool; it counts the cars at that pool and no other); #585.
R-OPN-16 · A scan whose code or plate finds no car is saved with no car
Section titled “R-OPN-16 · A scan whose code or plate finds no car is saved with no car”- Status: built
- Example: given an open session at PML, when the checker scans a code that is no car's unit code, then the scan is saved with the code and no car, and counts as extra unknown (R-OPN-08); a scan that finds car U-3 names U-3.
- Refusal: none.
- Who: every writer; the module's scan function finds the car (M5).
- Source: D93 (every scan is saved, including one whose code or plate finds no car); #585.
R-OPN-17 · A scan matches its session's expected row for its car, filled by the database; a scan with no car, or of a car not on the list, matches none
Section titled “R-OPN-17 · A scan matches its session's expected row for its car, filled by the database; a scan with no car, or of a car not on the list, matches none”- Status: built
- Example: given session S lists car U-3, when scan X of U-3 is saved in S, then X matches S's expected row for U-3, whatever expected row the writer passed, another session's or S's row for U-4 included, or none. A scan with no car, or of a car not on S's list, matches none and is extra (R-OPN-08), even when the writer named a row.
- Refusal: none: the database sets the match and ignores the writer's value.
- Who: every writer.
- Source: D93 (per scan, the expected row it matched); #585; R-OPN-04 (a car is expected once in a session); the lead in the session on #584, 2026-11-16, after be's review: a foreign key can't hold a scan with no car to no row, so a trigger fills the match (D3).
R-OPN-18 · A void session takes no scan
Section titled “R-OPN-18 · A void session takes no scan”- Status: built
- Example: given session S is void, when a checker saves any scan on it, a recheck included, then it is refused; its counts are ignored and it raises no alert.
- Refusal: opname.session_void
- Who: every writer, the module's scan function included.
- Source: D93 (void when abandoned, with a reason: its counts are ignored and it raises no alert); #585. The void half of the earlier R-OPN-07.
R-OPN-19 · An expected car's recheck outcome is found or confirmed missing, and a confirmed missing car has a note
Section titled “R-OPN-19 · An expected car's recheck outcome is found or confirmed missing, and a confirmed missing car has a note”- Status: built
- Example: given a finished session where car U-3 was missing, when a recheck scan finds it, then its expected row reads found; when a checker confirms it missing with the note "not at the pool, last out on 2026-11-10", then it reads confirmed missing. Confirmed missing with no note is refused, and a third outcome is refused. A car with no outcome is still an alert; a session with no alert left is settled, which is computed. The table doesn't refuse an outcome on a car matched in the count, found with no recheck scan behind it, or a change to an outcome once set: M5's recheck functions decide those. The outcome's note is its own (recheck_note), apart from v1's note on the expected row.
- Refusal: none: check_violation (23514) on a confirmed missing car with no note; invalid_text_representation (22P02) on another outcome.
- Who: every writer; the module's recheck functions set it (M5).
- Source: D93 (a recheck scan marks it found, or a checker confirms it missing, with a note; a confirmed missing car is recorded and nothing more follows); #585.
R-OPN-20 · An expected car takes a recheck outcome only while its session is finished
Section titled “R-OPN-20 · An expected car takes a recheck outcome only while its session is finished”- Status: built
- Example: given an open session, when one of its cars is confirmed missing, then it is refused, as no car is missing until the count finishes; on a void session it is refused too. In a finished session it is accepted.
- Refusal: opname.recheck_not_finished
- Who: every writer, the module's recheck functions included.
- Source: D93 (missing means not scanned when the count finishes; a void session raises no alert); #585.