Инвойсы: в разбор берутся только входящие счета (исходящие KH Build отбрасываются: промпт и защита в коде); processes.md
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,11 @@ export function parseRecognition(stdout: string): RecognizedInvoice {
|
||||
};
|
||||
}
|
||||
|
||||
/** Вендор - сама компания (KH Build LLC): такой счёт исходящий. */
|
||||
export function isOwnCompany(vendorName: string | null | undefined): boolean {
|
||||
return !!vendorName && /^\s*kh[\s.-]*build\b/i.test(vendorName);
|
||||
}
|
||||
|
||||
/** Детерминированный uuid записи инвойса: письмо + номер вложения + имя файла (повторный запуск не плодит дубли). */
|
||||
export function invoiceReviewId(messageId: string, index: number, filename: string): string {
|
||||
const h = createHash("sha1").update(`${messageId}\n${index}\n${filename}`).digest("hex");
|
||||
@@ -146,6 +151,7 @@ export function buildRecognitionPrompt(pdfPath: string, mail: { from: string; su
|
||||
"- amount: итоговая сумма к оплате, число в долларах",
|
||||
'- lines: массив строк счёта [{"description": "за что", "amount": число}]',
|
||||
"- object_name_or_address: название объекта или адрес, к которому относятся работы (Job, Project, Ship to, Site)",
|
||||
"Нас интересуют только ВХОДЯЩИЕ счета: счёт, который подрядчик или поставщик выставил компании KH Build LLC (мы - плательщик). Счета, которые выставила сама KH Build LLC (клиентам, например «New payment request from KH Build LLC», счета KHB-..., уведомления QuickBooks Payments о получении оплаты), - исходящие: для них is_invoice = false, document_type = \"other\".",
|
||||
"Если значение в документе не найдено, ставь null (не выдумывай).",
|
||||
].join("\n");
|
||||
}
|
||||
@@ -319,6 +325,11 @@ async function processAttachment(deps: InvoiceIngestDeps, msg: MailMessage, att:
|
||||
return "certificate";
|
||||
}
|
||||
if (!rec.is_invoice) return "none";
|
||||
// страховка от ошибки распознавания: счёт, выставленный самой KH Build, - исходящий, в разбор входящих не берём
|
||||
if (isOwnCompany(rec.vendor_name)) {
|
||||
deps.log.info({ messageId: msg.id, invoice: rec.invoice_number }, "исходящий счёт KH Build (вендор - мы сами): в разбор входящих не берётся");
|
||||
return "none";
|
||||
}
|
||||
|
||||
const resolved = await resolveAll(pool, rec);
|
||||
const problems = [...resolved.problems];
|
||||
|
||||
15
packages/accounting_automation/src/own-company.test.ts
Normal file
15
packages/accounting_automation/src/own-company.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildRecognitionPrompt, isOwnCompany } from "./invoices-mail.js";
|
||||
|
||||
describe("только входящие счета", () => {
|
||||
it("KH Build как вендор - свой, исходящий", () => {
|
||||
expect(isOwnCompany("KH Build LLC")).toBe(true);
|
||||
expect(isOwnCompany("KH BUILD, LLC")).toBe(true);
|
||||
expect(isOwnCompany("K.H. Build Co")).toBe(false);
|
||||
expect(isOwnCompany("Banko Overhead Doors, LLC")).toBe(false);
|
||||
expect(isOwnCompany(null)).toBe(false);
|
||||
});
|
||||
it("в промпте распознавания есть правило про исходящие", () => {
|
||||
expect(buildRecognitionPrompt("/x.pdf", { from: "a", subject: "b" })).toMatch(/ВХОДЯЩИЕ/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user