Fixed Form Vlidation
This commit is contained in:
+17
-2
@@ -59,10 +59,21 @@ async def _reject_repeat(
|
||||
raise ConflictError("An identical row already exists in this form")
|
||||
|
||||
|
||||
#: Tables whose printed Sl. No. starts over at 1 for each month rather than running on
|
||||
#: forever — a shared master list (e.g. Sales Projection's product list) refilled every
|
||||
#: month, not one MR's own running form.
|
||||
MONTH_NUMBERED_TABLES = {"sales_projection"}
|
||||
|
||||
|
||||
async def _renumber_rows(table_name: str, db: AsyncSession) -> None:
|
||||
columns = _table(table_name)
|
||||
# An MR's own form is numbered 1, 2, 3… whoever else has rows in the same table.
|
||||
partition = "PARTITION BY owner_user_id " if table_name in OWNED_TABLES else ""
|
||||
if table_name in OWNED_TABLES:
|
||||
partition = "PARTITION BY owner_user_id "
|
||||
elif table_name in MONTH_NUMBERED_TABLES:
|
||||
partition = "PARTITION BY lower(btrim(COALESCE(\"month\", ''))) "
|
||||
else:
|
||||
partition = ""
|
||||
serial_updates = ""
|
||||
for column in columns:
|
||||
if column in SERIAL_COLUMNS:
|
||||
@@ -398,7 +409,7 @@ async def update_csv_row(table_name: str, row_id: uuid.UUID, payload: dict[str,
|
||||
|
||||
|
||||
@router.delete("/{table_name}/rows/{row_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_csv_row(table_name: str, row_id: uuid.UUID, db: AsyncSession = Depends(get_db), current_user: User = Depends(require_role(Role.MR, Role.ADMIN))) -> None:
|
||||
async def delete_csv_row(table_name: str, row_id: uuid.UUID, db: AsyncSession = Depends(get_db), current_user: User = Depends(require_role(Role.ADMIN))) -> None:
|
||||
_table(table_name)
|
||||
row_owner = await _row_owner(table_name, row_id, current_user, db)
|
||||
result = await db.execute(text(f'DELETE FROM "{table_name}" WHERE id = :id'), {"id": row_id})
|
||||
@@ -477,6 +488,9 @@ async def download_csv_table_pdfs(
|
||||
from app.pdf.service import csv_table_pdf_bytes
|
||||
suffix = re.sub(r"[^a-z]", "", month.lower()) if month else ""
|
||||
filename = f"{table_name}-{suffix}.pdf" if suffix else f"{table_name}.pdf"
|
||||
# Printing every month together: a month-numbered table's stored Sl. No. (1, 2… 1, 2…)
|
||||
# would repeat, so it is recomputed as one running count over what is actually printed.
|
||||
renumber = table_name in MONTH_NUMBERED_TABLES and not (month and month.strip())
|
||||
pdf = csv_table_pdf_bytes(
|
||||
table_name,
|
||||
CSV_LABELS[table_name],
|
||||
@@ -485,6 +499,7 @@ async def download_csv_table_pdfs(
|
||||
approval_status,
|
||||
am_name,
|
||||
approved_at=approved_at,
|
||||
renumber=renumber,
|
||||
)
|
||||
return Response(
|
||||
pdf,
|
||||
|
||||
Reference in New Issue
Block a user