Skip to content

PARAF-220: Automate to_print flag and print all to_print files in d-print#138

Open
chris-adam wants to merge 1 commit into
masterfrom
PARAF-220/pour_impression
Open

PARAF-220: Automate to_print flag and print all to_print files in d-print#138
chris-adam wants to merge 1 commit into
masterfrom
PARAF-220/pour_impression

Conversation

@chris-adam

@chris-adam chris-adam commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

En résumé, deux changements: activer "to_print" automatiquement à la création des fichiers, et le prendre en compte dans le modèle "Pour impression" même pour les fichiers non-ODT.

@sgeulette Question: Ici, je set to_print lors de la création du fichier (subscriber i_annex_added). Est-ce qu'il faudrait le set plutôt lors de la transition avant signature (manuscrite) par exemple ?

Summary

Two related PARAF-220 changes, delivered together:

1. Automate the to_print flag on outgoing-mail files (subscribers.py)

New _correct_to_print(file_obj) helper, called from i_annex_added whenever a dmsommainfile or dmsappendixfile is added to an outgoing mail:

  • Appendix files (dmsappendixfile) are never printed → to_print=False.
  • A main GED file (dmsommainfile) is printed when the parent mail is not electronically signed (esign off), and not printed when it is.
  • The category-group to_be_printed_activated gate is respected: to_print is never forced True when printing is deactivated for that category group.
  • The container's categorized_elements cache is refreshed (update_categorized_elements) only when the value actually changes.

2. d-print document generation now honors to_print (browser/documentgenerator.py, profiles/default/templates/d-print.odt)

  • get_dms_files now returns, for every selected mail, all categorized files (main + appendix) whose to_print is True — via get_categorized_elements(..., filters={"to_print": True}) — ordered main-before-appendix, dashboard selection order preserved. The old per-mail limit=1 cap and the is_odt()-only exclusion are gone; limit is now an optional overall cap.
  • ODT files are still embedded as ODT content. Non-ODT files (PDF/scans) are rendered from their collective.documentviewer preview page images (get_print_pages); image files (png/jpg/…) are inserted at native size (is_image / img_format).
  • Duplex handling for non-ODT files via print_page_count / needs_blank_after: a blank page follows a file with an odd page count so the next file starts recto. ODT files keep managing their own duplex page break.

Tests

  • test_subscribers.test_correct_to_print — main on/off (esign), appendix always off, and the to_be_printed_activated gate.
  • test_adapterscreate_pdf_file tests extended to assert the generated signature pdf (and its source main) are to_print=False.
  • test_documentgenerator.test_DocumentGenerationOMDashboardHelperget_dms_files ordering/filtering + limit, and the new is_odt / is_image / img_format / get_print_pages / print_page_count / needs_blank_after helpers.

Summary by CodeRabbit

Summary

  • New Features
    • Outgoing mail attachments now automatically receive the correct print flag based on attachment type, signing state, and category activation.
    • Dashboard print preparation now builds printable documents from categorized “to print” elements (main before appendix) and enforces global limits across selected mails.
  • Bug Fixes
    • Print previews no longer render for ODTs or images, while PDF previews use stored viewer data when available.
    • Duplex printing now adds trailing blank pages only when required by page consumption rules.
  • Tests
    • Expanded coverage for print-flag behavior and dashboard page/preview generation.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds automatic to_print derivation for outgoing mail files based on portal type, mail esign, and category activation, wiring it into annex-added subscribers. Reworks dashboard document generation to select to_print files and render print-page previews with ODT/image handling and duplex blank-page logic.

Changes

to_print automation and dashboard print flow

Layer / File(s) Summary
Automatic to_print correction on annex addition
imio/dms/mail/subscribers.py, imio/dms/mail/tests/test_subscribers.py, CHANGES.rst
_correct_to_print derives to_print from portal type and parent mail esign, gated by to_be_printed_activated, and is wired into i_annex_added for main and appendix files; tests validate main/appendix behavior and the activation gate; changelog updated.
Signature PDF generation to_print verification
imio/dms/mail/tests/test_adapters.py
Tests assert generated/converted signature-target PDFs and untouched sibling files have to_print == False.
Dashboard file selection and print previews
imio/dms/mail/browser/documentgenerator.py, imio/dms/mail/tests/test_documentgenerator.py
get_dms_files now collects to_print=True categorized elements ordered main-before-appendix with limit slicing; new is_odt, is_image, img_format, print_page_count, needs_blank_after helpers added; get_print_pages returns previews from collective.documentviewer annotations except for ODT/image files; tests expanded accordingly.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant i_annex_added
  participant _correct_to_print
  participant file_obj
  participant categorized_elements

  i_annex_added->>_correct_to_print: call with obj
  _correct_to_print->>file_obj: compute to_print from portal_type and omail.esign
  _correct_to_print->>categorized_elements: check to_be_printed_activated
  _correct_to_print->>file_obj: update to_print if changed
  _correct_to_print->>categorized_elements: update_categorized_elements
