Skip to content

fix(import): creating the IR issues one per factory at once; lead-time popup - #1199

Merged
waritctd merged 2 commits into
developfrom
fix/ir-create-issues-immediately
Oct 29, 2026
Merged

waritctd merged 2 commits into
developfrom
fix/ir-create-issues-immediately

Conversation

@waritctd

Copy link
Copy Markdown
Owner

Ploy's rulings from 2026-10-29: a new import request has no DRAFT step any more. สร้างใบขอซื้อ (IR) now creates and issues one IR per factory in a single step. The deal moves to ขั้น 12, and every factory shows up on the import team's งานนำเข้า page straight away, in sync with the deal's จัดซื้อ-ส่งมอบ tab.

Why: with several factories, the deal reached ขั้น 12 on the first ออกเลข. The main button then disappeared while the other factories were still DRAFT, and nothing reminded sales of them.

Rulings

  1. Create issues straight away, one IR per factory. This reverses the "create and issue separately" part of the QA-09 ruling.
  2. Revisions keep their edit step: ออกฉบับแก้ไข still opens an editable DRAFT copy, and ออกเลข on it replaces the old IR.
  3. A factory with no lead time (none from the quotation and no country default) gets a lead-time popup, built like the new-factory country popup. It asks for min–max days for just those factories, and Retry creates and numbers all of them. Cancel creates nothing.
  4. Any DRAFT IRs left on existing deals stay as they are. They keep their ออกเลข button, and there is no data migration.

Changes

  • ImportRequestService.createDrafts:
  • New optional leadTimes in the create request: [{factoryName, minDays, maxDays}], matched by the same factory-name normalisation the country flow uses.
    • Values are validated before any write: 1–365 and min ≤ max, otherwise 400.
    • A value fills only a factory that has no lead time from the quotation or the country default.
    • If a lead time is still missing, the 409 says กรุณาระบุระยะเวลานำเข้าให้กับโรงงาน: … and lists only the factories still missing one.
  • DealFulfilmentPanel:
    • New FactoryLeadTimeModal. The country popup comes first, then the lead-time popup, and the final retry carries both answers. A retry guard stops it looping.
    • Button and toast wording is now ออกใบขอซื้อ (IR).
  • mockApi mirrors the backend.
  • The e2e spec and its helper no longer issue rows that create has already issued.
  • No API path or method changes, so no digest regen.

Test coverage (written first, shown red)

  • StoredImportRequestIntegrationTest:
    • createDrafts_issuesEveryFactoryInOneStep_andMovesTheDealToProcurement: 2 factories, both ISSUED, distinct doc numbers, step CONTACTED, fulfilment status IR_ISSUED, stage PROCUREMENT.
    • createDrafts_isAllOrNothing_whenOneNewFactoryHasNoLeadTime.
  • ImportRequestPaymentGateIntegrationTest.createDrafts_isRefused409_andWritesNothing_onADealWithNoDepositYet.
  • ImportRequestLeadTimeIntegrationTest:
    • the 409 lists only the factories missing a lead time and writes nothing;
    • with only some lead times supplied, the 409 lists the rest;
    • supplied values issue every row with them, and defaults are kept elsewhere;
    • a bad value gives 400 and writes nothing;
    • a supplied value is ignored when the factory already has a default.
  • DealFulfilmentPanel.test.jsx:
    • after create, the toast reads "ออกใบขอซื้อ (IR) แล้ว" and there is no ออกเลข button;
    • the lead-time popup: it opens; Retry is disabled until every row is filled and while min > max; Cancel creates nothing; the country popup then the lead-time popup chain; the retry guard.
  • Existing tests that relied on create making a DRAFT were updated. Tests that need a DRAFT now seed one with the new DraftSeed helper.

Not covered:

  • a factory with no items (create never builds one);
  • the ขั้น 11 main button reaching the popup (it uses the same requestCreateIrDrafts path);
  • a factory name with a comma (the same limit the country popup has).

Verification

  • Opus review: verdict MERGE after one FIX round. The reviewer reverted the fix and saw all the new tests fail.
  • Targeted backend run after the rebase, on a throwaway Postgres DB with fork=1: the importrequest classes plus ImportDealAuthz and DealQuotationConfirmOrder, 223 tests, 0 failures.
  • Targeted frontend run: 445 tests across the panel, deal page, fulfilment page, mockApi and salesActions. eslint is clean.
  • In-app check on a real backend:
    • A 2-factory deal (Panaria and a new factory, Rex Ceramics QA) went through the country popup, then the lead-time popup, and both IRs were numbered in one step: Panaria 75–90 days, Rex 30–45 days.
    • The deal moved to ขั้น 12, and it appeared on งานนำเข้า right away.
    • I advanced Rex there, and the import team's deal page and the sales rep's tab both showed the new step.

🤖 Generated with Claude Code

…e popup

Owner rulings 2026-10-29: no DRAFT step for a new import request.
สร้างใบขอซื้อ (IR) now creates AND issues one IR per factory in a single
transaction, so the deal moves to ขั้น 12 and every factory shows on the import
fulfilment page right away, in sync with the deal's จัดซื้อ-ส่งมอบ tab.

- createDrafts checks every new factory before any write (items, lead time,
  deposit gate) and issues each through the extracted issueStoredDraft; a
  failure writes nothing.
- A factory with no lead time from the quotation or country default gets a
  popup (like the new-factory country popup) asking min-max days; the 409
  lists only those factories and the retry carries the values (1-365, min<=max).
- Revisions keep their edit DRAFT; leftover DRAFT rows still issue as before.
- Button and toast wording now says ออกใบขอซื้อ (IR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
demo-glr Ready Ready Preview Oct 29, 2026 6:49am UTC

Request Review

…or the deposit

Code review of #1199:
- createDrafts checks requireImportRequestIssuable right after the stage
  check, so an unpaid deal is refused at the first press instead of after
  the country and lead-time popups.
- The deal tab's ออกใบขอซื้อ (IR) button is disabled with the hint
  "ออกใบขอซื้อ (IR) ได้หลังรับชำระมัดจำแล้ว" until the deal is deposit-ready
  (depositReadyForIr mirrors TicketService#requireImportRequestIssuable); the
  imperative entry point refuses early with the same message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@waritctd
waritctd merged commit f0eb570 into develop Oct 29, 2026
7 checks passed

This branch was successfully deployed

1 active deployment
Preview — c148bee8 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant