gigafibre-fsm/services/targo-hub
louispaulb f6d06d9b34 fix(campaigns/match): handle multi-email + dupe SLs + missing postal
Three independent bugs surfaced while debugging why Alexandre Duval
showed as "non lié" in a campaign:

1. ERPNext Customer.email_id can hold multiple addresses joined by
   ';' or ',' (211 records inherited from Legacy migration). The
   exact-match filter missed them. Now LIKE-searches a window then
   validates locally by splitting on ; , or whitespace.

2. Service Locations have duplicates at the same address — the same
   "7 Rue des Merles" exists 3 times, linked to 3 different customers
   (legacy migration artifact). The civic+postal strategy was taking
   the first hit which could be the wrong household. Added name-aware
   disambiguation: when the recipient has a name, walk the candidates
   and pick the one whose linked Customer name plausibly matches.

3. New 4th matching strategy "name+civic" — kicks in when the CSV
   row has no postal_code (most common Map export failure mode). Does
   a street-word filtered SL search and accepts only candidates whose
   Customer name plausibly matches. Confidence 0.65 (vs 0.85 for
   civic+postal).

Also: SQL filter for both civic+postal and name+civic now includes a
street-word LIKE constraint so the result set isn't dominated by
unrelated "7 ..." addresses, bumped limits to 50/100. The SL
denormalized customer_name field is often empty post-import — we now
fall back to a Customer lookup for the name check.

Verified end-to-end against live ERPNext: Alexandre Duval at
7 Rue des Merles now matches correctly via email (multi-value field),
via civic+postal (despite 3 dupe SLs), and via name+civic (no postal).
Gaëtan David at the same address also matches correctly without
collision.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 11:36:51 -04:00
..
data refactor: reduce token count, DRY code, consolidate docs 2026-04-13 08:39:58 -04:00
lib fix(campaigns/match): handle multi-email + dupe SLs + missing postal 2026-05-22 11:36:51 -04:00
preview feat: flow editor, Gemini QR scanner with offline queue, dispatch planning v2 2026-04-22 10:44:17 -04:00
public refactor: major cleanup — remove dead dispatch app, commit all backend code, extract client composables 2026-04-08 17:38:38 -04:00
scripts feat(campaigns): convert existing HTML templates to Unlayer JSON designs 2026-05-22 06:22:47 -04:00
templates feat(campaigns/templates): visible wrapper-expiry date in the email 2026-05-22 10:47:58 -04:00
.env.example feat(hub+ops): user invite flow sends temp password via Mailjet + dev .env.example 2026-05-05 19:50:06 -04:00
docker-compose.yml fix(hub): templates volume mount must be RW for editor saves 2026-05-22 06:49:48 -04:00
package-lock.json feat(campaigns/editor): MJML mode — proper email-focused visual builder 2026-05-21 22:29:42 -04:00
package.json feat(campaigns/editor): MJML mode — proper email-focused visual builder 2026-05-21 22:29:42 -04:00
server.js feat(campaigns): gift redirect wrapper — own expiry + reusable links 2026-05-22 10:15:43 -04:00