fix(booking-edit): recalcul du prix cassé par le format du nom transporteur
La recherche de tarif renvoie le transporteur en slug ("ssc-consolidation")
alors que la réservation stocke le nom d'affichage ("SSC Consolidation"), donc
le matching exact companyName === carrierName ne trouvait jamais l'offre →
"aucun tarif trouvé" et prix jamais recalculé.
Matching robuste : comparaison normalisée du transporteur (minuscules, sans
séparateurs) + conteneur + transit, avec fallbacks. Vérifié en conditions
réelles (GET booking, search-csv-offers, PATCH details renvoient 200 ; le prix
change bien quand le volume change).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
bce77edd76
commit
25fe78ccfc
@ -145,17 +145,25 @@ export default function EditBookingPage() {
|
|||||||
hasDangerousGoods: false,
|
hasDangerousGoods: false,
|
||||||
});
|
});
|
||||||
const results = response.results || [];
|
const results = response.results || [];
|
||||||
|
|
||||||
|
// The rate search returns the carrier as a slug (e.g. "ssc-consolidation")
|
||||||
|
// while the booking stores the display name ("SSC Consolidation"), so carriers
|
||||||
|
// are compared on a normalized form. Container + transit uniquely identify the
|
||||||
|
// originally chosen offer for the route, and are the primary match keys.
|
||||||
|
const norm = (s: string) => (s || '').toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
|
const carrier = norm(booking.carrierName);
|
||||||
|
const sameContainer = (r: any) => r.containerType === booking.containerType;
|
||||||
|
const sameTransit = (r: any) =>
|
||||||
|
(r.adjustedTransitDays ?? r.transitDays) === booking.transitDays;
|
||||||
|
const sameCarrier = (r: any) => norm(r.companyName) === carrier;
|
||||||
|
|
||||||
const match =
|
const match =
|
||||||
results.find(
|
results.find((r: any) => sameCarrier(r) && sameContainer(r) && sameTransit(r)) ||
|
||||||
(r: any) =>
|
results.find((r: any) => sameContainer(r) && sameTransit(r)) ||
|
||||||
r.companyName === booking.carrierName &&
|
results.find((r: any) => sameCarrier(r) && sameContainer(r)) ||
|
||||||
r.containerType === booking.containerType &&
|
results.find((r: any) => sameCarrier(r)) ||
|
||||||
(r.adjustedTransitDays ?? r.transitDays) === booking.transitDays
|
results.find((r: any) => sameContainer(r)) ||
|
||||||
) ||
|
null;
|
||||||
results.find(
|
|
||||||
(r: any) =>
|
|
||||||
r.companyName === booking.carrierName && r.containerType === booking.containerType
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!match) return null;
|
if (!match) return null;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user