3.5 KiB
Quotation Create 400 Investigation - 2026-06-30
Scope
Investigate why quotation creation fails with POST /api/crm/quotations -> 400.
Summary
The failure is reproducible on the running local app and the API returns:
{"message":"Missing product type code configuration quotation type."}
This happens inside the document-sequence layer during quotation code generation, not in the quotation form schema itself.
Reproduction
- Sign in with seeded UAT admin account:
admin.uat@alla.localUatDemo123!
- Submit a valid-looking quotation payload to
POST /api/crm/quotations. - The API returns
400with message:Missing product type code configuration quotation type.
Reproduced against the local app at http://localhost:3000 with authenticated session.
Findings
- Quotation creation reaches createQuotation(), passes quotation payload validation, and then calls
generateNextDocumentCode()for document code allocation. - The failure occurs inside the document-sequence product-type resolution path in src/features/foundation/document-sequence/service.ts and generateNextDocumentCode().
- Database inspection shows the organization does have valid master options for both:
crm_quotation_type:crane,dockdoor,solarcell,service,othercrm_product_type:crane,dockdoor,solarcell,service,sparepart
- Database inspection also shows quotation document sequences already exist for:
cranedockdoorsolarcellservice
- Because both option categories and document-sequence rows are present, the
400is not caused by missing seed data inms_optionsor missing quotation sequence rows. - The remaining failure point is the runtime mapping logic that resolves a quotation type id/code into the product-type code used by document sequences. That logic is currently rejecting a valid quotation type before sequence generation completes.
Likely Root Cause
The product-type map resolution in src/features/foundation/document-sequence/service.ts is not successfully resolving the incoming quotation type id/code to a usable document-sequence product type, even though:
- the quotation type option exists
- the product type option exists
- the document sequence row exists
In other words, this is a mapping bug in the document-sequence resolution path, not a missing reference-data problem in the quotation form.
Secondary Observation
The frontend currently surfaces quotation create failures through apiClient as generic API error: 400 Bad Request, which hides the backend message unless the request is inspected manually. That makes this class of failure harder to diagnose from the UI alone.
Status
- Investigation completed
- Root cause area identified
- No production code fix applied in this investigation round
Recommended Next Step
Patch the document-sequence product-type resolution so quotation type ids from quotation creation resolve consistently to the corresponding crm_product_type code before generateNextDocumentCode() runs.