Fixed Form Vlidation

This commit is contained in:
Shubhankar45
2026-09-22 10:36:55 +00:00
parent 8fdd20b29f
commit 2ed3945b5d
2435 changed files with 892940 additions and 32 deletions
+24 -4
View File
@@ -167,7 +167,9 @@ FORMS: dict[str, FormSpec] = {
Col("VALUE", "value", 9.6, "center"),
Col("CLOSING", "closing", 11.6, "center"),
Col("SEC. VALUE", "secondary_value", 10.1, "center"),
Col("AUG. SALES", "aug_sales", 9.6, "center"),
# Header text is filled in per report from the "month" column — see
# _sales_projection_columns — never a hardcoded month.
Col("SALES", "aug_sales", 9.6, "center"),
Col("VALUE", "value_2", 9.5, "center"),
),
min_rows=26,
@@ -252,6 +254,14 @@ def _has(row: Row, fields: tuple[str, ...]) -> bool:
return any(_text(row.get(field)) for field in fields)
def _sales_projection_columns(cols: tuple[Col, ...], rows: list[Row]) -> tuple[Col, ...]:
"""The printed form's "<Month>. Sales" column: the month it prints is whichever
month the rows were actually filled in for, never a fixed month."""
month = _distinct(rows, "month")
header = f"{month[:3].upper()}. SALES" if month else "SALES"
return tuple(Col(header, c.field, c.width, c.align) if c.field == "aug_sales" else c for c in cols)
def _grid(
cols: tuple[Col, ...],
rows: list[Row],
@@ -315,8 +325,15 @@ def build_form_context(
approval_status: str | None = None,
am_name: str | None = None,
approved_at: str | None = None,
renumber: bool = False,
) -> dict[str, object]:
"""Everything a form template needs, for all stored rows of ``table_name``."""
"""Everything a form template needs, for all stored rows of ``table_name``.
``renumber``: for a table whose stored Sl. No. restarts at 1 each month (see
MONTH_NUMBERED_TABLES in app/csv_data/router.py), the caller sets this when the rows
span more than one month — e.g. every month printed together — so the stored numbers
(1, 2… 1, 2…) are ignored in favour of one plain running count over what is printed.
"""
spec = FORMS.get(table_name)
grids: dict[str, dict[str, object]] = {}
extra: dict[str, object] = {}
@@ -360,11 +377,14 @@ def build_form_context(
for r in rows or [{}]
]
else:
columns = spec.columns
if table_name == "sales_projection":
columns = _sales_projection_columns(columns, rows)
grids["main"] = _grid(
spec.columns,
columns,
rows,
min_rows=spec.min_rows,
serial_field=spec.serial_field,
serial_field=None if renumber else spec.serial_field,
serial_dot=spec.serial_dot,
table_width=spec.table_width,
)
+2 -1
View File
@@ -155,10 +155,11 @@ def csv_table_pdf_bytes(
am_name: str | None = None,
am_role: str = "Area Manager",
approved_at: str | None = None,
renumber: bool = False,
) -> bytes:
"""Render every stored row of an imported table on its own company-form layout."""
context = build_form_context(
table_name, table_label, columns, rows, approval_status, am_name, approved_at
table_name, table_label, columns, rows, approval_status, am_name, approved_at, renumber
)
html = _env.get_template(f"forms/{context['template']}.html").render(**context)
if WEASYPRINT_AVAILABLE: