1

as mentioned in the title, I want to get the selected companies (in a multi-company DB) inside a report, I know that it can be done in python using:

select_companies = self.env['res.company'].browse(self._context.get('allowed_company_ids'))

enter image description here

but in qweb I don't have self (the record), is there another way to get the context?

NB: I will use them in t-if
Odoo v14

Bashir
  • 2,057
  • 5
  • 19
  • 44

1 Answers1

2

In document reports (QWeb) you usually got doc or o which represents the record you want to print/render. That's usually (except in very less situations) a normal Odoo recordset with all the things you can use in Odoo's python business logic code. So just try:

<span t-esc="o.env.context.get('allowed_company_ids', 'sorry nothing here')" />

That should print/render the list of company IDs. If that's working you can also use it in t-ifs and other QWeb control elements.

In business intelligence reports (QWeb again) it depends on how the report is called. In the comment the template account_reports.line_template is mentioned, which uses context.get() already. But that must not mean that this context is the normal context. But it's worth a try. You have to dig into the report python code, to find out what is present in the context or how to manipulate it.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • thanks for the answer, I already tried that, but after verification I see that I have no `doc` neither `o`, I am inheriting `account_reports.line_template` – Bashir Jul 13 '21 at 15:50
  • in `account_reports.line_template` I see there is ``, does it mean I can use `context.get('allowed_company_ids', 'sorry nothing here')` ? – Bashir Jul 13 '21 at 15:56