diff --git a/dokogen/variables.py b/dokogen/variables.py index d96f21b..dd79232 100644 --- a/dokogen/variables.py +++ b/dokogen/variables.py @@ -392,7 +392,21 @@ def _resolve(source: str, ctx: Dict) -> str: if source.startswith('decl:'): _, field, case = source.split(':') name = getattr(company, field, '') or '' - return dc.company_name_decline(name, case) if name else '—' + case_gr = dc._normalize_case(case) + # Сначала берём ГОТОВОЕ склонение из модели (пользователь мог + # подставить через Морфер/ИИ или ввести вручную), пересчитываем + # только если поле пустое + case_idx = {'nomn': 1, 'gent': 2, 'datv': 3, 'accs': 4, 'ablt': 5, 'loct': 6}.get(case_gr) + if case_idx: + if field == 'full_name': + ready = getattr(company, f'company_name_{case_idx}', '') or '' + if ready: + return ready + elif field == 'short_name': + ready = getattr(company, f'short_name_{case_idx}', '') or '' + if ready: + return ready + return dc.company_name_decline(name, case_gr) if name else '—' # Форматы ФИО if source.startswith('short_fio:'):