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
fin_journal_lines.py · 2.2 KB · 59 lines
1"""Pre-write hook for fin_journal_lines: a settled journal's lines are
2settled too.
3
4The closed-period gate on fin_journals stops the journal record itself
5from being touched -- but a journal's AMOUNTS live in its lines, and
6without this hook a line added to (or edited on) a journal dated inside a
7closed period would change settled books while the journal record sat
8innocently untouched. Same period, same rule, checked from the line's
9side: look up the parent journal, and if its date falls in a closed
10period, refuse.
11
12Rejection-only. Lines on journals in open periods pass untouched --
13including the ordinary compose flow of drafting a journal and adding its
14lines. A line whose journal_id does not resolve is left to relation
15validation, which owns missing parents.
16"""
17
18import os
19
20import object_finance
21import object_records
22
23
24def _base_dir():
25 return os.environ.get("DBBASIC_DATA_DIR", "data")
26
27
28def BEFORE_WRITE(request):
29 if request.get("action") not in ("create", "update"):
30 return None
31 record = request.get("record") or {}
32 existing = request.get("existing") or {}
33 journal_id = str(record.get("journal_id") or existing.get("journal_id") or "").strip()
34 if not journal_id:
35 return None # required/relation validation owns this
36
37 base = _base_dir()
38 try:
39 journal = object_records.get_collection_record("fin_journals", journal_id, base_dir=base)
40 except Exception:
41 return None # relation validation owns a missing journal
42
43 period = object_finance.closed_period_for(
44 journal.get("date"), base_dir=base,
45 owner_id=journal.get("owner_id") or "",
46 entity_id=journal.get("entity_id") or "")
47 if period is None:
48 return None
49
50 reason = str(period.get("reason") or "").strip()
51 label = f" ({reason})" if reason else ""
52 return {
53 "error": (f"This line belongs to a journal dated {journal.get('date')}, inside "
54 f"the closed period {period.get('start_date')} to "
55 f"{period.get('end_date')}{label}. Settled amounts are corrected by a "
56 "new journal in the current period, never by editing the old one's "
57 "lines."),
58 "status": 409,
59 }