iVendNextDevelopers My apps

Approvals by workflow

A customer wants a person's yes before a document goes out. iVendNext's own workflow does it, and an app can install one on the customer's own record type. S11 is the worked example: a Purchase Order over 50,000 waits for a Purchase Manager, and approving it submits it.

Next: the sample, S11 · Purchase Order approvalAll recipes

First, does the customer need an app at all? If all they want is that an order over an amount needs a particular person or role, no: it is one record in iVendNext Desk. Open Authorization Rule, set Transaction to Purchase Order, Based On to Grand Total, Authorized Value to the amount, and Approving Role or Approving User to who may submit above it. Anyone else who tries to submit an order over that value is refused. An app earns its place when the customer wants named steps, a Reject, mail, or the same thing installed on many sites.

The workflow

In manifest.json, under workflows:

{
  "name": "ACME PO APPROVAL Purchase Order Approval",
  "document_type": "Purchase Order",
  "send_email_alert": 1,
  "states": [
    {"state": "Draft", "doc_status": 0, "allow_edit": "Purchase User"},
    {"state": "Approved", "doc_status": 1, "allow_edit": "Purchase Manager"},
    {"state": "Rejected", "doc_status": 0, "allow_edit": "Purchase User"},
    {"state": "Cancelled", "doc_status": 2, "allow_edit": "Purchase Manager"}
  ],
  "transitions": [
    {"state": "Draft", "action": "Approve", "next_state": "Approved", "allowed": "Purchase Manager", "allow_self_approval": 0, "condition": "doc.base_grand_total > 50000"},
    {"state": "Draft", "action": "Reject", "next_state": "Rejected", "allowed": "Purchase Manager", "condition": "doc.base_grand_total > 50000"},
    {"state": "Draft", "action": "Submit", "next_state": "Approved", "allowed": "Purchase User", "allow_self_approval": 1, "condition": "doc.base_grand_total <= 50000"},
    {"state": "Rejected", "action": "Review", "next_state": "Draft", "allowed": "Purchase User", "allow_self_approval": 1},
    {"state": "Approved", "action": "Cancel", "next_state": "Cancelled", "allowed": "Purchase Manager", "allow_self_approval": 1}
  ]
}

A role the site does not have is made at install, empty, for the customer to give to staff.

More you can add in the same manifest

What it may not do

A workflow may run on any record type except the till's own (POS Invoice, the day's opening and closing, Customer, and what the till books), because a sale must never wait for an approval nobody at the counter gives. A state may write only your app's own field. The full list: What an app may not do.

Try it

ivn new acme_po_approval --from s11
cd apps/acme_po_approval
ivn check
ivn try

Then, on your sandbox: as the buyer, raise a Purchase Order over the amount; as the approver, open it and press Approve. It reads Approved and it is submitted. To remove it, uninstall it from Retail Extension Package: the workflow goes, and documents keep the state they were in.

What to tell the customer

Orders over the amount wait for a Purchase Manager, and the buyer submits the rest. Whoever may act next gets a mail.

Needs this serves

This page in the kit