Skip to content

Fix unsupported credit sale settlement#79

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-d0bd
Draft

Fix unsupported credit sale settlement#79
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-d0bd

Conversation

@cursor

@cursor cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown

Bug and impact

  • The checkout UI exposed payment_method=credit, and the sales backend accepted arbitrary payment method strings because the active SaleForm only validates remark.
  • A cashier could complete a sale as credit; the system would mark it COMPLETED, deduct inventory, and update member spend/points without recording receivables, deducting balance, or otherwise settling payment.
  • Draft sale completion accepted the same unsupported value.
  • Sale detail GET also rewrote persisted totals from line items, which could mutate historical completed sales and desynchronize reporting/member transaction records.

Root cause

  • Payment method normalization only mapped legacy account to balance; it did not validate values against implemented Sale.PAYMENT_METHODS.
  • The one-step checkout template reintroduced the unsupported credit button.
  • sale_detail contained read-time repair logic that wrote sale totals via raw SQL.

Fix

  • Added shared payment method normalization/validation while preserving account -> balance.
  • Reject unsupported payment methods in sale creation and completion; reject one-step mixed because that flow has no mixed-settlement handling.
  • Replaced the checkout credit button with supported other.
  • Removed hardcoded 855.33 amount fallback and made invalid totals fail.
  • Made sale detail read-only.
  • Added regression tests for unsupported credit submission, checkout UI exposure, and read-only sale detail.

Validation

  • mkdir -p logs && .venv/bin/python manage.py test inventory.tests.test_sales_balance_payment inventory.tests.test_sale_status && .venv/bin/python manage.py check
  • Result: 14 tests OK; only existing staticfiles.W004 warning for missing /workspace/static.
Open in Web View Automation 

cursoragent and others added 2 commits June 29, 2026 11:04
Co-authored-by: Xianist Lab <zhtyyx@users.noreply.github.com>
Co-authored-by: Xianist Lab <zhtyyx@users.noreply.github.com>
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