Add versioned Client FY Accounting Mirrors

This commit is contained in:
A R R R Associates
2026-09-19 12:19:33 +05:30
parent f20b79ff70
commit f6776cc96a
11 changed files with 457 additions and 198 deletions
@@ -1,2 +1,2 @@
__version__ = "1.26.18"
__version__ = "1.26.19"
AGENT_NAME = "ERP Local Agent"
@@ -239,6 +239,25 @@ class LocalAccountingStore:
def exists(self, client_id: int) -> bool:
return self.db_path(client_id).is_file()
def archive_current_mirror_version(self, client_id: int, version_no: int) -> Path | None:
"""Preserve the current canonical .act before a new mirror version is published.
The canonical client_<id>.act remains untouched until the verified new
export is atomically published. The archive is therefore a historical
copy, not a destructive move.
"""
version = int(version_no or 0)
if version <= 0:
return None
source = self.db_path(client_id)
if not source.is_file():
return None
archive = source.with_name(f"{source.stem}_v{version}{source.suffix}")
if archive.exists():
return archive
self._sqlite_backup(source, archive)
return archive
# HISTORICAL_ACT_SCHEMA_AUTO_UPGRADE_V1
def _ensure_historical_schema_compatibility(
@@ -4327,6 +4327,10 @@ class AgentCommandProcessor:
"accounting_relative_dir": str(payload.get("accounting_relative_dir") or "").strip(),
"requested_by_user_id": requested_by,
"replacement_requested": bool(payload.get("replacement_requested")),
"previous_version_no": int(payload.get("previous_version_no") or 0),
"mirror_version_no": int(payload.get("mirror_version_no") or 1),
"archived_previous_file_name": "",
"archived_previous_path": "",
"date_from": date_from, "date_to": date_to, "rows": {},
"started_at_utc": now, "updated_at_utc": now, "finished_at_utc": "",
"error": "", "mirror_db_path": "", "accounting_db_path": str(self.store.db_path(client_id)),
@@ -4384,8 +4388,18 @@ class AgentCommandProcessor:
f"Expected directory '{expected_dir}', resolved '{bound_db}'."
)
archived_previous = None
if bool(payload.get("replacement_requested")):
previous_version_no = int(payload.get("previous_version_no") or 0)
if previous_version_no > 0:
archived_previous = self.store.archive_current_mirror_version(client_id, previous_version_no)
publish(
status="running", percent=2, stage="Starting",
previous_version_no=int(payload.get("previous_version_no") or 0),
mirror_version_no=int(payload.get("mirror_version_no") or 1),
archived_previous_file_name=(archived_previous.name if archived_previous else ""),
archived_previous_path=(str(archived_previous) if archived_previous else ""),
message=(
"Starting read-only ODBC export from TallyPrime for "
f"FY {requested_fy or 'selected period'} into {bound_db}."