Files
SGF/packages/inventory-write/README.md
T
2026-11-23 11:48:07 +02:00

20 lines
3.2 KiB
Markdown

# Receipt movement writer
## Development extension authorised on 21 November 2026
The owner authorised preparing unit conversion in development/QA only. The working source now recognises an optional `quantity_conversion` receipt-line snapshot (`inventory.quantity.v1`): documentary/base units, explicit positive rational factor, source/version, original article and both accepted quantities in integer millesimals. The same writer validates the exact conversion and writes/replays one physical movement. Without that snapshot, the facts, source hash and receipt quantity are unchanged. Published `releases/0.1.0` is untouched.
`QuantityConversion` is the sole exact arithmetic implementation; it rejects nonrepresentable quantities and integer overflow. It never converts prices. The host still validates/freezes the basis, unit mapping and actor under its company lock, and retains original order/receipt/invoice quantities and prices. The prepared Compras adaptation freezes the basis on the first accepted receipt for an order line/article, then requires it on subsequent portions; lots/issues use base units and supplier returns preserve the exact documentary equivalent.
Compras holds a hash-pinned **development artifact**, not a published release. Its loader refuses this artifact outside `testing` and a guarded disposable database; default configuration remains off. No installation, activation or operational change in SGF or the pilot is authorised or performed. Different writer versions require separate kernels. Test results and remaining criteria are recorded in the existing Compras delivery trackers.
`ReceiptMovementWriter` is the single extracted writer for a new accepted physical receipt line. Source code comes from the former insert in Purchasing `ReceiptWorkflow`; versioned artifacts are distributed locally, verified by manifest and never replaced with different contents.
The host owns the company lock, current actor/policy/conflict checks, order eligibility, quantities/units/quality, explicit warehouse/item mapping, lots, downstream signals and audit. It must call the writer within that same transaction, with an authorisation callback. The writer is not a public receipt intake API and must not be used to reconstruct/backfill historical effects or bypass `ReceiptWorkflow`.
The writer reads the scoped receipt/line, checks physical acceptance and original receiver, freezes a source hash, locks/revalidates that hash and writes one `receipt_in` using the existing unique `goods_receipt_item_id`. It preserves the original snapshot and adds origin hash/reference. A compatible receipt with the same hash reuses its movement. A stale hash or a legacy/incompatible existing movement is refused; old rows are never rewritten/adopted automatically. Parent final status/number are excluded from the hash because native finalisation occurs later in the same transaction.
No independent commit, second balance or audit engine is introduced. Failure after insert rolls back with the host's receipt/lots/audit. Stock issues, transfers, corrections, consumption, payments and accounting are not implemented here. Tested on isolated PostgreSQL; no other-driver or deployment claim.
See [delivery and evidence](../../docs/STOCK_RECEIPT_LINK_DELIVERY.md).