Skip to content

[18.0] [FIX] report_pdf_form: handle also report id as report_ref#1175

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
camptocamp:report-ref-report-pdf-form
Jun 25, 2026
Merged

[18.0] [FIX] report_pdf_form: handle also report id as report_ref#1175
OCA-git-bot merged 1 commit into
OCA:18.0from
camptocamp:report-ref-report-pdf-form

Conversation

@twalter-c2c

Copy link
Copy Markdown
Contributor

_render_qweb_pdf_prepare_streams can receive report_ref as an int, a models.Model instance, or a str. We then can get an error like below. I suggest to cover all three cases.

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 2167, in _transactioning
    return service_model.retrying(func, env=self.env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/service/model.py", line 157, in retrying
    result = func()
             ^^^^^^
  File "/home/odoo/src/odoo/odoo/http.py", line 2134, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/http.py", line 2382, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 333, in _dispatch
    result = endpoint(**request.params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/http.py", line 754, in route_wrapper
    result = endpoint(self, *args, **params_ok)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/web/controllers/dataset.py", line 36, in call_kw
    return call_kw(request.env[model], method, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/api.py", line 535, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/documents_account/models/account_journal.py", line 13, in create_document_from_attachment
    action = super().create_document_from_attachment(attachment_ids)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_bank_statement_import/models/account_journal.py", line 30, in create_document_from_attachment
    return journal._import_bank_statement(attachments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_bank_statement_extract/models/account_journal.py", line 38, in _import_bank_statement
    return super()._import_bank_statement(attachments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_bank_statement_import_csv/models/account_journal.py", line 30, in _import_bank_statement
    return super()._import_bank_statement(attachments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_bank_statement_import/models/account_journal.py", line 56, in _import_bank_statement
    statement_ids, dummy, notifications = self._create_bank_statements(stmts_vals)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_bank_statement_import/models/account_journal.py", line 298, in _create_bank_statements
    statement.action_generate_attachment()
  File "/home/odoo/src/enterprise/account_accountant/models/account_bank_statement.py", line 35, in action_generate_attachment
    content, _content_type = ir_actions_report_sudo._render_qweb_pdf(statement_report, res_ids=statement.ids)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions_report.py", line 1024, in _render_qweb_pdf
    collected_streams, report_type = self._pre_render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/account/models/ir_actions_report.py", line 75, in _pre_render_qweb_pdf
    return super()._pre_render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions_report.py", line 1015, in _pre_render_qweb_pdf
    return self._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids), 'pdf'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/sale_pdf_quote_builder/models/ir_actions_report.py", line 17, in _render_qweb_pdf_prepare_streams
    result = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/enterprise/account_followup/models/ir_actions_report.py", line 12, in _render_qweb_pdf_prepare_streams
    res = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/l10n_ch/models/ir_actions_report.py", line 35, in _render_qweb_pdf_prepare_streams
    res = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/purchase/models/ir_actions_report.py", line 12, in _render_qweb_pdf_prepare_streams
    collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/hr_expense/models/ir_actions_report.py", line 12, in _render_qweb_pdf_prepare_streams
    res = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/account_edi_ubl_cii/models/ir_actions_report.py", line 11, in _render_qweb_pdf_prepare_streams
    collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/account_edi/models/ir_actions_report.py", line 14, in _render_qweb_pdf_prepare_streams
    collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/addons/account/models/ir_actions_report.py", line 22, in _render_qweb_pdf_prepare_streams
    return super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/user/odoo/external-src/reporting-engine/report_pdf_form/models/ir_actions_report.py", line 26, in _render_qweb_pdf_prepare_streams
    pdf_form_report = self.env["report.pdf.form"].search(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 1754, in search
    return self.search_fetch(domain, [], offset=offset, limit=limit, order=order)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 1778, in search_fetch
    query = self._search(domain, offset=offset, limit=limit, order=order or self._order)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 5818, in _search
    query = self._where_calc(domain)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 5569, in _where_calc
    return expression.expression(domain, self).query
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/osv/expression.py", line 799, in init
    self.parse()
  File "/home/odoo/src/odoo/odoo/osv/expression.py", line 1459, in parse
    push_result(model._condition_to_sql(alias, left, operator, right, self.query))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 3155, in _condition_to_sql
    assert not isinstance(value, BaseModel), \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Invalid value ir.actions.report(1692,) in domain term ('report_name', '=', ir.actions.report(1692,))

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @grindtildeath,
some modules you are maintaining are being modified, check this out!

@twalter-c2c twalter-c2c force-pushed the report-ref-report-pdf-form branch 2 times, most recently from df7300d to 8b90db2 Compare June 25, 2026 10:32
Comment thread report_pdf_form/models/ir_actions_report.py Outdated
Comment thread report_pdf_form/models/ir_actions_report.py Outdated
@twalter-c2c twalter-c2c force-pushed the report-ref-report-pdf-form branch from 8b90db2 to a8e652c Compare June 25, 2026 11:18
Comment on lines +37 to +38
elif isinstance(report_ref, str):
pdf_form_report = ReportPdfForm.search([("report_name", "=", report_ref)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question: Could it be an xmlid ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would say so, yes. Would that be a problem?

[("report_name", "=", report_ref)]
)
ReportPdfForm = self.env["report.pdf.form"]
if isinstance(report_ref, int):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@twalter-c2c twalter-c2c Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. Yes, I have just noticed that method as well. It is in fact used by the original _render_qweb_pdf_prepare_streams so I think I only need if isinstance(report_ref, str) before the original search. I will verify that and update a PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I refactored based on the suggestion. Can you please check @TDu @mmequignon?

@twalter-c2c twalter-c2c force-pushed the report-ref-report-pdf-form branch from a8e652c to 7064e93 Compare June 25, 2026 12:48

@grindtildeath grindtildeath left a comment

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.

LGTM

@mmequignon mmequignon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool, I didn't know about that _get_report method

@simahawk

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 18.0-ocabot-merge-pr-1175-by-simahawk-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 59cf530 into OCA:18.0 Jun 25, 2026
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 52e03a5. Thanks a lot for contributing to OCA. ❤️

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants