fix(invoice): use shippingLine.deliveryCategory as primary pickup signal

Order 1032 on dev still rendered as 'Versandart: Lager Graz' because the
shipping line's title/code/source contained no 'pickup' keyword — only
`shippingLine.deliveryCategory == "pickup"` flagged it as a pickup.

`shippingLine.deliveryCategory` only requires `read_orders` (already
granted), so query and use it as the primary signal. Keep the regex on
title/code/source/carrier as a fallback for custom rates without a proper
pickup category.
This commit is contained in:
Gerhard Scheikl
2026-05-15 15:12:59 +02:00
parent 4e522f41df
commit 8a40bcbee6
25 changed files with 1619 additions and 16 deletions
+33
View File
@@ -168,6 +168,7 @@ function buildAtB2BOrder(): RawOrderForInvoice {
code: "STD",
source: "shopify",
carrierIdentifier: null,
deliveryCategory: "shipping",
originalPriceSet: { shopMoney: { amount: "5.00", currencyCode: "EUR" } },
discountedPriceSet: { shopMoney: { amount: "5.00", currencyCode: "EUR" } },
taxLines: [
@@ -302,6 +303,25 @@ function buildPickupOrder(): RawOrderForInvoice {
code: "Pickup",
source: "shopify",
carrierIdentifier: null,
deliveryCategory: "pickup",
originalPriceSet: { shopMoney: { amount: "0.00", currencyCode: "EUR" } },
discountedPriceSet: { shopMoney: { amount: "0.00", currencyCode: "EUR" } },
taxLines: [],
};
return o;
}
/** Pickup variant where neither title/code nor source mention "pickup" —
* detection must rely purely on `deliveryCategory`. Mirrors what we
* observed on a real Shopify Local Pickup install. */
function buildCategoryOnlyPickupOrder(): RawOrderForInvoice {
const o = buildAtB2BOrder();
o.shippingLine = {
title: "Lager Graz",
code: "Standard",
source: "shopify",
carrierIdentifier: null,
deliveryCategory: "pickup",
originalPriceSet: { shopMoney: { amount: "0.00", currencyCode: "EUR" } },
discountedPriceSet: { shopMoney: { amount: "0.00", currencyCode: "EUR" } },
taxLines: [],
@@ -622,6 +642,19 @@ async function main() {
const pickupEnText = await pdfToText(await renderInvoicePdf(pickupEnVm));
assert("EN pickup PDF shows 'Pick-up location' label", pickupEnText.includes("Pick-up location"));
// Real-world pickup variant: shippingLine has no "pickup" keyword in
// title/code/source — only `deliveryCategory` says it's pickup.
const categoryPickupVm = composeInvoice({
order: buildCategoryOnlyPickupOrder(),
settings: settings as never,
invoiceNumber: "RE-1033",
});
assert("isPickup detected from deliveryCategory alone", categoryPickupVm.isPickup);
assertEq("pickupLocationName from title when category-only",
categoryPickupVm.pickupLocationName, "Lager Graz");
assert("shippingMethod cleared in category-only pickup",
categoryPickupVm.shippingMethod == null);
// Fallback: when footerNoteEn is empty, English uses the German note.
console.log("• Footer note fallback (en → de when EN empty)");
const settingsNoEn = { ...(settings as object), footerNoteEn: "" } as never;