iVendNextDevelopers Request a sandbox

Approvals across stores — a store manager's limit, head office above it — the recipe

This recipe is Approvals by workflow (S11) grown for a chain. A price change names its store; the store manager of that store approves it up to a limit, and head office approves anything above; each store sees only its own requests; a small outside service applies the change once. Reference implementation: samples/s14_approvals_stores/ (a manifest, an outside service, tests).

It keeps every safeguard S11 has. Read S11's recipe first: this page says only what is new.

When to use it. When the person who may approve depends on the store and on the size of the change, and the shop has more than one store.

Steps

  1. Four roles first. A manifest refuses a role the shop does not have. The sample names PP APS Requester, PP APS Store Manager, PP APS Head Office and PP APS Applier. Use the chain's own roles in a real roll-out. ⚠ No one holds a raising role and an approving role, and no one holds both approving roles. The shop's own self-approval check covers the Approve action only; the rest rests on this rule and on the service.

  2. Install the manifest (samples/s14_approvals_stores/manifest.json; recipes/manifest.md). It holds two record types and one workflow:

    • the price change request: item, price list, store (fixed once raised), new price, reason, change tracking on;
    • the approval rule table: one row per person — Store with a store and a limit (a percentage of the price now), or Head Office;
    • a workflow of five states: Requested → Store Approved → Head Office Approved → Applied, and Rejected. The store manager approves or rejects; head office approves (from Requested or Store Approved) or rejects (from any); the service applies from either approved state. Every row writes all nine rights out. The store manager, head office and service can read and write requests; only the administrator's role writes the rule table, so no one can raise their own limit.
  3. Fence each person to their store — in the shop. For every requester and store manager, one User Permission on POS Profile (their store). The shop then shows them, and lets them approve, their own store's requests only; a requester cannot raise a request for another store. Head office and the service have no store fence: they see all stores.

  4. Write the rules. One row per approver: Store, their store, their limit (for example 10); or Head Office. A person with no row has no authority in the service's eyes, whatever role they hold.

  5. The service's key is S11's (step 4 there): read and write on Item Price, fenced by a User Permission on the price lists it serves (Applicable For Item Price only), plus read and write on the request type (its workflow action saves the request) and read on the rule table. It cannot write a rule or raise a request.

  6. Run the outside service (approvals_stores.py apply) as often as you like. For each request in Store Approved or Head Office Approved, oldest first, it checks, and only then writes the price and takes the Apply action — once, and a rerun after a kill finishes it without writing the price again. It refuses and says why:

    • S11's refusals: item, price list or price changed after it was raised (and now the store); ten or more recorded changes; no recorded approval; no or two price rows;
    • an approval given by the person who raised the request — at any step, not only the last;
    • a store approval by someone without a Store rule for this request's store, or whose rule is not whole (a Store rule needs a store and a limit above 0 — the shop stores a blank limit as 0 — and a rule row must be named by its person, so a row whose Person was edited is not believed);
    • a store approval whose price row changed after the approval (an earlier request applied, another role's edit): the limit was judged against a price that is gone, so the manager rejects it and it is raised again. This stops a limit being climbed in steps — two +10% requests approved side by side would otherwise make +21%. A head-office approval names the price it wants and is applied whatever the row holds;
    • a change above the store manager's limit that head office has not approved: it waits, and the report says so;
    • a head-office approval by someone without a Head Office rule.
  7. Schedule the export (approvals_stores.py export --day <date> --out <folder>), as S11 step 6: the day's requests with the store and who approved at each step and who applied, and a column changed_after_raise that says yes where the item, price list, price or store was edited after the request was raised (the shop lets a requester edit an Applied request; the history keeps the truth, and the file now says so). A cell that starts with =, +, - or @ is written with a leading ', so a spreadsheet shows it as text.

Know these limits

What is refused, and why

Technical notes

What was proven, and where

Measured

This page in the kit