Skip to content

feat(invoice): Show the billed period on each invoice item - #7227

Open
Shariqk3 wants to merge 1 commit into
frappe:developfrom
Shariqk3:feat/invoice-item-billing-period
Open

feat(invoice): Show the billed period on each invoice item#7227
Shariqk3 wants to merge 1 commit into
frappe:developfrom
Shariqk3:feat/invoice-item-billing-period

Conversation

@Shariqk3

Copy link
Copy Markdown
Collaborator

Fixes #4942

Problem

An invoice line tells the customer what was charged and how much. It does not tell the customer when. A partner sees server-1 Storage Add-on for 12 days and cannot tell which 12 days. The same is true after a server resize: the invoice shows two lines for the same server on two plans, but not the day the change happened.

Solution

Each Invoice Item now keeps the first and the last date of the usage records it bills for.

  • period_start and period_end are new read-only Date fields on Invoice Item.
  • add_usage_record widens the period of an item when it adds a usage record to it.
  • remove_usage_record reads the periods back from the usage records that stay, so a cancelled usage record cannot leave a wrong date.
  • The item description names the period. Example: server-1 Storage Add-on for 12 days from 03-08-2026 to 14-08-2026. The description also goes into the invoice PDF.
  • The dashboard invoice table shows a Period column, and the CSV download includes the two dates.

The period comes from the usage records, and not from a new log doctype, because the usage records already hold the date of each charge.

Notes

  • A patch fills the period on the items of draft invoices. Without it, the items that already exist on this month's draft invoice would look like they start on the day of the deploy. Submitted invoices keep an empty period, because their descriptions are final.
  • The description field is now 240 characters, up from 140. The period text adds about 30 characters, and a long site name plus a plan name could pass the old limit.

Tests

Three new tests in test_invoice.py:

  • test_invoice_item_period_covers_first_and_last_usage_record
  • test_invoice_item_period_moves_when_the_first_usage_record_is_cancelled
  • test_invoice_item_description_names_the_billed_period

All 32 tests in press.press.doctype.invoice.test_invoice pass, together with the subscription tests. ruff check, Biome, and semgrep are clean, and the dashboard builds.

🤖 Generated with Claude Code

Customers cannot see when a charge starts or stops. Extra storage or a
resized server looks the same as a full month of use.

Each item now keeps the first and the last date of the usage records it
bills for. The period comes from the usage records, and not from a new
log doctype, because the usage records already hold the date of each
charge.

Fixes frappe#4942

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The PR appears safe to merge after removing the migration’s non-atomic per-invoice commit.

Billing-period behavior is coherent, but a later migration failure can leave only the previously processed invoices updated.

Files Needing Attention: press/press/doctype/invoice/patches/set_item_periods_on_draft_invoices.py

Fix all with Greploop

Fix All in Claude Code Fix All in Codex

Reviews (1): Last reviewed commit: "feat(invoice): Show the billed period on..." | Re-trigger Greptile

invoice.set_item_periods()
for item in invoice.items:
item.db_update()
frappe.db.commit()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Per-invoice migration commits

Committing inside the invoice loop makes the patch non-atomic: an error processing a later invoice leaves earlier invoices updated while the migration remains incomplete. Let the patch runner commit only after the entire patch succeeds.

Suggested change
frappe.db.commit()

Context Used: Guidelines for reviewing Frappe Framework applicat... (source)

Knowledge Base Used: Billing

Fix in Claude Code Fix in Codex

@codecov-commenter

codecov-commenter commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.11111% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.71%. Comparing base (e8fe4ee) to head (c5f0743).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
press/press/doctype/invoice/invoice.py 76.19% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7227      +/-   ##
===========================================
+ Coverage    59.66%   59.71%   +0.05%     
===========================================
  Files         1019     1019              
  Lines        93493    93609     +116     
  Branches      1212     1213       +1     
===========================================
+ Hits         55780    55902     +122     
+ Misses       37690    37684       -6     
  Partials        23       23              
Flag Coverage Δ
dashboard 87.44% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify

mergify Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@shadrak98

Copy link
Copy Markdown
Contributor

@Shariqk3 this solution is overengineered. I have mentioned the simple approach in the comment of the issue. I think this is already fixed by Huzan by showing subscription lists which tracks the same thing.

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.

[Enhancement]: Billing timing information in invoices

3 participants