Add FY-wise Tally data paths to engagement workspace

This commit is contained in:
A R R R Associates
2026-09-02 13:06:34 +05:30
parent ec00a76ace
commit a0db6cebfc
4 changed files with 175 additions and 9 deletions
+42 -3
View File
@@ -10,6 +10,28 @@ from app.modules.documents.services import client_folder_parts, get_active_stora
from app.modules.services.models import FirmServiceTaskTemplate, ServiceTaskCategory
_TALLY_MARKER_PREFIX = "ERP_TALLY_DATA_FY:"
def _previous_financial_year(financial_year: str) -> str:
match = re.match(r"^(\d{4})-(\d{2}|\d{4})$", (financial_year or "").strip())
if not match:
return ""
start = int(match.group(1))
prev_start = start - 1
return f"{prev_start:04d}-{start % 100:02d}"
def _tally_document_year(doc: Any) -> str:
description = str(getattr(doc, "description", "") or "").strip()
if description.startswith(_TALLY_MARKER_PREFIX):
return description[len(_TALLY_MARKER_PREFIX):].strip()
title = str(getattr(doc, "title", "") or "").strip()
match = re.match(r"^Tally Data\s*-\s*FY\s*(\d{4}-\d{2,4})$", title, re.IGNORECASE)
if match:
return match.group(1)
return ""
def _join_local_path(root: str, relative: str) -> str:
root = (root or "").strip().rstrip("\\/")
if not root:
@@ -148,6 +170,8 @@ def build_engagement_resource_context(db, engagement, tasks: Iterable[Any], docu
client = getattr(engagement, "client", None)
client_id = int(getattr(engagement, "client_id", 0) or 0)
fy = str(getattr(engagement, "financial_year", "") or "").strip()
prior_fy = _previous_financial_year(fy)
tally_year_options = [year for year in (fy, prior_fy) if year]
accounting_relative_dir = ""
accounting_relative_path = ""
@@ -174,19 +198,32 @@ def build_engagement_resource_context(db, engagement, tasks: Iterable[Any], docu
default_upload_task_id = next((row["task_id"] for row in categories if row.get("task_id")), None)
document_options = []
tally_data_files: list[dict[str, Any]] = []
for doc in documents:
versions = list(getattr(doc, "versions", None) or [])
latest = versions[0] if versions else None
document_options.append({
latest_relative_path = str(getattr(latest, "local_relative_path", "") or "") if latest else ""
tally_year = _tally_document_year(doc)
row = {
"id": int(getattr(doc, "id", 0) or 0),
"title": str(getattr(doc, "title", "") or "Document"),
"tally_financial_year": tally_year,
"document_type": str(getattr(doc, "document_type", "GENERAL") or "GENERAL"),
"version_no": int(getattr(doc, "current_version_no", 0) or 0),
"task_instance_id": getattr(doc, "task_instance_id", None),
"latest_filename": str(getattr(latest, "original_filename", "") or "") if latest else "",
"latest_relative_path": str(getattr(latest, "local_relative_path", "") or "") if latest else "",
"latest_relative_path": latest_relative_path,
"storage_status": str(getattr(latest, "storage_status", "") or "") if latest else "",
})
}
document_options.append(row)
if tally_year:
tally_data_files.append({
**row,
"financial_year": tally_year,
"local_path": _join_local_path(storage_root_path, latest_relative_path) if latest_relative_path else "",
})
tally_data_files.sort(key=lambda row: row.get("financial_year", ""), reverse=True)
return {
"accounting_relative_dir": accounting_relative_dir,
@@ -194,6 +231,8 @@ def build_engagement_resource_context(db, engagement, tasks: Iterable[Any], docu
"accounting_local_path": accounting_local_path,
"storage_root_path": storage_root_path,
"storage_node_name": storage_node_name,
"tally_year_options": tally_year_options,
"tally_data_files": tally_data_files,
"task_categories": categories,
"default_upload_task_id": default_upload_task_id,
"document_options": document_options,