feat: add Process Loan Statement of Accounts#1300
Conversation
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 Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
…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.
|
@greptileai review |
Confidence Score: 5/5This looks safe to merge.
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.
2315600 to
12b161c
Compare
…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> | |||
There was a problem hiding this comment.
Loan Statement of accounts already has a template, no need to have two templates
There was a problem hiding this comment.
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).
- 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.
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.