akt-cli 0.7.0__tar.gz → 0.8.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: akt-cli
3
- Version: 0.7.0
3
+ Version: 0.8.1
4
4
  Summary: akt — a CLI toolbox to fully drive an Akaunting accounting instance
5
5
  Keywords: akaunting,accounting,cli,invoices,bills,api
6
6
  Author: AsyncAlchemist
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "akt-cli"
3
- version = "0.7.0"
3
+ version = "0.8.1"
4
4
  description = "akt — a CLI toolbox to fully drive an Akaunting accounting instance"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -226,6 +226,12 @@ def _build_parser() -> argparse.ArgumentParser:
226
226
  p.add_argument("--to", dest="date_to", metavar="YYYY-MM-DD")
227
227
  p.set_defaults(_special=sp)
228
228
 
229
+ gp = sub.add_parser("gc-ledger", parents=[common],
230
+ help="Report/remove orphaned ledger rows (needs the akt-api module)")
231
+ gp.add_argument("--apply", action="store_true",
232
+ help="delete the orphaned rows (default: report only)")
233
+ gp.set_defaults(_special="gc_ledger")
234
+
229
235
  return parser
230
236
 
231
237
 
@@ -236,7 +242,9 @@ def _need_akt_api(client: Client, cmd: str) -> None:
236
242
 
237
243
 
238
244
  def _fetch_balances(client: Client, ns: Any):
239
- accounts = client.list("chart-of-accounts", all_pages=True)
245
+ # One big page instead of paginating (a chart of accounts is small); saves
246
+ # round-trips, which matters when a script runs many balance/report calls.
247
+ accounts = client.list("chart-of-accounts", all_pages=True, params={"limit": 1000})
240
248
  accts_by_id = {a["id"]: {"code": a.get("code"), "name": a.get("name"),
241
249
  "type_id": a.get("type_id")} for a in accounts}
242
250
  params: dict[str, Any] = {}
@@ -444,6 +452,23 @@ def _run_special(name: str, client: Client, ns: Any) -> int:
444
452
  print(f" {'Net income to date':>40} {bs['net_income']:>12,.2f}")
445
453
  print(" BALANCED" if bs["balanced"] else " *** DOES NOT BALANCE")
446
454
  return 0 if bs["balanced"] else 1
455
+ if name == "gc_ledger":
456
+ _need_akt_api(client, "gc-ledger")
457
+ rep = client.get("akt-api/ledgers/orphans")
458
+ data = rep.get("data", rep) if isinstance(rep, dict) else rep
459
+ total = data.get("total", 0)
460
+ if not ns.apply:
461
+ if ns.json:
462
+ emit(data, as_json=True)
463
+ else:
464
+ for t, c in (data.get("by_type") or {}).items():
465
+ print(f" {c:>6} {t}")
466
+ print(f"{total} orphaned ledger row(s). Run with --apply to delete.")
467
+ return 0
468
+ res = client.request("DELETE", "akt-api/ledgers/orphans")
469
+ d = res.get("data", res) if isinstance(res, dict) else res
470
+ print(f"deleted {d.get('deleted', 0)} orphaned ledger row(s).")
471
+ return 0
447
472
  raise ValueError(name)
448
473
 
449
474
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes