From e67ccbb9cd1aa81b511c85a6ce8bbb5789bad573 Mon Sep 17 00:00:00 2001 From: Hagernesh Date: Mon, 17 Aug 2026 18:10:55 +0000 Subject: [PATCH] fix(eims): stop sending our internal fee-basis tag as MoR's ItemList Unit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Confirmed live 2026-08-17 on INV-20260817-00008: MoR rejected the document with a SCHEMA ERROR on ItemList[0].Unit — 'PER_CONTAINER' (from the line's own metadata.unit) fails MoR's enum (LTR/MTR/101/PCS/ROL/MTS/PKG/SET/KLG), its 8-char max, and its ^[A-Za-z]{3,8}$ regex all at once. line.metadata.unit is our own fee-basis tag (PER_CONTAINER/PER_TON/ PER_ITEM — how a charge is computed) and was never a MoR unit of measure; the mapper was reusing the same field name for two unrelated concepts. Every line now sends the single configured EIMS_UNIT_DEFAULT instead of guessing a per-line value that doesn't exist in MoR's vocabulary. --- .../src/modules/billing/eims-invoice.mapper.spec.ts | 4 +++- .../src/modules/billing/eims-invoice.mapper.ts | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.spec.ts b/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.spec.ts index 6d58a7bec..75d39a500 100644 --- a/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.spec.ts +++ b/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.spec.ts @@ -151,7 +151,9 @@ describe("toEimsInvoice", () => { // EimsLineTax.discount comment in eims-invoice.mapper.ts. Discount: 25, TotalLineAmount: 1050, - Unit: "CTR", + // Not "CTR" from the line's metadata.unit — that's our internal fee-basis tag, not a MoR + // unit of measure, and is never read for this field (see the mapper's own comment). + Unit: "PCS", }); expect(doc.ValueDetails).toEqual({ Discount: null, diff --git a/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.ts b/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.ts index b8755c709..c72e61c7a 100644 --- a/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.ts +++ b/apps/edr-freight-api/src/modules/billing/eims-invoice.mapper.ts @@ -463,7 +463,13 @@ export function toEimsInvoice( const PreTaxValue = round2(num(line.amount)); const TaxAmount = round2((PreTaxValue * tax.ratePercent) / 100); const ExciseTaxValue = round2(tax.exciseTaxValue); - const unit = typeof line.metadata?.unit === "string" ? line.metadata.unit : context.unitDefault; + // `line.metadata.unit` is our own fee-basis tag (PER_CONTAINER/PER_TON/PER_ITEM — how a charge + // is computed, see the fee-rule docs), never a MoR unit of measure — sending it as-is here + // (confirmed live 2026-08-17: "PER_CONTAINER" fails Unit's enum, its 8-char max, and its regex + // all at once) is what a prior version of this mapper did by mistake. MoR's own enum + // (LTR/MTR/101/PCS/ROL/MTS/PKG/SET/KLG) has no freight-shipment concept at all, so every line + // uses the single configured default rather than guessing a per-line value that doesn't exist. + const unit = context.unitDefault; return { Discount: round2(tax.discount),