Skip to content

Add daily lease status automation for Upcoming, Active, and Expired leases#53

Merged
aakvatech merged 3 commits into
version-15from
feat-expired-upcoming-lease
May 7, 2026
Merged

Add daily lease status automation for Upcoming, Active, and Expired leases#53
aakvatech merged 3 commits into
version-15from
feat-expired-upcoming-lease

Conversation

@aakvatech
Copy link
Copy Markdown
Contributor

Summary

This PR adds automated Lease Status updates for system-controlled lease statuses.

The automation updates leases between the following statuses based on lease dates:

  • Upcoming
  • Active
  • Expired

The daily scheduler runs through daily_long and updates only leases that are already in one of the system-controlled statuses. Manual statuses such as Draft, Terminated, Closed, Vacating, Not Materialized, Renewal to Previous Lease, and Adendum to Previous Lease are intentionally not overwritten.

Changes

  • Added set_lease_status() on the Lease document controller.
  • Added get_system_controlled_statuses() helper.
  • Added get_status_for_lease() helper to calculate the correct status based on:
    • start_date
    • end_date
    • skip_end_date
  • Added update_lease_statuses() scheduler method.
  • Added timeline comments when the scheduler changes a Lease Status.
  • Used frappe.db.set_value() for scheduler updates to avoid full document save hooks.
  • Preserved audit visibility through add_comment() on the Lease timeline.

Status Rules

Condition Result
start_date is in the future Upcoming
start_date <= today and end_date >= today Active
end_date < today Expired
skip_end_date is checked Will not be marked Expired
end_date == today Remains Active until the next day

Manual Status Handling

Only these statuses are system-controlled:

  • Upcoming
  • Active
  • Expired

Any other Lease Status is treated as manually controlled and is not updated automatically.

Scheduler

The scheduler method is intended to run under daily_long:

scheduler_events = {
    "daily_long": [
        "propms.property_management_solution.doctype.lease.lease.update_lease_statuses"
    ]
}

@aakvatech aakvatech merged commit a169e4f into version-15 May 7, 2026
1 check was pending
@codacy-production
Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 high · 2 minor

Alerts:
⚠ 3 issues (≤ 0 issues of at least minor severity)

Results:
3 new issues

Category Results
Documentation 2 minor
ErrorProne 1 high

View in Codacy

🟢 Metrics 23 complexity · 0 duplication

Metric Results
Complexity 23
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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