Skip to content

[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark#1156

Open
bosd wants to merge 58 commits intoOCA:19.0from
bosd:19.0-fix-report_qweb_pdf_watermark-multi-company
Open

[19.0][FIX] report_qweb_pdf_watermark: Use document company for watermark#1156
bosd wants to merge 58 commits intoOCA:19.0from
bosd:19.0-fix-report_qweb_pdf_watermark-multi-company

Conversation

@bosd
Copy link
Copy Markdown
Contributor

@bosd bosd commented Apr 16, 2026

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

  • Added _get_watermark_company() helper that returns the document's company_id when available, falling back to self.env.company otherwise.
  • The company watermark branch now uses this helper.

Test plan

  • Configure watermarks on two companies
  • Switch to company B, print an invoice belonging to company A via the gear button — correct (company A) watermark is applied
  • Non multi-company setups unchanged (falls back to self.env.company)
  • Pre-commit passes

Notes

Based on #1091 (the 19.0 migration). Will rebase on 19.0 once that is merged.

hbrunn and others added 30 commits November 14, 2025 19:51
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/
[MIG] report_qweb_pdf_watermark: Migration to 15.0
OCA-git-bot and others added 27 commits November 14, 2025 19:51
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.
@OCA-git-bot OCA-git-bot added series:19.0 mod:report_qweb_pdf_watermark Module report_qweb_pdf_watermark labels Apr 16, 2026
Copy link
Copy Markdown
Contributor

@ivantodorovich ivantodorovich left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:report_qweb_pdf_watermark Module report_qweb_pdf_watermark series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.