Changing a product's tracking
Changing a product’s tracking (stock addon)
Section titled “Changing a product’s tracking (stock addon)”Developer page for the tracking conversion check. The decision lives in erp_addon_stock::tracking; the product’s
tracking field and its write path belong to the lot work (planned), which calls it.
The call
Section titled “The call”use erp_addon_stock::tracking::{Tracking, TrackingChange, check_tracking_change};
check_tracking_change(tx, &[TrackingChange { product_id, from: Tracking::Serial, to: Tracking::Lot }]).await?;Call it from the write path of tracking, in the transaction of the write, with every product the write touches
(one call per write, not one per product: it runs one query per kind for the whole batch). A refusal is a
Validation error; the write rolls back with the transaction. Tracking::from_selection reads the stored selection
(empty is untracked) and refuses any other value.
What it decides
Section titled “What it decides”| From | To | Result |
|---|---|---|
| any | the same | allowed |
| untracked | lot | allowed; stock already on hand stays without a lot (the client may show the reference’s hint) |
| lot | untracked | allowed; lots stay on their quants and lines |
| serial | untracked, lot | refused while a serial number is on hand or on an open line |
| lot, untracked | serial | refused while a lot is on hand or on an open line (checked on the new mode, so lot to untracked to serial cannot get round it) |
Counted: serial positions and lot quants of non-zero quantity, open active lines (serial children, or plain lines naming a lot). Not counted: zero quantity rows, done lines, inactive children. A lot or serial number counts once however many rows name it. Cases: SPEC-STOCKLEDGER-031, -037, -038, SPEC-STOCKOPS-064.
The refusal text is ADR 0139 D5.6’s: it names the product, the number found and says that converting existing stock is not available yet.
Words it from StockError::TrackingChangeBlocked, so a caller never builds its own sentence.
What waits
Section titled “What waits”Converting the refused cases needs the writers of serial positions and open serial children (planned). No setting is involved: the decision has no threshold. The count is exact, not capped; it reads
the rows of the named products only (unmeasured, DEFERRED_PERFORMANCE).