accounting_automation: сверка инвойсов с QuickBooks (invoice-reconcile), оплата независима от согласования, сумма и вендор из ленты, сводка Анастасии, правки finalize, поиска чека, проверки инвойса, chargeback; документы

Миграция 071: acc_discrepancies.reason и уникальный индекс открытых расхождений, уникальный открытый card_fraud по операции, insurer в разборе сертификатов.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 19:43:58 +03:00
parent 85f781b9fe
commit 74ffe8613b
34 changed files with 999 additions and 85 deletions

View File

@@ -0,0 +1,16 @@
-- Автоматизация бухгалтерии: причина расхождения (без дублей по инвойсу и причине) и один открытый fraud по операции. Только добавляет.
-- Причина расхождения инвойса с QuickBooks: paid_no_qbo, qbo_txn_missing, amount_mismatch, date_mismatch, qbo_paid_not_marked, paid_but_rejected,
-- paid_without_approval (задания invoice-reconcile и invoice-paid). Для сверки выписок (statement_vs_qbo) пусто.
alter table acc_discrepancies add column if not exists reason text;
-- Открытое расхождение по паре «инвойс, причина» одно: повторный прогон его не дублирует.
create unique index if not exists acc_discrepancies_open_reason_uq on acc_discrepancies (invoice_id, reason) where closed_at is null and reason is not null;
-- Открытое дело card_fraud по одной операции ленты одно (раньше проверялось только в коде).
create unique index if not exists acc_chargeback_fraud_open_uq on acc_chargeback (feed_txn_id) where kind = 'card_fraud' and status <> 'closed';
-- Страховщик в разборе сертификата: при завершении разбора переносится в acc_insurance_certificates.insurer (вместе с drive_file_id и сроком).
-- _original и _history получают ту же колонку (триггер копирует строку целиком).
alter table acc_certificates_review add column if not exists insurer text;
alter table acc_certificates_review_original add column if not exists insurer text;
alter table acc_certificates_review_history add column if not exists insurer text;