[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark#1156
Open
[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark#1156
Conversation
When no background configuration is present on the report definition, don't try to browse the report model especially because this breaks some upstream reports (see odoo/odoo#23389)
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-11.0/reporting-engine-11.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-11-0/reporting-engine-11-0-report_qweb_pdf_watermark/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-12.0/reporting-engine-12.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-report_qweb_pdf_watermark/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-12.0/reporting-engine-12.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-report_qweb_pdf_watermark/
external_dependencies
[MIG] report_qweb_pdf_watermark: Migration to 15.0
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-15.0/reporting-engine-15.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_qweb_pdf_watermark/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: reporting-engine-16.0/reporting-engine-16.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_pdf_watermark/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-16.0/reporting-engine-16.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-0-report_qweb_pdf_watermark/es/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-17.0/reporting-engine-17.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-17-0/reporting-engine-17-0-report_qweb_pdf_watermark/it/
Currently translated at 100.0% (10 of 10 strings) Translation: reporting-engine-18.0/reporting-engine-18.0-report_qweb_pdf_watermark Translate-URL: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-report_qweb_pdf_watermark/tr/
When printing a document in a multi-company environment, the company watermark was selected based on self.env.company (the company currently active in the UI switcher) rather than the company of the document being printed. This caused the wrong watermark to appear when a user switched to company B and printed an invoice belonging to company A (or vice versa), as reported in OCA#1134. Fix by introducing a _get_watermark_company() helper that returns the document's company_id when available, falling back to self.env.company otherwise.
ivantodorovich
suggested changes
Apr 28, 2026
Contributor
There was a problem hiding this comment.
The last commit looks good. Minor optional comment from me.
However, this PR has 58 commits.. it looks like a rebase gone wrong. Can you clean it up? EDIT: Ok I see you mentioned you're basing on top of #1091. Sorry for the noise
| model_name = self.model or report_sudo.model | ||
| docs = self.env[model_name].browse(docids) | ||
| if docs and "company_id" in docs._fields and docs[:1].company_id: | ||
| return docs[:1].company_id |
Contributor
There was a problem hiding this comment.
Maybe we can follow this core pattern: https://github.com/OCA/odoo/blob/214244ac6b4b1f4747c91e7247c5536cdea0b415/odoo/orm/models.py#L4044-L4049
Something like:
if "company_id" in docs._fields:
company = docs.company_id[:1]
elif "company_ids" in docs._fields:
company = docs.company_ids[:1]
return company or self.env.company
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1134.
When printing a document in a multi-company environment, the company watermark is selected based on
self.env.company(the company currently active in the UI switcher) rather than the company of the document being printed. This causes the wrong watermark to appear when a user switches to company B and prints an invoice belonging to company A (or vice versa).Changes
_get_watermark_company()helper that returns the document'scompany_idwhen available, falling back toself.env.companyotherwise.Test plan
self.env.company)Notes
Based on #1091 (the 19.0 migration). Will rebase on 19.0 once that is merged.