[object Object]

← back to Filemaker Mcp

sync: every order also creates one no-$ per-SKU tracking record with the DW SKU in 'WC Pattern Number AKA DW SKU'; verified 8/8 on order 32476

ea51d97a3d806be31200c5e9e8d2134b3d9932d2 · 2026-06-29 13:27:12 -0700 · Steve

Files touched

Diff

commit ea51d97a3d806be31200c5e9e8d2134b3d9932d2
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jun 29 13:27:12 2026 -0700

    sync: every order also creates one no-$ per-SKU tracking record with the DW SKU in 'WC Pattern Number AKA DW SKU'; verified 8/8 on order 32476
---
 lib/invoice.js   | 10 +++++-----
 lib/sync-core.js | 10 +++++++++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/invoice.js b/lib/invoice.js
index dc6c6c7..014d856 100644
--- a/lib/invoice.js
+++ b/lib/invoice.js
@@ -59,12 +59,12 @@ async function patch(id, field, value) {
 const MAX_LINES = 4; // DETAIL 1 / Q1 / NET 1 family caps at maxRepeat 4
 
 // Create one no-dollar tracking record per SKU in the order, with the DW SKU in
-// the 'wc pattern no' field (which looks up the pattern Name/Color). Separate
-// from the billing invoice. Returns the created SKUs.
-const WCPATNO_LAYOUT = '1-order detail 1 Copy3'; // has 'wc pattern no', shares header base table
+// the writable "WC Pattern Number AKA DW SKU" field (FileMaker's pattern Name/Color
+// lookup keys off it when opened/imported in the client). Separate from the
+// billing invoice. Returns the created records.
 export async function createSkuRecords(order, accountNumber, clientName, { commit = true } = {}) {
   const items = order.line_items || [];
-  const skus = items.map((li) => wcPattern(li.sku));
+  const skus = items.map((li) => wcPattern(li.sku)); // base DW SKU, sample-stripped
   if (!commit) return { wouldCreate: skus.length, skus };
   const created = [];
   for (const sku of skus) {
@@ -73,7 +73,7 @@ export async function createSkuRecords(order, accountNumber, clientName, { commi
       'SOLD NAME': clientName || '', 'Date': today(),
     }, { dryRun: false }).catch(() => null);
     if (!res) continue;
-    try { await fm.updateRecord('invoice', WCPATNO_LAYOUT, res.recordId, { 'wc pattern no': sku }, { dryRun: false }); } catch {}
+    try { await fm.updateRecord('invoice', DWSKU_LAYOUT, res.recordId, { [DWSKU_FIELD]: sku }, { dryRun: false }); } catch {}
     created.push({ recordId: res.recordId, sku });
   }
   return { created, skus };
diff --git a/lib/sync-core.js b/lib/sync-core.js
index 8f6889a..c92e49f 100644
--- a/lib/sync-core.js
+++ b/lib/sync-core.js
@@ -91,9 +91,16 @@ export async function syncOrder(order, { commit = true } = {}) {
   }
 
   // 2) invoice
-  const { createInvoiceForOrder } = await import('./invoice.js');
+  const { createInvoiceForOrder, createSkuRecords } = await import('./invoice.js');
   const inv = await createInvoiceForOrder(order, accountNumber, { commit });
 
+  // 2b) one no-$ per-SKU tracking record (DW SKU field) for every order
+  let skuRecs = null;
+  if (commit) {
+    try { skuRecs = await createSkuRecords(order, accountNumber, mapped.fields['Company'], { commit }); }
+    catch (e) { skuRecs = { error: e.message }; }
+  }
+
   // 3) Slack alert (only on real commit)
   let slack = null;
   if (commit) {
@@ -107,6 +114,7 @@ export async function syncOrder(order, { commit = true } = {}) {
     action: commit ? 'processed' : 'would-process',
     client: clientAction, accountNumber, company: mapped.fields['Company'], email: mapped.fields['Email address'],
     invoiceNumber: inv.invoiceNumber, invoiceTotal: inv.grandTotal,
+    skuRecords: skuRecs?.created?.length ?? 0,
     slack: slack?.ok ? 'posted' : (slack?.error || 'n/a'),
     matchedOn: dupes.length ? [...new Set(dupes.flatMap((d) => d.why))] : undefined,
   };

← 707cde7 invoice: populate 'WC Pattern Number AKA DW SKU' from primar  ·  back to Filemaker Mcp  ·  invoice: strip dashes in WC Pattern Number AKA DW SKU; write f9e757d →