Skip to content

feat: add Process Loan Statement of Accounts#1300

Open
Nihantra-Patel wants to merge 13 commits into
frappe:developfrom
Nihantra-Patel:feat/process-loan-statement-of-accounts
Open

feat: add Process Loan Statement of Accounts#1300
Nihantra-Patel wants to merge 13 commits into
frappe:developfrom
Nihantra-Patel:feat/process-loan-statement-of-accounts

Conversation

@Nihantra-Patel

@Nihantra-Patel Nihantra-Patel commented Jun 25, 2026

Copy link
Copy Markdown
Member

Adds a lending-side equivalent of ERPNext's Process Statement Of Accounts. It lets users configure and send Loan Statement of Account statements to a set of applicants (Customer/Employee) on a chosen date, with optional scheduled auto-emailing.

It reuses the existing Loan Statement of Account report as the data source and renders a per-applicant PDF from it.

image image Screenshot 2026-06-26 at 11 05 57 AM

Nihantra-Patel and others added 4 commits June 16, 2026 15:42
Adds a lending-side equivalent of ERPNext's Process Statement Of
Accounts that generates and emails "Loan Statement of Account"
statements to configured applicants (Customer/Employee), with optional
scheduled auto-emailing.

Details:
- New "Process Loan Statement of Accounts" doctype with report filters
  (company, date range, loan product, currency, view), applicant
  collection, print preferences, email settings, schedule, and Jinja
  email content (subject/body/pdf name).
- New "Process Loan Statement of Accounts Applicant" child table
  (applicant type/applicant/name/email) with auto-fill of name & email
  on manual selection or via Fetch Applicants.
- Reuses the existing "Loan Statement of Account" report as the data
  source; renders per-applicant PDFs via a Jinja print template.
- Send Emails / Download form actions and a Fetch Applicants helper.
- Daily scheduler hook (send_auto_email) sends due statements and rolls
  the date window forward by the configured frequency.
- Tests covering validation, filter mapping, HTML rendering, currency
  override, applicant detail lookup, and empty-data skipping.
@codecov-commenter

codecov-commenter commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.08197% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.00%. Comparing base (69310c9) to head (1902331).

Files with missing lines Patch % Lines
..._of_accounts/process_loan_statement_of_accounts.py 90.60% 17 Missing ⚠️
...ccounts/test_process_loan_statement_of_accounts.py 99.44% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1300      +/-   ##
===========================================
+ Coverage    82.56%   83.00%   +0.44%     
===========================================
  Files          154      157       +3     
  Lines        10881    11247     +366     
===========================================
+ Hits          8984     9336     +352     
- Misses        1897     1911      +14     
Files with missing lines Coverage Δ
lending/hooks.py 100.00% <ø> (ø)
...nt/process_loan_statement_of_accounts_applicant.py 100.00% <100.00%> (ø)
...ccounts/test_process_loan_statement_of_accounts.py 99.44% <99.44%> (ø)
..._of_accounts/process_loan_statement_of_accounts.py 90.60% <90.60%> (ø)

... and 1 file with indirect coverage changes

🚀 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.

Nihantra-Patel and others added 4 commits June 26, 2026 10:05
…atement of Accounts

The render_template calls use trusted sources: TEMPLATE_PATH and
base_template_path are hardcoded module constants, and pdf_name/subject/
body are author-defined templates validated via validate_template() and
editable only by Loan Manager / System Manager. Add inline nosemgrep
suppressions with justifications.
Add tests covering previously-untested paths: PDF generation
(consolidated and per-applicant), get_context, recipients/cc resolution,
applicant email/detail lookup, fetch_applicants (all loans, by product,
and missing-product error), download_statements, send_emails (success,
no-data, and no-recipient skip), set_next_schedule_date for every
frequency, send_auto_email, and the auto-email date-sync in validate.
- Remove the display-only currency field (it only swapped the symbol
  without converting amounts, which was misleading); statements now
  always format in the company's default currency.
- Render Letter Head content/footer through Jinja so placeholders
  (company_logo, doc.doctype/name) resolve, fixing PDF generation
  (wkhtmltopdf ContentNotFoundError) and the misleading header title;
  the header now shows the report name and applicant.
- Log download failures to the Error Log.
- Re-anchor test dates to today() to match ERPNext's Process Statement
  Of Accounts test convention instead of hardcoded sentinel years.
- Drop explanatory comments/docstrings added during development.
@Nihantra-Patel

Copy link
Copy Markdown
Member Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Reviews (6): Last reviewed commit: "Merge branch 'develop' into feat/process..." | Re-trigger Greptile

- Require read permission on the applicant (Customer/Employee) in
  get_applicant_details to prevent email enumeration.
- Require the "email" permission (not default read) before send_emails
  dispatches statements.
- Pick up overdue auto-email schedules with start_date <= today so a
  missed run still recovers instead of being skipped forever.
- Replace unittest.mock usage in tests with direct execution, asserting
  on real outcomes (Email Queue rows, schedule roll-forward, rendered
  letter head), matching the lending report test convention.
@Nihantra-Patel Nihantra-Patel force-pushed the feat/process-loan-statement-of-accounts branch from 2315600 to 12b161c Compare June 26, 2026 06:58
@Nihantra-Patel Nihantra-Patel marked this pull request as ready for review June 26, 2026 09:04
…uilder

- Skip applicants the user cannot read before returning their name and
  email from fetch_applicants, matching the per-applicant check in
  get_applicant_details.
- Rewrite the Loan and schedule lookups with frappe.qb instead of
  frappe.get_all.
@@ -0,0 +1,98 @@
<style>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Loan Statement of accounts already has a template, no need to have two templates

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tested reusing the Loan Statement of Account report template for the PDF. It fails with a Jinja TemplateSyntaxError.

Although both files are .html, they use different template languages:

  • The report template is client-side ({%= %}, JS syntax), rendered in the browser for the desk report view.
  • The PDF/email needs a server-side Jinja template ({{ }}).

Jinja cannot parse the report's JS syntax, so one template cannot serve both. This is the same reason ERPNext keeps separate templates for Process Statement Of Accounts (the AR/GL reports have their own .html, and the PSOA doctype keeps its own Jinja templates for the PDF).

@Nihantra-Patel Nihantra-Patel marked this pull request as draft June 26, 2026 11:14
@Nihantra-Patel Nihantra-Patel marked this pull request as ready for review June 26, 2026 12:53
Nihantra-Patel and others added 3 commits June 26, 2026 19:00
- Skip applicants the user cannot read while building statements in
  get_statement_dict, so saved child rows are not trusted blindly when
  downloading or emailing PDFs.
- Anchor the next schedule window to the document's start_date instead
  of today so an overdue run does not leave a gap between statement
  periods.
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.

3 participants