Allow depreciation analysis from ready FY mirror without local mapping row
This commit is contained in:
@@ -4,7 +4,7 @@ import io
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
ERP_LOCAL_AGENT_VERSION = "1.26.2"
|
ERP_LOCAL_AGENT_VERSION = "1.26.3"
|
||||||
ERP_LOCAL_AGENT_NAME = "ERP Local Agent"
|
ERP_LOCAL_AGENT_NAME = "ERP Local Agent"
|
||||||
RUNTIME_ROOT = Path(__file__).resolve().parent / "local_agent_runtime"
|
RUNTIME_ROOT = Path(__file__).resolve().parent / "local_agent_runtime"
|
||||||
_DETERMINISTIC_ZIP_TIMESTAMP = (2026, 1, 1, 0, 0, 0)
|
_DETERMINISTIC_ZIP_TIMESTAMP = (2026, 1, 1, 0, 0, 0)
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
__version__ = "1.26.2"
|
__version__ = "1.26.3"
|
||||||
AGENT_NAME = "ERP Local Agent"
|
AGENT_NAME = "ERP Local Agent"
|
||||||
|
|||||||
@@ -634,9 +634,13 @@ class LocalAccountingStore:
|
|||||||
raise ValueError("Accounting storage is not initialized for this client.")
|
raise ValueError("Accounting storage is not initialized for this client.")
|
||||||
tally_guid = str(mapping.get("tally_guid") or "").strip()
|
tally_guid = str(mapping.get("tally_guid") or "").strip()
|
||||||
company_name = str(mapping.get("company_name") or "").strip()
|
company_name = str(mapping.get("company_name") or "").strip()
|
||||||
mapping_id = int(mapping.get("id"))
|
mapping_id = (
|
||||||
|
int(mapping.get("id"))
|
||||||
|
if mapping.get("id") not in (None, "")
|
||||||
|
else None
|
||||||
|
)
|
||||||
if not tally_guid or not company_name:
|
if not tally_guid or not company_name:
|
||||||
raise ValueError("Active Tally mapping is incomplete.")
|
raise ValueError("Accounting Mirror company identity is incomplete.")
|
||||||
started = _utc_now_iso()
|
started = _utc_now_iso()
|
||||||
counts: dict[str, int] = {}
|
counts: dict[str, int] = {}
|
||||||
run_id = None
|
run_id = None
|
||||||
@@ -688,12 +692,16 @@ class LocalAccountingStore:
|
|||||||
raise ValueError("Accounting storage is not initialized for this client.")
|
raise ValueError("Accounting storage is not initialized for this client.")
|
||||||
tally_guid = str(mapping.get("tally_guid") or "").strip()
|
tally_guid = str(mapping.get("tally_guid") or "").strip()
|
||||||
company_name = str(mapping.get("company_name") or "").strip()
|
company_name = str(mapping.get("company_name") or "").strip()
|
||||||
mapping_id = int(mapping.get("id"))
|
mapping_id = (
|
||||||
|
int(mapping.get("id"))
|
||||||
|
if mapping.get("id") not in (None, "")
|
||||||
|
else None
|
||||||
|
)
|
||||||
date_from = str(transactions.get("date_from") or "").strip()
|
date_from = str(transactions.get("date_from") or "").strip()
|
||||||
date_to = str(transactions.get("date_to") or "").strip()
|
date_to = str(transactions.get("date_to") or "").strip()
|
||||||
vouchers = transactions.get("vouchers") or []
|
vouchers = transactions.get("vouchers") or []
|
||||||
if not tally_guid or not company_name:
|
if not tally_guid or not company_name:
|
||||||
raise ValueError("Active Tally mapping is incomplete.")
|
raise ValueError("Accounting Mirror company identity is incomplete.")
|
||||||
if not date_from or not date_to:
|
if not date_from or not date_to:
|
||||||
raise ValueError("Transaction sync date range is missing.")
|
raise ValueError("Transaction sync date range is missing.")
|
||||||
|
|
||||||
@@ -1047,7 +1055,42 @@ class LocalAccountingStore:
|
|||||||
def depreciation_preview(self, client_id: int, *, tally_guid: str, fy_start: str, fy_end: str) -> dict:
|
def depreciation_preview(self, client_id: int, *, tally_guid: str, fy_start: str, fy_end: str) -> dict:
|
||||||
if not self.exists(client_id):
|
if not self.exists(client_id):
|
||||||
raise ValueError("Accounting storage is not initialized for this client.")
|
raise ValueError("Accounting storage is not initialized for this client.")
|
||||||
mapping = self.get_active_mapping_by_guid(client_id, tally_guid)
|
try:
|
||||||
|
mapping = self.get_active_mapping_by_guid(client_id, tally_guid)
|
||||||
|
except Exception:
|
||||||
|
mapping = {}
|
||||||
|
with self.connect(client_id) as db:
|
||||||
|
mapped = db.execute(
|
||||||
|
"""SELECT *
|
||||||
|
FROM tally_company_mapping
|
||||||
|
WHERE client_id=? AND is_active=1
|
||||||
|
ORDER BY id DESC LIMIT 1""",
|
||||||
|
(int(client_id),),
|
||||||
|
).fetchone()
|
||||||
|
if mapped:
|
||||||
|
mapping = dict(mapped)
|
||||||
|
else:
|
||||||
|
identity = db.execute(
|
||||||
|
"""SELECT company_name
|
||||||
|
FROM tally_ledgers
|
||||||
|
WHERE tally_guid=? AND trim(COALESCE(company_name,''))<>''
|
||||||
|
ORDER BY id LIMIT 1""",
|
||||||
|
(str(tally_guid or "").strip(),),
|
||||||
|
).fetchone()
|
||||||
|
mapping = {
|
||||||
|
"id": None,
|
||||||
|
"client_id": int(client_id),
|
||||||
|
"tally_guid": str(tally_guid or "").strip(),
|
||||||
|
"company_name": str(identity["company_name"] or "").strip() if identity else "",
|
||||||
|
"is_active": 1,
|
||||||
|
"mirror_only_identity": True,
|
||||||
|
}
|
||||||
|
if not str(mapping.get("company_name") or "").strip():
|
||||||
|
raise ValueError(
|
||||||
|
"Accounting Mirror is ready, but its company identity could not be resolved "
|
||||||
|
"for depreciation analysis. Refresh the mirror once and retry."
|
||||||
|
)
|
||||||
|
|
||||||
start = date.fromisoformat(str(fy_start)); end = date.fromisoformat(str(fy_end))
|
start = date.fromisoformat(str(fy_start)); end = date.fromisoformat(str(fy_end))
|
||||||
if start > end: raise ValueError("Financial-year start cannot be after end date.")
|
if start > end: raise ValueError("Financial-year start cannot be after end date.")
|
||||||
with self.connect(client_id) as db:
|
with self.connect(client_id) as db:
|
||||||
|
|||||||
Reference in New Issue
Block a user