Refine the handling of order_number values in the MCP API. Custom free-text order_numbers are now allowed to repeat across orders without triggering collision checks, while only values formatted as ORD-YYYY-MM-NNN will be subject to collision verification. Update tests to reflect this new behavior and ensure proper functionality.
35 lines
1.8 KiB
JavaScript
35 lines
1.8 KiB
JavaScript
import { readFileSync } from "node:fs";
|
|
import PocketBase from "pocketbase";
|
|
const envLocal = readFileSync(".env.local", "utf8");
|
|
for (const line of envLocal.split("\n")) {
|
|
const m = line.match(/^([A-Z0-9_]+)\s*=\s*(.+?)\s*$/);
|
|
if (m && !process.env[m[1]]) process.env[m[1]] = m[2].replace(/^["']|["']$/g, "");
|
|
}
|
|
const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL);
|
|
await pb.admins.authWithPassword(process.env.PB_ADMIN_EMAIL, process.env.PB_ADMIN_PASSWORD);
|
|
|
|
let numChecked = 0, orderAttempted = 0, dnAttempted = 0, total = 0;
|
|
for (let p = 1; p <= 30; p++) {
|
|
const r = await pb.collection("orders").getList(p, 200, {
|
|
fields: "id,order_number_duplicate_checked,duplicate_order_matching_attempted,delivery_note_matching_attempted",
|
|
sort: "created",
|
|
});
|
|
for (const o of r.items) {
|
|
total++;
|
|
if (o.order_number_duplicate_checked === true) numChecked++;
|
|
if (o.duplicate_order_matching_attempted === true) orderAttempted++;
|
|
if (o.delivery_note_matching_attempted === true) dnAttempted++;
|
|
}
|
|
if (r.items.length < 200) break;
|
|
}
|
|
const hits1 = await pb.collection("orders").getList(1, 100, {
|
|
filter: 'order_number_duplicate != "" && order_number_duplicate != null',
|
|
});
|
|
const hits2 = await pb.collection("orders").getList(1, 100, {
|
|
filter: 'potential_duplicate_order != "" && potential_duplicate_order != null',
|
|
});
|
|
const hits3 = await pb.collection("orders").getList(1, 100, {
|
|
filter: 'potential_delivery_note != "" && potential_delivery_note != null',
|
|
});
|
|
console.log(`total=${total} num=${numChecked} (${(numChecked/total*100).toFixed(1)}%) order=${orderAttempted} (${(orderAttempted/total*100).toFixed(1)}%) dn=${dnAttempted} (${(dnAttempted/total*100).toFixed(1)}%)`);
|
|
console.log(`hits: order-num=${hits1.totalItems} item-dup=${hits2.totalItems} dn=${hits3.totalItems}`);
|