When you create a report class, you can modify the scope you will be able to access from the report, by modifying self.localcontext
.
You can, as below, add a binding to cr
:
class my_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(my_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({'time': time,
'cr': cr,
'company_vat': self._get_company_vat})
def _get_company_vat(self):
res_users_obj = pooler.get_pool(self.cr.dbname).get('res.users')
company_vat = res_users_obj.browse
In your report, you'll be able to use time
, cr
or company_vat()
.
You'll see that you can also add a binding for methods, this is maybe a better solution than directly access cr
from your report.
On a side note, when you have some computation to do in a report, you often better have to compute it before the rendering of the template than during the rendering.
If you do not use a custom class and cannot create it (SaaS for example), you should be able to access to the current cursor with self._cr
, if self
is a browse_record
.
Did you try self.cr ?
Yup: AttributeError: "Field 'cr' does not exist in object 'browse_record(sale.order, 185)'"