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

@@ -130,6 +130,26 @@ d("chargeback и fraud (временная БД)", () => {
});
describe("решения Юли и Анастасии (MCP) и пересчёт контракта", () => {
it("approve требует fix_vendor_name; привязка инвойса другого вендора предупреждает, но не блокирует", async () => {
const id = (await start()).body.chargeback.id as string;
expect(await errOf(call(anastasia, "acc_chargeback_decide", { id, decision: "approve" }))).toContain("fix_vendor_name");
expect(await errOf(call(anastasia, "acc_chargeback_decide", { id, decision: "approve", fix_vendor_name: " " }))).toContain("fix_vendor_name");
expect((await db.pool.query("select status from acc_chargeback where id = $1", [id])).rows[0].status).toBe("claimed");
await call(anastasia, "acc_chargeback_decide", { id, decision: "approve", fix_vendor_name: "Other Builders LLC" });
const link = (await call(yulia, "acc_chargeback_link_invoice", { id, invoice_id: await invoice(1000) })) as any; // вендор инвойса - Fix Co
expect(link.chargeback.status).toBe("fix_invoiced");
expect(link.warnings).toHaveLength(1);
expect(link.warnings[0]).toContain("Fix Co");
expect(link.warnings[0]).toContain("Other Builders LLC");
});
it("совпадение вендора с точностью до юридического суффикса предупреждения не даёт", async () => {
const id = (await start()).body.chargeback.id as string;
await call(anastasia, "acc_chargeback_decide", { id, decision: "approve", fix_vendor_name: "fix co llc" });
const link = (await call(yulia, "acc_chargeback_link_invoice", { id, invoice_id: await invoice(1000) })) as any;
expect(link.warnings).toBeUndefined();
});
it("полный путь: decide -> link_invoice -> confirm; удержание уменьшает остаток; закрытие при нулевом остатке", async () => {
const cb = (await start()).body.chargeback;
const id = cb.id as string;
@@ -266,6 +286,21 @@ d("chargeback и fraud (временная БД)", () => {
expect(await errOf(call(yulia, "acc_fraud_update", { id: cb, status: "filed" }))).toContain("не fraud");
});
it("открытое дело по операции защищено уникальным индексом; параллельное создание возвращает «дело уже есть»", async () => {
await addOp("F1");
await expect(
(async () => {
await db.pool.query("insert into acc_chargeback (kind, status, feed_txn_id, reason) values ('card_fraud', 'collecting', 'U1', 'a')");
await db.pool.query("insert into acc_chargeback (kind, status, feed_txn_id, reason) values ('card_fraud', 'filed', 'U1', 'b')");
})(),
).rejects.toMatchObject({ code: "23505" });
await db.pool.query("insert into acc_chargeback (kind, status, feed_txn_id, reason) values ('card_fraud', 'closed', 'U1', 'закрытое не мешает')");
const [a, b] = (await Promise.all([call(yulia, "acc_fraud_create", { feed_txn_id: "F1" }), call(yulia, "acc_fraud_create", { feed_txn_id: "F1" })])) as any[];
expect([a.created, b.created].sort()).toEqual([false, true]);
expect(a.chargeback.id).toBe(b.chargeback.id);
expect((await db.pool.query("select count(*)::int as n from acc_chargeback where feed_txn_id = 'F1'")).rows[0].n).toBe(1);
});
it("после закрытия по той же операции можно завести новое дело", async () => {
const a = ((await call(yulia, "acc_fraud_create", { feed_txn_id: "F1" })) as any).chargeback.id as string;
await call(yulia, "acc_fraud_update", { id: a, status: "closed" });