Compare commits

...

1 Commits

Author SHA1 Message Date
8fc028cdc8 form-export-fix 2026-07-27 13:57:07 +03:00

View File

@ -40,6 +40,17 @@ ZIP_MEDIA_TYPE = "application/zip"
FORM1_DIRECTION_REQUIRED_SHEETS = {"AHR", "CAP"} FORM1_DIRECTION_REQUIRED_SHEETS = {"AHR", "CAP"}
SHEETS_WITH_SECTIONS = {"AHR", "CAP", "OPER"} SHEETS_WITH_SECTIONS = {"AHR", "CAP", "OPER"}
SHEET_NAMES = {
'AHR': 'АХР',
'CAP': 'КВП',
'OPER': 'Операц',
'AHR_LIMIT': 'АХР Лимиты',
'AHR_RENT': 'АХР Аренда',
'AHR_SECURITY': 'АХР Безопасность',
'AHR_UTILITY': 'АХР Коммунальные услуги',
'SMETA': 'Смета',
}
SKIP_SHEETS = ('OTCH9F',)
@dataclass(frozen=True) @dataclass(frozen=True)
class ExportSheetPlan: class ExportSheetPlan:
@ -233,6 +244,9 @@ class ExportService:
workbook = self._create_workbook_with_metadata(form=form) workbook = self._create_workbook_with_metadata(form=form)
exported_sheets = 0 exported_sheets = 0
for plan in plans: for plan in plans:
if not plan.validation_direction and plan.sheet_name in SKIP_SHEETS:
continue
self._validate_sheet_query_params( self._validate_sheet_query_params(
form_type_code=form.form_type.code, form_type_code=form.form_type.code,
sheet=plan.sheet_name, sheet=plan.sheet_name,
@ -245,7 +259,7 @@ class ExportService:
direction=plan.effective_direction, direction=plan.effective_direction,
sections=plan.effective_sections, sections=plan.effective_sections,
) )
worksheet = workbook.create_sheet(title=self._safe_sheet_name(plan.sheet_name)) worksheet = workbook.create_sheet(title=self._safe_sheet_name(plan.sheet_name, plan.effective_direction))
self._write_sheet_rows( self._write_sheet_rows(
worksheet=worksheet, worksheet=worksheet,
rows=rows, rows=rows,
@ -420,7 +434,15 @@ class ExportService:
return form_type_code == FormTypeEnum.FORM_1 and sheet in FORM1_DIRECTION_REQUIRED_SHEETS return form_type_code == FormTypeEnum.FORM_1 and sheet in FORM1_DIRECTION_REQUIRED_SHEETS
@staticmethod @staticmethod
def _safe_sheet_name(value: str) -> str: def _safe_sheet_name(value: str, direction: str | None = None) -> str:
if value in SHEET_NAMES:
sheet_name = SHEET_NAMES[value]
match direction:
case 'Support':
sheet_name = f'{sheet_name}'
case 'Development':
sheet_name = f'{sheet_name}_Р'
return sheet_name
safe = value safe = value
for char in ("[", "]", ":", "*", "?", "/", "\\"): for char in ("[", "]", ":", "*", "?", "/", "\\"):
safe = safe.replace(char, "_") safe = safe.replace(char, "_")