Skip to content

feat: plot sales lifecycle v2 close/terminate, payment sync, cost tracking, TCB v0.6#39

Merged
av-dev2 merged 1 commit into
version-15from
backport-38-to-version-15
May 29, 2026
Merged

feat: plot sales lifecycle v2 close/terminate, payment sync, cost tracking, TCB v0.6#39
av-dev2 merged 1 commit into
version-15from
backport-38-to-version-15

Conversation

@github-actions
Copy link
Copy Markdown

Backport of #38 to version-15.


Summary

This PR completes the core plot sales lifecycle and fixes several accounting
issues discovered during testing.

Sales Order Close & Contract Termination

  • Added Close Sales Order button (Actions menu) with full downstream effects:
    forfeiture JE, credit note, TCB decline, plot release, PA cancellation
  • Fixed contract termination to set SO status = Closed (not Cancel) so all
    accounting entries are preserved as audit trail
  • Credit note now correctly zeros SI outstanding via update_outstanding_for_self=0
  • Fixed draft contract total_paid persistence — _persist_payment_sync_state
    now uses db.set_value instead of save() to prevent validate() resetting values
  • Removed incorrect advance row zeroing from _sync_contract_after_payment

Payment Sync

  • Moved from background job to synchronous execution — eliminates
    TimestampMismatchError from concurrent syncs and worker dependency
  • Overpayment now detected via pe.unallocated_amount and shown on Plot Contract
  • SI payment schedule rows synced alongside SO rows on each payment
  • cost_center auto-enforced on all JE rows where land_acquisition is set

Government Share JE

  • Auto-posted per payment at government_share_percent
  • Cancelled automatically when the linked Payment Entry is cancelled

TCB v0.6

  • paymentOption (Partial/Exact), expireDate, amount wired to Sales Order fields
  • All three fields are optional — only sent to TCB when explicitly set

Land Acquisition Cost Tracking

  • JE amounts now included in acquisition_cost_tzs via _fetch_billed_from_je
  • je_billed_tzs field added to LA form with drill-down table showing each JE
  • Recalculate Plot Costs button: background job that updates stock valuations
    for unsold plots when late PIs arrive; skips delivered/Title Closed plots
  • cost_per_sqm now updated on all plots including unchanged-cost ones

Reports & UI

  • Government Payable report rebuilt for per-payment JE model with LA filter
  • Title Closed folded into Delivered in all counts and reports
  • Sales Invoice before_save hook: clears deferred revenue fields, restores
    Balance payment schedule row if ERPNext collapsed it
  • Journal Entry before_save hook: enforces LandMS cost center on LA rows

…fixes

Sales Order & Contract:
- Add Close Sales Order button with forfeiture JE, credit note, TCB decline
- Fix _cancel_unpaid_plot_sales_invoice: throw → return on partial payments
- Fix contract termination: SO set to Closed (not Cancelled) to preserve audit trail
- Fix credit note update_outstanding_for_self=0 to zero SI outstanding
- Fix _persist_payment_sync_state: use db.set_value for draft contracts
  to prevent validate() resetting total_paid to 0
- Remove advance row zeroing from _sync_contract_after_payment
- Add overpayment detection via pe.unallocated_amount on contract
- Handle TimestampMismatchError on contract auto-submit

Payment Sync:
- Move from background job to synchronous execution
- Pass pe_name through sync chain for overpayment detection
- Add _sync_si_schedule_for_so to sync SI payment schedule rows
- Auto-fill cost_center on JE rows when land_acquisition is set

Government Share JE:
- Auto-post per payment at government_share_percent
- Cancel JE when linked Payment Entry is cancelled

TCB v0.6:
- Wire paymentOption, expireDate, amount fields to Sales Order
- Add relatedRef support via related_control_number

Land Acquisition Cost Tracking:
- Add JE cost sync via hooks.py and _fetch_billed_from_je
- Add je_billed_tzs field on LA form with drill-down table
- Add Recalculate Plot Costs background job button
- Fix cost_per_sqm update for unchanged plots on re-run
- Add one-time migration patch for LA cost backfill

Reports & UI:
- Rebuild Government Payable report for per-payment JE model
- Fold Title Closed into Delivered in plot inventory report and chart
- Add Sales Invoice before_save hook: clear deferred revenue, restore Balance row
- Add Journal Entry before_save hook: enforce LA cost center
- Fix SI Balance row restoration: reverse-lookup SO via plot_sales_invoice

Schema:
- New fields: je_billed_tzs, je_summary_html on Land Acquisition
- New fields: last_recalculation_cost/date/log/in_progress on Land Acquisition
- New fields: recalculation_section on Land Acquisition
- New custom fields: paymentOption, include_expire_date, include_amount on Sales Order

(cherry picked from commit 2fe579d)
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.

2 participants