Skip to main content

Approval Workflow

The heart of the app โ€” process, processStep, purchaseOrder and stepApproval: configuring a workflow, submitting, evaluating, finalizing, cancelling.

๐Ÿ“„๏ธadd (purchaseOrder)

add creates the core procurement document โ€” a purchaseOrder. It's where you capture the request: who is asking (requester), what they want (product), which organization/unit it belongs to, an estimated cost, and an optional budgetLine to encumber. The PO is created as a Draft with an initial history entry of "created". If you don't pass a process explicitly, the fn resolves one automatically via resolveProcessForPO. This is the first of many purchaseOrder acts โ€” everything else in the chapter reads or mutates what you create here.

๐Ÿ“„๏ธcancel (purchaseOrder)

cancel aborts a purchase order that hasn't finished. It's allowed from Draft, Pending, and InProgress โ€” i.e. any state before the order is Approved/Rejected/terminal. On cancel it releases the budget reservation (totalEncumbered -= amount, remainingBudget += amount), sets status: "Cancelled", stamps completedAt, and pushes a cancelled history entry with an optional reason. Only Manager/Admin, or UnitHead with the canRegisterPurchaseOrder feature, can cancel.

๐Ÿ“„๏ธupdateRelations (purchaseOrder)

updateRelations lets you replace one or more relations of a purchase order after it was created โ€” requester, organization, requestingUnit, product, process, budgetLine, tender, or the attachments array. Every relation is swapped with replace: true, so the old embedded snapshot is dropped and the new one takes its place, with back-references kept in sync. This is how you fix a wrong budgetLine before submit, or attach a tender to a PO. Only Manager/Admin, or UnitHead with the canRegisterPurchaseOrder feature, can call it.