iVendNextDevelopers Request a sandbox

S28 — Merge counts, and a customer's history on the till

What the shop does

One small app, two doors, one settings record.

Merge counts (a Desk button). A stock user ticks several draft stock counts on the Stock Reconciliation list and presses Merge counts. One new draft count appears, holding every item of the ticked counts; a person checks it and submits it. The ticked counts are never changed: each gets a comment, merged into ⟨new count⟩.

Customer history (a partner page). A cashier presses a key on the till with a customer on the sale, or a back-office user opens the page for a customer in Desk, and sees that customer's last sales: the date, the store, who served, the sale's discount and each line's discount.

What happens When
One new draft count: one row per item, warehouse and batch two or more draft counts of one company and one purpose are ticked
The quantities are added the settings say Sum (the default)
The quantity of the latest count is kept the settings say Last (latest by posting date and time)
The valuation rate of the latest count that has one (a row counted at zero stores none), and the latest count's posting date and time always
Merge counts does not run on ⟨count⟩ in this state. (the shop's words; the app is not called) a submitted or cancelled count is ticked
Nothing merged, with the reason one count only, two companies, two purposes (opening stock and a count), or a row with serial numbers or with its batch or serials in a bundle
The same new draft again, and no second one the press is retried from the same dialog
The customer's last sales, newest first the page opens for a customer
No customer on this sale the till's sale has no customer
No sales yet the customer has no submitted sale

Bounds, said plainly.

What the shop does to set it up

  1. Install manifest.json (the shop's administrator, on the install screen; on your sandbox, tools/deploy/deploy.py). It adds PP MHS Settings, a field on the count (Merged by press), the two services and the button (all switched off), and the roles PP MHS Integration, PP MHS Counts and PP MHS History (empty).
  2. In Role Permissions, give PP MHS Integration read, create and write on Stock Reconciliation, read and create on Comment, and read on POS Invoice, Sales Invoice and User. A manifest grants rights only on its own record types (the integration user recipe). On the sandbox, a read the shop gave to every user did not reach the app's key: give it to the role.
  3. Make the app's integration user with that role and generate its API key.
  4. Fill PP MHS Settings named Default: the rule for the same item in the same warehouse (Sum or Last) and the number of sales the page shows.
  5. Give PP MHS Counts to the people who merge and PP MHS History to the people who open the page.
  6. Open each service (Retail Extension Subscription), read what it receives, tick the consent and switch it on; switch the button on (Retail Desk Action).
  7. Place the Customer history key in POS Studio → Apps for the till's theme.

What leaves the shop. The press sends the ticked counts' names; the page receives the till's sale (with its customer and cashier) or, in Desk, the customer's name. The service reads the ticked counts, the settings, the customer's sales and the full names of the people who made them; it writes one draft count per press and a comment on each ticked count.

Run it

python3 -m unittest discover -s samples/s28_merge_and_history/tests -p 'test_*.py'
python3 samples/s28_merge_and_history/tests/canaries.py

The service, with its settings in a file kept out of git (the integration user's key and the two secrets the install handed back):

cat > samples/s28_merge_and_history/service/.env.local <<'EOF'
PP_BASE=https://your-sandbox.example
PP_KEY=…
PP_SECRET=…
PP_ACTION_SECRET=…
PP_PAGE_SECRET=…
PP_PORT=8133
EOF
python3 samples/s28_merge_and_history/service/app.py samples/s28_merge_and_history/service/.env.local

The shop must reach it over HTTPS with a real certificate: put it behind your own host, and write that address in the manifest's allowed_urls and the two endpoint_urls.

The files

File What
merge.py the merge, pure: the press's signature, the refusals, the rows (sum or last), the new draft, the answer
history.py the page, pure: the context's signature and expiry, the nonce once, the customer, the newest sales without roll-ups, each visit's discounts
service/app.py the service: the shop over the record API with the app's key, the press, the page and its one read
service/history.html the page, drawn with the design kit (kit/design/), which the service serves beside it
manifest.json the settings, the field on the count, the two services, the button, the three roles
tests/ 52 laptop tests (test_merge.py, test_history.py, test_shop.py, test_manifest.py); canaries.py removes each guard in turn and its test must go RED (37 of 37)

Technical notes

What was proven where

Needs this serves

This page in the kit