opencashflow 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opencashflow-0.11.0/.claude/skills/run-opencashflow/SKILL.md +105 -0
- opencashflow-0.11.0/.claude/skills/run-opencashflow/smoke.py +115 -0
- opencashflow-0.11.0/.github/workflows/publish.yml +43 -0
- opencashflow-0.11.0/.gitignore +11 -0
- opencashflow-0.11.0/LICENSE +201 -0
- opencashflow-0.11.0/PKG-INFO +141 -0
- opencashflow-0.11.0/README.md +113 -0
- opencashflow-0.11.0/docs/examples/hogar-chileno.yaml +212 -0
- opencashflow-0.11.0/docs/model.md +377 -0
- opencashflow-0.11.0/pyproject.toml +45 -0
- opencashflow-0.11.0/src/opencashflow/__init__.py +1 -0
- opencashflow-0.11.0/src/opencashflow/cli.py +3751 -0
- opencashflow-0.11.0/src/opencashflow/cli_export.py +286 -0
- opencashflow-0.11.0/src/opencashflow/credit_card.py +237 -0
- opencashflow-0.11.0/src/opencashflow/creditcard_statements.py +682 -0
- opencashflow-0.11.0/src/opencashflow/engine.py +694 -0
- opencashflow-0.11.0/src/opencashflow/models.py +262 -0
- opencashflow-0.11.0/src/opencashflow/period_close.py +400 -0
- opencashflow-0.11.0/src/opencashflow/periods.py +110 -0
- opencashflow-0.11.0/src/opencashflow/record_stack.py +105 -0
- opencashflow-0.11.0/src/opencashflow/schemas.py +302 -0
- opencashflow-0.11.0/src/opencashflow/seed.py +228 -0
- opencashflow-0.11.0/src/opencashflow/sheet_spec.py +374 -0
- opencashflow-0.11.0/src/opencashflow/wallet.py +86 -0
- opencashflow-0.11.0/src/opencashflow/wallet_movements.py +152 -0
- opencashflow-0.11.0/tests/__init__.py +0 -0
- opencashflow-0.11.0/tests/test_cli_creditcard_core.py +200 -0
- opencashflow-0.11.0/tests/test_cli_register_generic_commands.py +110 -0
- opencashflow-0.11.0/tests/test_cli_sheet_import_export.py +88 -0
- opencashflow-0.11.0/tests/test_cli_show.py +262 -0
- opencashflow-0.11.0/tests/test_cli_table_layout.py +32 -0
- opencashflow-0.11.0/tests/test_creditcard_statements.py +578 -0
- opencashflow-0.11.0/tests/test_engine_rules.py +739 -0
- opencashflow-0.11.0/tests/test_period_close.py +317 -0
- opencashflow-0.11.0/tests/test_periods.py +176 -0
- opencashflow-0.11.0/tests/test_real_world_examples.py +266 -0
- opencashflow-0.11.0/tests/test_record_stack.py +150 -0
- opencashflow-0.11.0/tests/test_sheet_spec.py +311 -0
- opencashflow-0.11.0/tests/test_sign_resolution.py +123 -0
- opencashflow-0.11.0/tests/test_standalone_entry_point.py +121 -0
- opencashflow-0.11.0/tests/test_wallet_movements.py +209 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: run-opencashflow
|
|
3
|
+
description: Build, test, and exercise the opencashflow library (a framework-agnostic SQLAlchemy/Pydantic cashflow-projection engine) and its standalone `opencashflow` CLI. Use when asked to install it, run its tests, verify it works after a change, try its CLI directly, or see a worked example of its write paths (override, record, period close, wallet movement).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
`opencashflow` is primarily a Python **library** (no server, no GUI), but since v0.8.1 it
|
|
7
|
+
also has its own standalone CLI (`opencashflow` console script / `python -m
|
|
8
|
+
opencashflow.cli`) -- a minimal, app-independent surface (no ledger, no credit cards, no
|
|
9
|
+
multi-user auth) good for trying the library out or running its example specs, but not a
|
|
10
|
+
substitute for a real consuming app's own richer CLI (e.g. `opencashflow-cli`'s `ocf`).
|
|
11
|
+
For exercising the library's write paths as CODE (the thing a consuming app actually
|
|
12
|
+
does), use `.claude/skills/run-opencashflow/smoke.py` -- a runnable worked example (not a
|
|
13
|
+
pytest file, no assertions-as-the-point) that seeds a sheet and walks every write path
|
|
14
|
+
the library exposes, printing the result of each step.
|
|
15
|
+
|
|
16
|
+
All paths below are relative to the repo root (`~/Escritorio/opencashflow`).
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
Python >=3.10 (verified against 3.14.7 in this container). No system packages needed --
|
|
21
|
+
pure Python, SQLAlchemy + Pydantic only, SQLite backing store.
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python3 -m venv .venv # skip if .venv already exists
|
|
27
|
+
source .venv/bin/activate
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Run (agent path)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
source .venv/bin/activate
|
|
35
|
+
python .claude/skills/run-opencashflow/smoke.py
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Expected output (values may shift slightly if the seed data changes):
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
== 1. seed_sheet + compute_sheet ==
|
|
42
|
+
Sheet #1 seeded, 7 sections. SALDO FINAL (Jan 2026) proyectado = 1537000.00
|
|
43
|
+
== 2. _do_set_override (write path: manual override) ==
|
|
44
|
+
Wrote override on row 'Sueldo líquido' -> 2000000.00. SALDO FINAL recomputed = 1177000.00
|
|
45
|
+
== 3. record set (write path: actual/accrued/paid + CellActualEntry) ==
|
|
46
|
+
Recorded actual=2000000.00 on cell #6
|
|
47
|
+
== 4. close_period (dry_run, then committed) ==
|
|
48
|
+
Preview: SALDO FINAL=3200000.00, real_net_flow=2000000.00, 0 rollover(s), warnings=[...]
|
|
49
|
+
Committed: period.is_closed=True, next_period_label=Feb 2026
|
|
50
|
+
== 5. wallet + wallet_movements (write path: Wallet/WalletMovement) ==
|
|
51
|
+
wallet_movement_add -> movement #1, wallet balance = 50000.0
|
|
52
|
+
wallet_movement_undo -> reversal #2, wallet balance = 0.0
|
|
53
|
+
|
|
54
|
+
All write paths exercised successfully.
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
It runs entirely against an in-memory SQLite database created fresh each run --
|
|
58
|
+
it never touches a real `opencashflow.db`, so it's always safe to re-run. A
|
|
59
|
+
non-zero exit / traceback means the library's public surface (`compute_sheet`,
|
|
60
|
+
`_do_set_override`, `close_period`, `do_wallet_movement_add/undo`) has a real
|
|
61
|
+
regression, not a flaky test.
|
|
62
|
+
|
|
63
|
+
## Run the standalone CLI directly
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
.venv/bin/opencashflow seed --user-id 1 --months 6
|
|
67
|
+
.venv/bin/opencashflow sheets
|
|
68
|
+
.venv/bin/opencashflow rows --sheet-id 1
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Defaults to a throwaway `sqlite:///./opencashflow-demo.db` in the current directory
|
|
72
|
+
(override with `--db-url` or `$OPENCASHFLOW_DB_URL`) -- never a real consuming app's own
|
|
73
|
+
database. This is the generic surface `register_generic_commands` builds, plus a minimal
|
|
74
|
+
`seed`; it has no ledger/credit-card/auth commands (those live in a real consuming app).
|
|
75
|
+
|
|
76
|
+
## Test
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
source .venv/bin/activate
|
|
80
|
+
pytest tests/ -v
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
96 tests, all pass (confirmed this session). No known-flaky tests.
|
|
84
|
+
|
|
85
|
+
## Gotchas
|
|
86
|
+
|
|
87
|
+
- **`opencashflow.wallet` must be imported before `Base.metadata.create_all()`** on
|
|
88
|
+
a fresh database -- `Wallet`/`WalletMovement` live in their own module and only
|
|
89
|
+
register their tables on `opencashflow.models.Base`'s registry as a side effect of
|
|
90
|
+
being imported. Skipping the import silently creates every table except
|
|
91
|
+
`wallets`/`wallet_movements`. `smoke.py` does `import opencashflow.wallet # noqa: F401`
|
|
92
|
+
for exactly this reason.
|
|
93
|
+
- **Write-path result objects don't use the field names you'd guess**:
|
|
94
|
+
`_do_set_override(...)` returns `OverrideWriteResult` objects whose written value
|
|
95
|
+
is at `.override.value` (not `.new_value`, not `.override.manual_value`) --
|
|
96
|
+
confirmed by inspecting `opencashflow.models.CellOverride`'s actual columns, not
|
|
97
|
+
by guessing from the CLI's print statements.
|
|
98
|
+
- **`.venv` is not relocatable.** `pip install -e .` bakes this repo's absolute path
|
|
99
|
+
into the venv's editable-finder files and script shebangs. If this folder is ever
|
|
100
|
+
moved or renamed, re-run `pip install -e .` against the new path (or delete and
|
|
101
|
+
recreate `.venv` entirely if even `pip` itself stops working).
|
|
102
|
+
- **`find_balance_row` (used by `close_period`) auto-detects the starting-balance
|
|
103
|
+
row by scanning for the one row using the `previous_period` projection rule** --
|
|
104
|
+
there's no config flag for it. A sheet with zero or more than one such row raises
|
|
105
|
+
`ValueError` (never `sys.exit`), listing every candidate.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Smoke test / worked example for the `opencashflow` library.
|
|
2
|
+
|
|
3
|
+
This is not a test in the pytest sense (no assertions) -- it is a runnable
|
|
4
|
+
demonstration that imports the package as an external consumer would and
|
|
5
|
+
exercises every write path the library exposes, printing the result of each
|
|
6
|
+
step. Run it after `pip install -e ".[dev]"` to confirm the library actually
|
|
7
|
+
works end to end, not just that its own unit tests pass in isolation.
|
|
8
|
+
|
|
9
|
+
python .claude/skills/run-opencashflow/smoke.py
|
|
10
|
+
|
|
11
|
+
Everything runs against an in-memory SQLite database created fresh each run
|
|
12
|
+
-- it never touches a real `opencashflow.db`.
|
|
13
|
+
"""
|
|
14
|
+
from datetime import date, datetime
|
|
15
|
+
from decimal import Decimal
|
|
16
|
+
|
|
17
|
+
from sqlalchemy import create_engine
|
|
18
|
+
from sqlalchemy.orm import sessionmaker
|
|
19
|
+
|
|
20
|
+
import opencashflow.wallet # noqa: F401 -- registers Wallet/WalletMovement on Base.metadata
|
|
21
|
+
from opencashflow.cli import _do_set_override
|
|
22
|
+
from opencashflow.engine import compute_sheet
|
|
23
|
+
from opencashflow.models import Base, CellActualEntry, SheetCell, SheetPeriod, SheetRow
|
|
24
|
+
from opencashflow.period_close import close_period
|
|
25
|
+
from opencashflow.wallet import Wallet
|
|
26
|
+
from opencashflow.wallet_movements import do_wallet_movement_add, do_wallet_movement_undo
|
|
27
|
+
from opencashflow.seed import seed_sheet
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def cell_for(result, row_id, period_id):
|
|
31
|
+
for section in result["sections"]:
|
|
32
|
+
for row_data in section["rows"]:
|
|
33
|
+
if row_data["row"].id == row_id:
|
|
34
|
+
for cr in row_data["cells"]:
|
|
35
|
+
if cr.period_id == period_id:
|
|
36
|
+
return cr
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def main():
|
|
41
|
+
engine = create_engine("sqlite:///:memory:")
|
|
42
|
+
Base.metadata.create_all(bind=engine)
|
|
43
|
+
db = sessionmaker(bind=engine)()
|
|
44
|
+
|
|
45
|
+
print("== 1. seed_sheet + compute_sheet ==")
|
|
46
|
+
sheet = seed_sheet(db, user_id=1, months=3, base_period=date(2026, 1, 1))
|
|
47
|
+
result = compute_sheet(sheet.id, db)
|
|
48
|
+
first_period = db.query(SheetPeriod).filter_by(sheet_id=sheet.id).order_by(SheetPeriod.sort_order).first()
|
|
49
|
+
saldo_final_row = next(
|
|
50
|
+
r for s in result["sections"] for r in s["rows"] if r["row"].name == "SALDO FINAL"
|
|
51
|
+
)["row"]
|
|
52
|
+
saldo_before = cell_for(result, saldo_final_row.id, first_period.id).projected_value
|
|
53
|
+
print(f" Sheet #{sheet.id} seeded, {len(result['sections'])} sections. "
|
|
54
|
+
f"SALDO FINAL ({first_period.label}) proyectado = {saldo_before}")
|
|
55
|
+
assert saldo_before is not None
|
|
56
|
+
|
|
57
|
+
print("== 2. _do_set_override (write path: manual override) ==")
|
|
58
|
+
ingresos_row = next(
|
|
59
|
+
r for s in result["sections"] for r in s["rows"]
|
|
60
|
+
if r["row"].name not in ("SALDO INICIAL", "SALDO FINAL") and r["row"].section.section_type == "income"
|
|
61
|
+
)["row"]
|
|
62
|
+
write_results = _do_set_override(
|
|
63
|
+
db, sheet.id, ingresos_row, [first_period],
|
|
64
|
+
value=Decimal("2000000"), created_by=1, note="smoke test override",
|
|
65
|
+
)
|
|
66
|
+
result = compute_sheet(sheet.id, db)
|
|
67
|
+
saldo_after_override = cell_for(result, saldo_final_row.id, first_period.id).projected_value
|
|
68
|
+
print(f" Wrote override on row '{ingresos_row.name}' -> {write_results[0].override.value}. "
|
|
69
|
+
f"SALDO FINAL recomputed = {saldo_after_override}")
|
|
70
|
+
assert saldo_after_override != saldo_before
|
|
71
|
+
|
|
72
|
+
print("== 3. record set (write path: actual/accrued/paid + CellActualEntry) ==")
|
|
73
|
+
cell = db.query(SheetCell).filter_by(row_id=ingresos_row.id, period_id=first_period.id).first()
|
|
74
|
+
if not cell:
|
|
75
|
+
cell = SheetCell(row_id=ingresos_row.id, period_id=first_period.id)
|
|
76
|
+
db.add(cell)
|
|
77
|
+
db.flush()
|
|
78
|
+
cell.actual_value = cell.accrued_value = cell.paid_value = Decimal("2000000")
|
|
79
|
+
db.add(CellActualEntry(cell_id=cell.id, actual_value=cell.actual_value,
|
|
80
|
+
accrued_value=cell.accrued_value, paid_value=cell.paid_value,
|
|
81
|
+
note="smoke test record", created_by=1))
|
|
82
|
+
db.commit()
|
|
83
|
+
print(f" Recorded actual={cell.actual_value} on cell #{cell.id}")
|
|
84
|
+
|
|
85
|
+
print("== 4. close_period (dry_run, then committed) ==")
|
|
86
|
+
preview = close_period(db, sheet, first_period, acting_user_id=1, dry_run=True)
|
|
87
|
+
print(f" Preview: SALDO FINAL={preview.saldo_final_value}, real_net_flow={preview.real_net_flow}, "
|
|
88
|
+
f"{len(preview.rollovers)} rollover(s), warnings={preview.warnings}")
|
|
89
|
+
report = close_period(db, sheet, first_period, acting_user_id=1, dry_run=False)
|
|
90
|
+
db.refresh(first_period)
|
|
91
|
+
print(f" Committed: period.is_closed={first_period.is_closed}, "
|
|
92
|
+
f"next_period_label={report.next_period_label}")
|
|
93
|
+
assert first_period.is_closed
|
|
94
|
+
|
|
95
|
+
print("== 5. wallet + wallet_movements (write path: Wallet/WalletMovement) ==")
|
|
96
|
+
wallet_obj = Wallet(user_id=1, name="Efectivo", wallet_type="cash", currency="CLP", balance=Decimal("0"))
|
|
97
|
+
db.add(wallet_obj)
|
|
98
|
+
db.commit()
|
|
99
|
+
second_period = db.query(SheetPeriod).filter_by(sheet_id=sheet.id).order_by(SheetPeriod.sort_order).offset(1).first()
|
|
100
|
+
add_result = do_wallet_movement_add(
|
|
101
|
+
db, wallet_obj, sheet.id, ingresos_row, second_period,
|
|
102
|
+
amount=Decimal("50000"), note="smoke test deposit", created_by=1,
|
|
103
|
+
)
|
|
104
|
+
db.refresh(wallet_obj)
|
|
105
|
+
print(f" wallet_movement_add -> movement #{add_result.movement.id}, wallet balance = {wallet_obj.balance}")
|
|
106
|
+
undo_result = do_wallet_movement_undo(db, add_result.movement, note="smoke test undo", created_by=1)
|
|
107
|
+
db.refresh(wallet_obj)
|
|
108
|
+
print(f" wallet_movement_undo -> reversal #{undo_result.reversal.id}, wallet balance = {wallet_obj.balance}")
|
|
109
|
+
assert wallet_obj.balance == Decimal("0")
|
|
110
|
+
|
|
111
|
+
print("\nAll write paths exercised successfully.")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == "__main__":
|
|
115
|
+
main()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Runs on every version tag push (vX.Y.Z), matching this repo's own
|
|
4
|
+
# release convention (version bump + tag as the last step of a feature).
|
|
5
|
+
# Uses PyPI's trusted publishing (OIDC) -- no API token stored as a
|
|
6
|
+
# secret. The PyPI project must have this repo/workflow registered as a
|
|
7
|
+
# trusted publisher first (a one-time step on pypi.org).
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
tags:
|
|
11
|
+
- "v*.*.*"
|
|
12
|
+
workflow_dispatch: {} # manual "Run workflow" button, for a first-time test run
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.x"
|
|
22
|
+
- name: Build sdist and wheel
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade build
|
|
25
|
+
python -m build
|
|
26
|
+
- uses: actions/upload-artifact@v4
|
|
27
|
+
with:
|
|
28
|
+
name: dist
|
|
29
|
+
path: dist/
|
|
30
|
+
|
|
31
|
+
publish:
|
|
32
|
+
needs: build
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
environment: pypi
|
|
35
|
+
permissions:
|
|
36
|
+
id-token: write
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/download-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: dist
|
|
41
|
+
path: dist/
|
|
42
|
+
- name: Publish to PyPI
|
|
43
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: opencashflow
|
|
3
|
+
Version: 0.11.0
|
|
4
|
+
Summary: Motor de proyección de flujo de caja: modelos SQLAlchemy, engine de cálculo y schemas Pydantic, agnóstico de framework web y de ledger.
|
|
5
|
+
Project-URL: Homepage, https://github.com/LuisLopezMunoz/opencashflow
|
|
6
|
+
Project-URL: Repository, https://github.com/LuisLopezMunoz/opencashflow
|
|
7
|
+
Project-URL: Issues, https://github.com/LuisLopezMunoz/opencashflow/issues
|
|
8
|
+
Author-email: Luis Alfredo López <luis@bmya.cl>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: budgeting,cashflow,finance,projection,sqlalchemy
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Accounting
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: pydantic<3,>=2.5
|
|
23
|
+
Requires-Dist: pyyaml<7,>=6
|
|
24
|
+
Requires-Dist: sqlalchemy<3,>=2.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# opencashflow
|
|
30
|
+
|
|
31
|
+
Motor de proyección de flujo de caja: modelos SQLAlchemy, engine de cálculo y schemas
|
|
32
|
+
Pydantic. Agnóstico de framework web, de autenticación y de ledger — es una librería,
|
|
33
|
+
no una aplicación.
|
|
34
|
+
|
|
35
|
+
Modela una planilla financiera como sección → fila → celda, donde cada fila declara una
|
|
36
|
+
regla de proyección (`constant`, `previous_period`, `sum_rows`, `percent_of_row`, entre
|
|
37
|
+
otras) y cada celda puede exponer un valor proyectado y, por separado, un valor real
|
|
38
|
+
(`actual_value`/`accrued_value`/`paid_value`) que la aplicación consumidora es responsable
|
|
39
|
+
de poblar. Overrides manuales son inmutables y auditables (nunca se actualizan, se
|
|
40
|
+
reemplazan). Ver [docs/model.md](docs/model.md) para el glosario completo del dominio.
|
|
41
|
+
|
|
42
|
+
## Instalación
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install "opencashflow @ git+https://github.com/LuisLopezMunoz/opencashflow.git@v0.1.0"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
(Todavía no está publicado en PyPI — instalar directamente desde el repositorio.)
|
|
49
|
+
|
|
50
|
+
Esto también instala el comando `opencashflow` (equivalente a `python -m
|
|
51
|
+
opencashflow.cli`) -- una CLI standalone, independiente de cualquier app consumidora
|
|
52
|
+
(sin ledger, sin auth multiusuario), útil para probar la librería o correr el demo de
|
|
53
|
+
abajo.
|
|
54
|
+
|
|
55
|
+
## Demo en un minuto
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
opencashflow seed --user-id 1 --months 12 --base-period 2026-01
|
|
59
|
+
opencashflow rows --sheet-id 1
|
|
60
|
+
opencashflow doctor --sheet-id 1
|
|
61
|
+
opencashflow show --sheet-id 1
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Esto crea (en una base SQLite descartable, `./opencashflow-demo.db` por defecto) una
|
|
65
|
+
planilla de ejemplo realista -- un hogar chileno con ingresos, gastos fijos/variables,
|
|
66
|
+
impuestos, financiamiento y un saldo acumulado -- lista sus filas y reglas, y por
|
|
67
|
+
último muestra la matriz calculada como tabla. (`--cards`/`--bridge` -- tarjetas de
|
|
68
|
+
crédito con parseo de PDF de banco y financiamiento puente -- son de las pocas cosas
|
|
69
|
+
que se quedan del lado de una app consumidora real; el modelo básico de tarjeta y
|
|
70
|
+
`creditcard list/edit/cupo/map` sí son parte de esta CLI standalone. Ver
|
|
71
|
+
[docs/model.md](docs/model.md), secciones "CLI genérico" y "Tarjetas de crédito".)
|
|
72
|
+
|
|
73
|
+
El mismo ejemplo vive como archivo declarativo en
|
|
74
|
+
[docs/examples/hogar-chileno.yaml](docs/examples/hogar-chileno.yaml) -- una planilla
|
|
75
|
+
completa (secciones → filas → reglas) en un solo documento YAML, generado con `sheet
|
|
76
|
+
export` y reimportable con `sheet import`:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
opencashflow sheet import --file docs/examples/hogar-chileno.yaml --user-id 1
|
|
80
|
+
opencashflow sheet export --sheet-id 1 # -- lo mismo, de vuelta a YAML, a stdout
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Ver [docs/model.md](docs/model.md), sección "Sheet spec", para el formato completo
|
|
84
|
+
(los 6 tipos de regla soportados, cómo se referencian filas por nombre, `sheet
|
|
85
|
+
import`/`export`). Nota: el spec captura la ESTRUCTURA de una planilla (secciones,
|
|
86
|
+
filas, reglas) -- no overrides manuales por celda, que es justamente lo que distingue
|
|
87
|
+
al ejemplo de arriba (generado con `seed`, que sí aplica un par de overrides realistas
|
|
88
|
+
de calendario) del mismo ejemplo reimportado desde el YAML (que empieza sin ellos).
|
|
89
|
+
|
|
90
|
+
## Uso mínimo (desde Python)
|
|
91
|
+
|
|
92
|
+
Este paquete no crea usuarios ni conexiones a base de datos por ti — trae tu propia
|
|
93
|
+
`Session` de SQLAlchemy y tu propio `user_id` (un entero simple, sin relación con ningún
|
|
94
|
+
modelo de usuario: ver "Ownership" en [docs/model.md](docs/model.md)).
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from datetime import datetime
|
|
98
|
+
|
|
99
|
+
from sqlalchemy import create_engine
|
|
100
|
+
from sqlalchemy.orm import sessionmaker
|
|
101
|
+
|
|
102
|
+
from opencashflow.engine import compute_sheet
|
|
103
|
+
from opencashflow.models import Base, CashflowSheet, SheetRow, SheetSection
|
|
104
|
+
from opencashflow.periods import generate_periods
|
|
105
|
+
|
|
106
|
+
engine = create_engine("sqlite:///example.db")
|
|
107
|
+
Base.metadata.create_all(bind=engine)
|
|
108
|
+
db = sessionmaker(bind=engine)()
|
|
109
|
+
|
|
110
|
+
sheet = CashflowSheet(user_id=1, name="Mi flujo de caja", currency="CLP",
|
|
111
|
+
horizon_months=6, base_period=datetime(2026, 1, 1))
|
|
112
|
+
db.add(sheet)
|
|
113
|
+
db.flush()
|
|
114
|
+
generate_periods(sheet, db)
|
|
115
|
+
|
|
116
|
+
section = SheetSection(sheet_id=sheet.id, name="Ingresos", section_type="income")
|
|
117
|
+
db.add(section)
|
|
118
|
+
db.flush()
|
|
119
|
+
|
|
120
|
+
row = SheetRow(section_id=section.id, name="Sueldo",
|
|
121
|
+
default_projection_rule={"type": "constant", "value": 1_500_000})
|
|
122
|
+
db.add(row)
|
|
123
|
+
db.commit()
|
|
124
|
+
|
|
125
|
+
result = compute_sheet(sheet.id, db)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Para un ejemplo completo y realista (una planilla de hogar chileno con las cuatro reglas
|
|
129
|
+
de proyección, saldo acumulado y overrides de calendario), ver
|
|
130
|
+
`opencashflow.seed.seed_sheet()`.
|
|
131
|
+
|
|
132
|
+
## Desarrollo
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pip install -e ".[dev]"
|
|
136
|
+
pytest tests/ -v
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Licencia
|
|
140
|
+
|
|
141
|
+
Apache 2.0 — ver [LICENSE](LICENSE).
|