Skip to content

fix: set thanks_printed when printing thanks letters via report binding#154

Open
dbruehlmeier wants to merge 1 commit intoOCA:18.0from
dbruehlmeier:fix/thanks-printed-multi-select
Open

fix: set thanks_printed when printing thanks letters via report binding#154
dbruehlmeier wants to merge 1 commit intoOCA:18.0from
dbruehlmeier:fix/thanks-printed-multi-select

Conversation

@dbruehlmeier
Copy link

@dbruehlmeier dbruehlmeier commented Mar 16, 2026

Summary

When printing thanks letters from the list view using multi-select and the Print menu (report binding), the thanks_printed flag on donation.donation is not set to True. The same action from the form view button works differently: the thanks_printed flag on donation.donation is set automatically.

I'm not sure if this is actually a feature or a bug, but from a UX perspective it's inconsistent behaviour and thus feels like a bug.

Why this approach

The root cause is that the report donation.report_thanks was bound directly to the model via binding_model_id. When triggered from the Print menu, Odoo's report machinery generates the PDF without ever calling print_thanks(), so the flag is never set.
I considered two alternatives before settling on the current approach:

  1. Override ir.actions.report._render_qweb_pdf to set the flag whenever the thanks report is rendered. I discarded this because it patches a global model for a domain-specific concern — a disproportionate side effect for what is essentially a flag toggle. It also couples the flag-setting to the PDF rendering pipeline, which makes the behaviour harder to reason about and test.
  2. Override _render_qweb_pdf_prepare_streams (the canonical extension point used by core modules like purchase, account, l10n_ch). While more idiomatic than option 1, those core overrides exist to modify PDF content (embed XML, merge documents), not to set business flags. Using the same hook for a different purpose felt like a misuse of the pattern.
    Instead, I replaced the direct report binding with an ir.actions.server that calls print_thanks(). This follows the same pattern as purchase.order.print_quotation() — set the flag, then return the report action — and ensures a single code path for both form and list view. No global model overrides needed.
    The "Mark as Thanks Printed" list header button became redundant (it only set the flag without printing) and was removed.

@OCA-git-bot
Copy link
Contributor

Hi @alexis-via,
some modules you are maintaining are being modified, check this out!

@dbruehlmeier dbruehlmeier force-pushed the fix/thanks-printed-multi-select branch 2 times, most recently from 42c0843 to 3720320 Compare March 17, 2026 06:51
When printing thanks letters from the list view using multi-select,
the thanks_printed flag was not set to True. Only the form view button
correctly updated the flag.

Replace the direct report binding with a server action that calls
print_thanks(), ensuring a single code path for both single and
multi-select printing. Remove the now-redundant 'Mark as Thanks
Printed' list header button and thanks_printed_button() method.

Add DE and FR translations for thanks-related strings and unit tests
for the thanks letter printing functionality.
@dbruehlmeier dbruehlmeier force-pushed the fix/thanks-printed-multi-select branch from 3720320 to 0cad797 Compare March 17, 2026 06:55
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.

2 participants