feat: UI/UX cleanup V1 with header, import requisites, and status fixes

This commit is contained in:
Арсентьев Александр
2026-09-27 20:22:13 +03:00
parent 79d802d536
commit 94571f9684
31 changed files with 2842 additions and 73 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ def _scope_label(agreement, docs):
if agreement.boq_document_id is None:
return "Весь проект"
doc = next((doc for doc in docs if doc.id == agreement.boq_document_id), None)
return doc.name if doc else f"Ведомость #{agreement.boq_document_id}"
return doc.display_name if doc else f"Ведомость #{agreement.boq_document_id}"
def _parse_scope(db, project_id, scope):
+50 -14
View File
@@ -6,6 +6,7 @@ from app.models import project, boq
from app.models.daily_report import DailyReport, DailyReportItem
from app.importer import excel_importer
import os
from datetime import date
from decimal import Decimal
from pathlib import Path
@@ -59,9 +60,7 @@ async def view_boq_document(request: Request, project_id: int, document_id: int,
).first()
if document is None:
raise HTTPException(status_code=404, detail="BOQ document not found")
document_title = document.name.replace("BOQ Import - ", "Импорт ведомости — ").replace(
"BOQ Import — ", "Импорт ведомости — "
)
document_title = document.display_name
items = db.query(boq.WorkItem).filter(
boq.WorkItem.boq_document_id == document_id,
@@ -150,6 +149,10 @@ async def upload_excel_file(
request: Request,
project_id: int,
file: UploadFile = File(...),
document_name: str = Form(""),
document_number: str = Form(""),
document_date: str = Form(""),
contract: str = Form(""),
db: Session = Depends(get_db)
):
db_project = db.query(project.Project).filter(project.Project.id == project_id).first()
@@ -159,19 +162,23 @@ async def upload_excel_file(
filename = Path(file.filename or "upload.xlsx").name
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
file_location = UPLOAD_DIR / filename
with open(file_location, "wb+") as file_object:
file_object.write(file.file.read())
# Get the sheets from the Excel file
sheets = excel_importer.get_excel_sheets(file_location)
return request.app.templates.TemplateResponse("projects/import_sheet_selection.html", {
"request": request,
"project": db_project,
"project_id": project_id,
"filename": filename,
"sheets": sheets
"sheets": sheets,
"document_name": document_name,
"document_number": document_number,
"document_date": document_date,
"contract": contract,
})
@router.post("/{project_id}/import/preview")
@@ -182,22 +189,26 @@ async def preview_import(
sheet_name: str = Form(...),
header_row: int = Form(...),
start_row: int = Form(...),
document_name: str = Form(""),
document_number: str = Form(""),
document_date: str = Form(""),
contract: str = Form(""),
db: Session = Depends(get_db)
):
# Get the file path
file_path = UPLOAD_DIR / Path(filename).name
# Import and preview data
try:
preview_data = excel_importer.preview_excel_data(file_path, sheet_name, header_row, start_row)
except (ValueError, OSError) as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
# Get project
db_project = db.query(project.Project).filter(project.Project.id == project_id).first()
if db_project is None:
raise HTTPException(status_code=404, detail="Project not found")
return request.app.templates.TemplateResponse("projects/import_preview.html", {
"request": request,
"project": db_project,
@@ -205,9 +216,20 @@ async def preview_import(
"filename": filename,
"sheet_name": sheet_name,
"header_row": header_row,
"start_row": start_row
"start_row": start_row,
"document_name": document_name or sheet_name,
"document_number": document_number,
"document_date": document_date,
"contract": contract or (db_project.contract_number or ""),
})
def _parse_optional_date(value: str):
value = (value or "").strip()
if not value:
return None
return date.fromisoformat(value)
@router.post("/{project_id}/import/confirm")
async def confirm_import(
request: Request,
@@ -216,20 +238,34 @@ async def confirm_import(
sheet_name: str = Form(...),
header_row: int = Form(...),
start_row: int = Form(...),
document_name: str = Form(""),
document_number: str = Form(""),
document_date: str = Form(""),
contract: str = Form(""),
db: Session = Depends(get_db)
):
# Get the file path
file_path = UPLOAD_DIR / Path(filename).name
# Import data into database
db_project = db.query(project.Project).filter(project.Project.id == project_id).first()
if db_project is None:
raise HTTPException(status_code=404, detail="Project not found")
try:
result = excel_importer.import_excel_data(db, file_path, sheet_name, header_row, start_row, project_id)
parsed_date = _parse_optional_date(document_date)
except ValueError as exc:
raise HTTPException(status_code=400, detail="Дата ведомости должна быть в формате ГГГГ-ММ-ДД") from exc
try:
result = excel_importer.import_excel_data(
db, file_path, sheet_name, header_row, start_row, project_id,
document_name=document_name,
document_number=document_number,
document_date=parsed_date,
contract=contract,
)
except (ValueError, OSError) as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
# Get project
return request.app.templates.TemplateResponse("projects/import_confirm.html", {
"request": request,