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
expense_attention.py · 1.9 KB · 61 lines
1"""system_expense_attention -- how much spending is waiting for approval.
2
3COUNT {} -> {count, detail}
4
5The same gate as time logs, over money instead of hours: an expense at
6`submitted` has been claimed and not yet decided, and the person who has
7to decide is by design not the person who claimed it. Until somebody
8looks, the books do not have it and the claimant is out of pocket, which
9is the kind of queue people find out about through a complaint rather
10than through a screen.
11
12The detail is the total, in whole currency units, because approving four
13coffees and approving a laptop are the same row count and very different
14afternoons.
15
16COUNT rather than GET or POST: the verb is the contract with the daemon's
17attention pass. Nothing here writes. A missing collection reads as zero;
18a genuine failure raises, so the rollup records the error and keeps the
19last count rather than reporting an empty queue nobody emptied.
20"""
21
22import os
23
24import object_records
25
26ACTOR = "system_expense_attention"
27
28# draft is still being written, approved/rejected have had a decision,
29# billed is already on an invoice. `submitted` is the waiting room.
30WAITING_STATUS = "submitted"
31
32
33def _base_dir():
34 return os.environ.get("DBBASIC_DATA_DIR", "data")
35
36
37def _text(value):
38 return str(value if value is not None else "").strip()
39
40
41def _cents(value):
42 try:
43 return int(_text(value) or 0)
44 except ValueError:
45 # A hand-edited amount must not take the count down with it.
46 return 0
47
48
49def COUNT(request):
50 try:
51 rows = object_records.read_collection_records("expenses", base_dir=_base_dir())
52 except Exception:
53 return {"count": 0}
54
55 waiting = [row for row in rows if _text(row.get("status")) == WAITING_STATUS]
56 if not waiting:
57 return {"count": 0}
58
59 total = sum(_cents(row.get("amount_cents")) for row in waiting)
60 detail = f"{total / 100:,.2f} awaiting approval" if total else ""
61 return {"count": len(waiting), "detail": detail}