Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
backorder_attention.py · 2.3 KB · 70 lines
1"""system_backorder_attention -- how many people are waiting on stock.
2
3COUNT {} -> {count, detail}
4
5The open backorder rows: goods a customer has already been sold and not
6yet been sent, plus the interest recorded for people the shop refused and
7promised to tell. `filled` and `cancelled` have both had an answer.
8
9Severity `warning` rather than `normal` in the manifest, and the argument
10is the one system_shipment_attention makes about a stuck parcel: nobody
11chose to be in this queue, and the clock is running somewhere else -- in
12this case in the inbox of somebody who has already paid. It is not
13`urgent`, which is reserved for the server saying it stopped doing its
14own work.
15
16The detail names the OLDEST wait rather than a total, because that is the
17row somebody should ring first: "9 waiting" is a number, "9 waiting, the
18oldest 21 days" is a reason to open the page.
19
20A row whose requested_on will not parse is counted but contributes no
21age. An unreadable date must not silently become evidence that somebody
22has been waiting no time at all, and must not take the whole count down
23with it either.
24
25Degrades to zero when backorders is absent, the same posture every other
26provider on this box takes: a rollup pass should not log an error every
27five minutes about a collection nobody installed.
28"""
29
30import os
31from datetime import date
32
33import object_records
34
35ACTOR = "system_backorder_attention"
36
37WAITING_STATUS = "open"
38
39
40def _text(value):
41 return str(value if value is not None else "").strip()
42
43
44def _days_since(value, today):
45 try:
46 return (today - date.fromisoformat(_text(value))).days
47 except ValueError:
48 return None
49
50
51def COUNT(request):
52 base = os.environ.get("DBBASIC_DATA_DIR", "data")
53 try:
54 rows = object_records.read_collection_records("backorders",
55 base_dir=base)
56 except Exception:
57 return {"count": 0}
58
59 waiting = [row for row in rows
60 if _text(row.get("status")) == WAITING_STATUS]
61 if not waiting:
62 return {"count": 0}
63
64 today = date.today()
65 ages = [age for age in (_days_since(row.get("requested_on"), today)
66 for row in waiting)
67 if age is not None and age >= 0]
68 if not ages:
69 return {"count": len(waiting)}
70 return {"count": len(waiting), "detail": f"oldest waiting {max(ages)} days"}