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
goodwill.py · 1.8 KB · 46 lines
1"""hook_goodwill -- a goodwill record cites a reason the shop lists, and
2says what the customer was told.
3
4A gate, so it only refuses or stamps (docs/logic-decisions.md #6): the
5reason code must be a correction_reasons code that applies to goodwill
6(data a manager extends, so a typo is refused with the list rather than
7stored as a reason nobody can count); customer_wording is filled from the
8reason's wording when the person left it blank, so every goodwill row says
9what the customer heard. Who may give goodwill at all is the permission
10rules' (shift lead, manager, owner create), and the approver is the row's
11owner, which the server stamps.
12
13Fails closed: reason codes that cannot be read refuse the write (503)
14rather than letting an unchecked code through.
15"""
16
17from __future__ import annotations
18
19import os
20
21import object_collections
22import object_corrections
23import object_records
24
25
26def _base_dir():
27 return os.environ.get("DBBASIC_DATA_DIR", "data")
28
29
30def BEFORE_WRITE(request):
31 action = object_corrections.text(request.get("action"))
32 if action != "create":
33 return None
34 record = dict(request.get("record") or {})
35 try:
36 reasons = object_records.read_collection_records("correction_reasons", base_dir=_base_dir())
37 except object_collections.CollectionNotFoundError:
38 reasons = []
39 except Exception:
40 return {"status": 503, "error": "Reason codes could not be read; nothing was recorded."}
41 reason, why = object_corrections.find_reason(reasons, record.get("reason_code"), "goodwill")
42 if reason is None:
43 return {"status": 422, "error": why}
44 if not object_corrections.text(record.get("customer_wording")):
45 record["customer_wording"] = object_corrections.text(reason.get("customer_wording"))
46 return {"record": record}