W128: Bulk-import purchase orders
Creates many POs at once from an uploaded CSV or Excel file. Triggered from the Data page, POs import. The whole import succeeds or fails atomically; partial imports are deliberately not supported.
Steps
-
Parse the upload. Read the file into rows of
{ header, items[] }. Collect per-row parse errors into a list rather than throwing on the first one. -
Abort on parse failures. If any rows failed to parse, raise a
ValidationErrorthat lists them. Nothing is persisted. -
Create each PO inside one transaction. Open one
withTransaction. For each parsed row, run the Create PO flow (W111) steps 1 to 5. The step-5 reconciliation projector writesORDERledger entries only for rows whose initial status leavesPlanning(and isn'tCancelled). -
Commit. On any single-row failure, the entire batch rolls back.
Returns
The list of created PO numbers.
Business rules
- All or nothing. Atomic import; the user never has to reconcile which subset of rows landed.
- PO numbers in the file are advisory. The workflow always generates fresh numbers from the org's counter to avoid colliding with existing POs.
Errors
ValidationError. Parse failures listed per row, or any single row failing the Create PO rules.