Loading
sequenceDiagram
  participant DocumentGenerationOMDashboardHelper
  participant get_categorized_elements
  participant get_print_pages

  DocumentGenerationOMDashboardHelper->>get_categorized_elements: collect to_print files
  DocumentGenerationOMDashboardHelper->>get_print_pages: build preview pages per file
  get_print_pages-->>DocumentGenerationOMDashboardHelper: empty for ODT/image, per-page data otherwise
Loading

Suggested reviewers: sgeulette

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: automating to_print and printing all to_print files in d-print.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PARAF-220/pour_impression

Comment @coderabbitai help to get the list of available commands.

@chris-adam chris-adam force-pushed the PARAF-220/pour_impression branch from 32004bc to 6465696 Compare July 1, 2026 14:35

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGES.rst`:
- Line 16: Fix the typo in the changelog entry by updating the d-print note in
CHANGES.rst so it says “takes” instead of “taks”. Locate the document generation
release note mentioning the to_print attribute and correct the word in that
entry.

In `@imio/dms/mail/adapters.py`:
- Around line 1807-1819: The signing path in `adapters.py` is forcing `to_print`
on GED main files and generated signature PDFs without honoring the
`to_be_printed_activated` gate, which bypasses `subscribers._correct_to_print`.
Update the `pdf_file.to_print` and `orig_fobj.to_print` handling in the
signing-related branches to go through the same gated logic used elsewhere
instead of assigning directly. Also add a regression test covering the signing
flow with `to_be_printed_activated=False` to ensure files do not appear in
`d-print` when printing is disabled.

In `@imio/dms/mail/browser/documentgenerator.py`:
- Around line 370-371: The limit handling in documentgenerator.py treats 0 as
falsy in the file-slicing logic, so get_dms_files(limit=0) returns all files
instead of none. Update the limit check in the file selection block to
explicitly test for a provided value using the relevant file list variable so
that 0 is respected as a valid limit and only None means “no limit”.
- Around line 453-455: The preview-page blob reads in documentgenerator.py leave
each stream open after blob.open().read(), so update the page loop to read the
blob inside a context manager and close it immediately after use. Locate the
page-collection logic in the loop that builds pages and ensure the Blob object
from files["large/dump_%d.%s" % (page, fmt)] is opened with a with block before
appending the page data to pages.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd386ad4-ba27-423d-931b-de0f2b6ae4e7

📥 Commits

Reviewing files that changed from the base of the PR and between 1baa40e and 32004bc.

📒 Files selected for processing (8)
  • CHANGES.rst
  • imio/dms/mail/adapters.py
  • imio/dms/mail/browser/documentgenerator.py
  • imio/dms/mail/profiles/default/templates/d-print.odt
  • imio/dms/mail/subscribers.py
  • imio/dms/mail/tests/test_adapters.py
  • imio/dms/mail/tests/test_documentgenerator.py
  • imio/dms/mail/tests/test_subscribers.py

Comment thread CHANGES.rst Outdated
Comment thread imio/dms/mail/adapters.py Outdated
Comment on lines +1807 to +1819
# PARAF-220: the generated signature file (from a GED main) is printed;
# the source GED main is not (its pdf replaces it in the print output).
pdf_file.to_print = orig_fobj.portal_type == "dmsommainfile"
if orig_fobj.portal_type == "dmsommainfile" and orig_fobj is not pdf_file:
orig_fobj.to_print = False
update_categorized_elements(
self.context,
orig_fobj,
get_category_object(self.context, orig_fobj.content_category),
limited=True,
sort=False,
logging=True,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Honor to_be_printed_activated in the signing path.

These branches force to_print=True for GED mains / generated signature PDFs without re-checking the category-group gate. That bypasses subscribers._correct_to_print, so a category with printing disabled will start showing up in d-print as soon as the file goes through signing.

Please route these assignments through the same gated logic, and add a regression case with to_be_printed_activated=False.

Also applies to: 1896-1906

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@imio/dms/mail/adapters.py` around lines 1807 - 1819, The signing path in
`adapters.py` is forcing `to_print` on GED main files and generated signature
PDFs without honoring the `to_be_printed_activated` gate, which bypasses
`subscribers._correct_to_print`. Update the `pdf_file.to_print` and
`orig_fobj.to_print` handling in the signing-related branches to go through the
same gated logic used elsewhere instead of assigning directly. Also add a
regression test covering the signing flow with `to_be_printed_activated=False`
to ensure files do not appear in `d-print` when printing is disabled.

Comment thread imio/dms/mail/browser/documentgenerator.py Outdated
Comment thread imio/dms/mail/browser/documentgenerator.py Outdated
@chris-adam chris-adam force-pushed the PARAF-220/pour_impression branch 3 times, most recently from afbe2ec to 6b9ab81 Compare July 2, 2026 09:50
@chris-adam chris-adam force-pushed the PARAF-220/pour_impression branch from 6b9ab81 to dfbbd9c Compare July 2, 2026 09:57
@chris-adam

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chris-adam chris-adam requested a review from sgeulette July 2, 2026 10:11
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