Skip to content

fix(lease): preserve existing invoice schedules on advance days recalculation - #83

Merged
aakvatech merged 1 commit into
Aakvatech-Limited:version-15-hotfixfrom
iamtalib13:fix/lease-invoice-schedule-recalculation
Sep 3, 2026
Merged

fix(lease): preserve existing invoice schedules on advance days recalculation#83
aakvatech merged 1 commit into
Aakvatech-Limited:version-15-hotfixfrom
iamtalib13:fix/lease-invoice-schedule-recalculation

Conversation

@iamtalib13

Copy link
Copy Markdown
Contributor

Summary

Fixes invoice schedule recalculation in the Lease DocType so that changing Days to Invoice in Advance does not modify, delete, or regenerate existing invoice schedule dates.

Newly added lease periods are calculated independently using the updated advance setting.

Changes

  • Preserve existing un-invoiced invoice schedule records during recalculation.
  • Prevent existing date_to_invoice values from being recalculated when advance days are changed.
  • Process existing schedules chronologically using:
    • schedule_start_date ASC
    • creation ASC
  • Fix cleanup logic to check schedule_start_date > lease.end_date instead of date_to_invoice > lease.end_date.
  • Allow users to modify days_to_invoice_in_advance even after invoices have been created.
  • Replace the blocking frappe.msgprint modal with a non-blocking frappe.show_alert notification.

Problem

Previously, changing Days to Invoice in Advance could cause existing un-invoiced schedules to be deleted and regenerated with different date_to_invoice values.

Additionally, schedules were ordered by date_to_invoice, which could produce an incorrect sequence when schedules had different advance-day settings.

Verification

Initial Schedule

Created a monthly Lease from September 2026 to December 2026 with:

  • Days to Invoice in Advance: 5

Generated schedules:

Row Schedule Period Date to Invoice
1 Sep 2026 27-08-2026
2 Oct 2026 26-09-2026
3 Nov 2026 27-10-2026
4 Dec 2026 26-11-2026

Recalculation

Updated:

  • Days to Invoice in Advance: 5 → 10
  • Lease End Date: 28-02-2027

Then generated the Invoice Schedule again.

Result

Existing schedules remained unchanged:

  • 27-08-2026
  • 26-09-2026
  • 27-10-2026
  • 26-11-2026

Only the newly added periods were generated using the updated 10 days advance:

Row Schedule Period Date to Invoice
5 Jan 2027 22-12-2026
6 Feb 2027 22-01-2027

Also verified that the completion notification is displayed as a floating green alert.

Expected Behavior

Changing Days to Invoice in Advance should affect only newly generated invoice schedule periods. Existing schedule records and their invoice dates must remain untouched.

@aakvatech
aakvatech merged commit a3f6d72 into Aakvatech-Limited:version-15-hotfix Sep 3, 2026
3 of 4 checks passed
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Backport failed for version-16-hotfix, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin version-16-hotfix
git worktree add -d .worktree/backport-83-to-version-16-hotfix origin/version-16-hotfix
cd .worktree/backport-83-to-version-16-hotfix
git switch --create backport-83-to-version-16-hotfix
git cherry-pick -x ceee36fd01188b8f4e0bd5a9115d346bdada5af0

1 similar comment
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

Backport failed for version-16-hotfix, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin version-16-hotfix
git worktree add -d .worktree/backport-83-to-version-16-hotfix origin/version-16-hotfix
cd .worktree/backport-83-to-version-16-hotfix
git switch --create backport-83-to-version-16-hotfix
git cherry-pick -x ceee36fd01188b8f4e0bd5a9115d346bdada5af0

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Backport failed for version-15, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin version-15
git worktree add -d .worktree/backport-83-to-version-15 origin/version-15
cd .worktree/backport-83-to-version-15
git switch --create backport-83-to-version-15
git cherry-pick -x ceee36fd01188b8f4e0bd5a9115d346bdada5af0

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Backport failed for version-16-hotfix, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin version-16-hotfix
git worktree add -d .worktree/backport-83-to-version-16-hotfix origin/version-16-hotfix
cd .worktree/backport-83-to-version-16-hotfix
git switch --create backport-83-to-version-16-hotfix
git cherry-pick -x ceee36fd01188b8f4e0bd5a9115d346bdada5af0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants