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

9 downloads

Install on DigitalOcean 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.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 49 minutes ago History
fringe_export.py · 2.8 KB · 65 lines
1"""action_fringe_export -- the fringe-benefit register, as a payroll provider takes it.
2
3GET /objects/action_fringe_export?from=2025-01-01&to=2025-12-31[&format=csv]
4
5Hands over what finance recorded, row for row, for the benefits whose
6period overlaps [from, to]: employee, benefit, period, value in cents,
7taxable yes/no, how it was valued and from what. It computes nothing --
8no withholding, no grossing-up, no valuation. Those are the payroll
9provider's and the accountant's, and a number this box made up would be
10handed on looking exactly like one finance determined.
11
12Who may run it: role:finance and admins (the execute rule), and the object
13asks again before reading, because it reads storage directly and is the
14only gate in front of pay information about named people: the caller must
15be an admin or read every row of the register whole
16(object_access.Access.reads_every_row) -- an own-rows grant is not enough
17for an export that is everybody's rows.
18
19CSV cells that a spreadsheet would run as a formula are prefixed with a
20quote (object_expense_rules.fringe_csv): payroll staff open these.
21"""
22
23import os
24import re
25
26import object_access
27import object_collections
28import object_expense_rules as rules
29import object_records
30
31_DATE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
32
33
34def _base_dir():
35 return os.environ.get("DBBASIC_DATA_DIR", "data")
36
37
38def GET(request):
39 base = _base_dir()
40 access = object_access.Access(request.get("_identity"), base_dir=base)
41 if not (access.is_admin or access.reads_every_row("fringe_benefits")):
42 return {"status": 403, "error": "The fringe-benefit register is for finance and admins."}
43 start = rules.text(request.get("from"))
44 end = rules.text(request.get("to"))
45 for name, value in (("from", start), ("to", end)):
46 if value and not _DATE.match(value):
47 return {"status": 400, "error": f"{name} must be YYYY-MM-DD"}
48 try:
49 rows = object_records.read_collection_records("fringe_benefits", base_dir=base)
50 except object_collections.CollectionNotFoundError:
51 rows = []
52 picked = rules.fringe_export_rows(rows, start=start, end=end)
53 if rules.text(request.get("format")).lower() == "csv":
54 return {"status": 200, "content_type": "text/csv; charset=utf-8",
55 "body": rules.fringe_csv(picked)}
56 return {"ok": True, "from": start, "to": end, "count": len(picked),
57 "total_value_cents": sum(int(row["value_cents"] or 0) for row in picked),
58 "taxable_value_cents": sum(int(row["value_cents"] or 0) for row in picked
59 if row["taxable"] == "yes"),
60 "columns": list(rules.FRINGE_EXPORT_COLUMNS), "rows": picked,
61 "note": ("Values are as finance recorded them; nothing here computes payroll or "
62 "withholding. Check with your accountant.")}
63
64
65POST = GET