Odoo 9.0c: How to get the current user in qweb report?

1.3k views Asked by At

when i duplicate a sale order or account invoice qweb report from the report created by other user, the information about saleperson is the same with the orginal report. Could we get the current user in the copy one. Please help me to point out step by step the right way to get the purpose. Thank for your time. Sory because my low level of English.

1

There are 1 answers

0
DASADIYA CHAITANYA On BEST ANSWER

There are 3 different way we can add and print the user detail into the Qweb Report

1. Directly access the 'user' global object in qweb Part

<span t-esc="user.name" />

2. Get the current user detail from the report parser class

parser report class method:-

def get_cur_user(self):
    return self.pool.get('res.users').browse(self.cr,self.uid,self.uid).name

Call parser class method into qweb View Part :-

<t t-if="get_cur_user()">
    <spane t-esc="get_cur_user()" />
</t>

3. Set the custom user_id (many2one) field on that particular report and set as default attribute as env user record set

Add into your report model :-

user_id = fields.Many2one('res.users', string='Print By User', default=lambda self: self.env.user)

Access that field into the Qweb View part:-

<t t-if="o.user_id">
    <spane t-field="o.user_id.name" />
</t>