Skip to content

fix(sales): remaining invoice sources the accepted new-engine quotation when no deposit notice was issued - #1175

Closed
waritctd wants to merge 3 commits into
developfrom
fix/remaining-invoice-new-engine-source
Closed

waritctd wants to merge 3 commits into
developfrom
fix/remaining-invoice-new-engine-source

Conversation

@waritctd

Copy link
Copy Markdown
Owner

Draft. P0-4 from the 2026-10-22 release review. A new-engine deal on a deposit-bypass policy (CREDIT_CUSTOMER / WAIVED / NOT_REQUIRED) could never get ใบแจ้งหนี้ส่วนที่เหลือ: the shared resolver knew only an ISSUED deposit notice or a legacy quotation + ticket_item.approved_price, which the new engine never writes. Pairs with #1173 (0% quotation → NOT_REQUIRED).

Change (+47 lines, 2 files)

  • DepositNoticeRepository: findAcceptedDealQuotationLines(ticketId) — newest ACCEPTED new-engine quotation's lines with the stored amount.
  • DepositNoticeService#resolveRemainingInvoice: one new branch, fires only under a bypass policy with no ISSUED notice, before the approved_price fallback. Serves getRemainingInvoiceOptions, createDraft, issue. Legacy and notice paths unchanged.

Test-first

  • da839dc7 tests (RED): DealQuotationOutcomeIntegrationTest, 1 error / 37 pass — remainingInvoice_newEngineAcceptedQuotation_depositWaived_sourcesTheQuotationsLines_andIssues → ApiException 409 ไม่พบใบเสนอราคาที่ลูกค้ายอมรับ… at resolveLegacy:730.
  • c8f479c9 fix → 38/0/0. Wider: DepositNoticeServiceTest 48, RemainingInvoiceServiceIT 28, OrderConfirmationIT 13, PaymentTrackIT 14, BillingNoteServiceIT 58, DealQuotationConfirmOrderIT 31, +7 smaller classes, 0 failures.
  • 8ad1ae62 guard assertion (green before and after, by design).

Coverage

Test Pins
…depositWaived_sourcesTheQuotationsLines_andIssues options + draft use the quotation's lines (qty, final price), reference = quotation no., deduction 0, items total = subtotal; issue works, grand total = quotation grand total
…issuedNotice_linesAndDeductionStillComeFromTheNotice_alsoUnderABypassPolicy with an ISSUED notice the notice stays the source (lines edited qty−4 so they differ from the quotation), deduction = notice deposit, depositNoticeId set; still true once the policy reads as a bypass; REQUIRED + no notice → 409
…QuotationOnlyIssued_depositWaived_still409 status filter: an ISSUED-only quotation gives 409 and writes nothing
…nonOwnerSales_refused_writesNothing non-owning sales → 403 on options and createDraft, nothing written

Mutations (implementer 8 + reviewer 4), each killed by a named test except drop ORDER BY…LIMIT 1 (equivalent: a deal cannot hold two ACCEPTED quotations).

Not covered: mixed legacy + new-engine ticket (legacy wins, as before); DEAL_DIRECT route; revision after acceptance; account-side issue flow; multi-line ordering; EN/USD quotations.

Opus review (2026-10-23): APPROVE WITH NOTES — owner rulings pending

  1. HIGH DEAL_DIRECT is still a dead end: the filter takes doc_status='ACCEPTED', but a DEAL_DIRECT quotation only ever reaches APPROVED (DealQuotationRepository:1292; recordOutcome refuses that origin). After fix(sales): a no-deposit quotation puts the deal on the no-deposit payment path #1173 moves 0% direct deals to NOT_REQUIRED they still 409 here. Option: (PRICING_REQUEST AND ACCEPTED) OR (DEAL_DIRECT AND APPROVED) as the deposit autofill already does.
  2. MEDIUM EN/USD quotation: computeRemainingInvoiceMoney applies flat 7% VAT (DepositNoticeService:394), so this path now ISSUES a THB-labelled invoice with VAT on USD lines where before it 409'd (probe: 91,233.09 → 97,619.41). Suggest blocking document_language='EN' in the new branch.
  3. LOW REQUIRED + no notice returns the old 409 "ไม่พบใบเสนอราคาที่ลูกค้ายอมรับ…" (false: there is one) instead of a blockingReason like the legacy "ยังไม่ได้ออกใบแจ้งยอดมัดจำจากใบเสนอราคา X". ~3 lines.

Merge order: conflicts with #1170 and #1173 in DealQuotationOutcomeIntegrationTest.java only; a hunk-level keep-both DROPS a closing brace each time (130/129, 132/131). Resolve by taking each side's method block whole and adding the }. Production files merge clean.

🤖 Generated with Claude Code

waritctd and others added 3 commits October 23, 2026 12:11
…n when the deposit is waived (RED)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on when no deposit notice was issued

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ine deal's remaining invoice

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

vercel Bot commented Oct 23, 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 23, 2026 6:13am UTC

Request Review

@waritctd

waritctd commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Closing: superseded by W5-01 (#1204, released in #1209). DepositNoticeService#resolveFromNewEngineQuotation already bills a bypass-policy deal from the answered new-engine quotation, including EN VAT and the stored total.

@waritctd waritctd closed this Nov 1, 2026

This branch was successfully deployed

1 active deployment
Preview — 8ad1ae62 Deployed Oct 23, 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