Skip to content

[16.0][ADD] advance_payment_receipt_kmitl: issue receipt on advance return - #1255

Open
n3n wants to merge 6 commits into
16.0from
16.0-review-advance-payment-refund-receipt
Open

[16.0][ADD] advance_payment_receipt_kmitl: issue receipt on advance return#1255
n3n wants to merge 6 commits into
16.0from
16.0-review-advance-payment-refund-receipt

Conversation

@n3n

@n3n n3n commented Sep 3, 2026

Copy link
Copy Markdown
Member

When a returned advance is approved, the office must now issue a proper cash receipt (ใบเสร็จรับเงิน) instead of the old draft inbound account.payment, which never posted and left the money-in unreceipted.

This adds a small extension seam to advance_payment (_settle_return/_cancel_return_settlement on the return line, behaviour unchanged when no bridge is present) and a new advance_payment_receipt_kmitl bridge that overrides it to issue a draft kmitl.receipt — the single money-in + accounting document — copying the agreement's partner and analytic dimensions, taking its product and payment method from Settings, and flowing through the normal remittance workflow. Admin-reset cancels a draft receipt and is blocked once the receipt has entered remittance/posting. The bridge depends on advance_payment_budget (which supplies the agreement's analytic dimensions the receipt requires) and receipt_kmitl; static-verified (pyflakes + xmllint) with tests for the happy path, missing-config, and admin-reset cases.

@n3n
n3n force-pushed the 16.0-review-advance-payment-refund-receipt branch 2 times, most recently from a976dc1 to 0656723 Compare September 3, 2026 18:16
n3n added 6 commits September 6, 2026 16:13
Extract the money-in creation in advance.payment.return.line from
action_approve/action_admin_reset into two overridable methods,
_settle_return() and _cancel_return_settlement(). Behaviour is
unchanged (still a draft inbound account.payment) when no bridge
overrides them; this lets a bridge settle a return through a different
document without re-implementing action_approve.
Bridge advance_payment_budget and receipt_kmitl: when a returned
advance is approved, override the base return-settlement seam to issue
a draft kmitl.receipt (the single money-in + accounting document)
instead of a draft inbound account.payment, avoiding a double count.
The receipt copies the agreement's partner and analytic dimensions, its
product and payment method come from Settings, and it flows through the
normal remittance workflow. Admin-reset cancels a draft receipt and is
blocked once it has entered remittance/posting.
Replace the auto-issued receipt on approval with an explicit officer step:
the loan officer records the receiving transfer method and date on the
return line, then presses "สร้างใบเสร็จรับเงิน" to both create the
kmitl.receipt and finalize the return in one action.

- Return line gains receipt_payment_method_id (transfer-only) and
  receipt_transfer_date, editable while pending_review.
- Receipt vals are built from the line's officer-entered data instead of a
  config-only payment method; payment type is hard-set to transfer.
- Guard against agreements with no department dimension set, and against a
  missing receiving method, with clear UserErrors instead of a raw DB
  constraint failure.
- Smart buttons: return line -> receipt, receipt -> advance agreement.
- Receipt description/line description now include the agreement, borrower,
  and loan reason instead of being auto-derived only from config.
…scription

Keep the header description to the agreement number and borrower name.
Remove the to_verify_report / to_reconcile review states from the loan
lifecycle. Reporting the actual expense and returning leftover money both
happen freely while in_progress; closing the agreement is never automatic
anymore, the loan officer must press "ปิดสัญญา" once the debt is settled.

- state: draft -> to_verify -> to_approve -> waiting_transfer -> in_progress
  -> done (+ cancel), collapsing the previous report/reconcile substates.
- action_submit_report stays in_progress; action_accept_report and
  _try_auto_close are removed; action_close becomes the explicit,
  loan-officer-gated close action.
- Return line confirm / return wizard confirm now check state == in_progress
  instead of to_reconcile.
- Views: drop the "ตรวจรับรายงาน" button, add "ปิดสัญญา", fix the "รอคืนเงิน"
  banner and "แจ้งคืนเงิน" visibility to key off amount_remaining, collapse
  the dead search filters, update statusbar/decorations.
- advance_payment_followup.DEBTOR_STATES collapses to (in_progress,).
- Update advance_payment and advance_payment_receipt_kmitl tests for the new
  lifecycle (explicit action_close, no auto-close assertions).
The loan officer has no ACL read access to account.analytic.plan, but
department_analytic_id computes by walking it — reading it in the officer's
own user context raised AccessError when pressing "สร้างใบเสร็จรับเงิน".
Sudo the read, same rationale as the receipt create() call right below it.
@n3n
n3n force-pushed the 16.0-review-advance-payment-refund-receipt branch from cd1f062 to b857a6f Compare September 6, 2026 09:13
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