fix: per-site attribution needs its own column, not pickuplocationid
Caught by testing the previous commit against production: creating a booking with a resolved site failed with pickupbookings_pickuplocationid_fkey FOREIGN KEY (pickuplocationid) REFERENCES appcustomerlocations(...) pickuplocationid is the *customer's* saved address, a B2C concept. It never referred to the client company's own kitchens or branches. The pre-existing code that validated an incoming pickuplocationid against TenantLocation was wrong on the same point and would have 500'd for any caller that used it — it had simply never been called with a value. Adds tenantlocationid to pickupbookings and consignments (nullable, indexed, additive via AutoMigrate), carried across at pickup, and points the reporting filter, the by_location breakdown and the Unattributed bucket at it. The booking request accepts tenantlocationid, and still accepts pickuplocationid as an alias so anything written against the earlier docs starts working instead of failing. Also gofmt on the two model files touched; booking.go was already failing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,7 +128,7 @@ tenants at once aren't a meaningful report, so it 400s without one.
|
||||
|
||||
The same rows appear as `by_location` inside `GET /admin/reports`.
|
||||
|
||||
**Send `pickuplocationid` on bookings.** Attribution depends on it. The server
|
||||
**Send `tenantlocationid` on bookings.** Attribution depends on it. The server
|
||||
will try to recognise the site from the pickup coordinates (within 150m) or a
|
||||
matching address, but an explicit id is exact and always wins.
|
||||
|
||||
@@ -266,8 +266,8 @@ delivered, riderkms, ridercharges, dutyminutes }`.
|
||||
POST /admin/expressbooking
|
||||
{
|
||||
"tenantid": 13, // required; forced to your own tenant on client logins
|
||||
"pickuplocationid": 15, // a stored kitchen/branch — fills address, pincode and
|
||||
// coords for you, and is what makes per-site reporting work
|
||||
"tenantlocationid": 13, // a stored kitchen/branch — fills address, pincode and
|
||||
// coords for you, and is what per-site reporting groups by
|
||||
"customer_phone": "9876543210", // creates a Guest customer if unknown
|
||||
"customer_name": "Ramesh",
|
||||
"deliveryaddress": "12 Cross Cut Road, Gandhipuram",
|
||||
@@ -286,8 +286,12 @@ POST /admin/expressbooking
|
||||
|
||||
Rules worth knowing:
|
||||
- `parcels` must be non-empty and `tenantid` must exist.
|
||||
- Pickup address + pincode are required **unless** `pickuplocationid` supplies them.
|
||||
- A `pickuplocationid` belonging to another tenant is rejected.
|
||||
- Pickup address + pincode are required **unless** `tenantlocationid` supplies them.
|
||||
- A `tenantlocationid` belonging to another tenant is rejected.
|
||||
- `pickuplocationid` is accepted as an alias for `tenantlocationid`, for anything
|
||||
written against the earlier version of this doc. Prefer the new name: the
|
||||
database column called `pickuplocationid` means something else entirely (the
|
||||
B2C customer's saved address) and is not what per-site reporting uses.
|
||||
- **CityGate**: the pickup pincode prefix must be an open city — `641`
|
||||
Coimbatore, `600` Chennai, `560` Bengaluru, `500` Hyderabad, `629` Nagercoil.
|
||||
Any other prefix is refused at the middleware, before the handler runs.
|
||||
|
||||
Reference in New Issue
Block a user