Skip to Content
Menu
This question has been flagged
3 Replies
7073 Views

I want to print employee details from hr.employee model to my qweb report(Purchase Requisition).

I am trying the code like following:

                            <tr>
                                <td style="border:1px solid #000;padding-left:5px">Department:<span t-esc="o.user_id.partner_id.department_id.name"/></td>
                                <td style="border:1px solid #000;padding-left:5px"> </td></tr>

And facing this error: Error to render compiling AST AttributeError: 'res.partner' object has no attribute 'department_id'

I understood that my current object does'nt contain department_id field. Then how can I get this employee details from hr.employee model for the logged in user??

Any help is highly appreciated and I am using odoo 10. Thanks!

Avatar
Discard
Author Best Answer

Hi Dear,

Thank you for your kind replies. I am sharing the solution which worked for me. This may help someone who reach here. 

For relational fields use this:

<span t-esc="','.join(o.user_id.mapped('employee_ids.department_id.display_name'))" />

For other fields use this:

<span t-esc="request.env.user.employee_ids.mobile_phone" />



Avatar
Discard

Try the Emipro Technologies Pvt. Ltd. Solution it seems to be the good one.

Did you restart odoo server and upgrade module ?

Best Answer

Try overrding your model get_report_values function and pass to it a variable containing current user (Employee) object and use it in your template (<span t-esc="employee.department_id.name"/>)

@api.model
def get_report_values(self, docids, data=None):
    docs = self.env['your.model'].browse(docids)
    employee = self.env['hr.employee'].search(['user_id', '=', self.env.user.id], limit=1)
    return {
        'doc_ids': docids,
        'doc_model': 'your.model',
        'docs': docs,
        'employee': employee and employee[0]
}
Avatar
Discard
Best Answer

In res.partner "department_id" not available, you can create one compute field in res.partner which is set department of that partner.

from odoo import fields,models,api

class res_partner(models.Model):

_inherit='res.partner'

@api.multi

def set_department(self):

user=self.env.user

for record in self:

employee_id=self.env['hr.employee'].search([('user_id','=',user.id)])

record.department_id=employee_id and employee_id.department_id.id or False

department_id=fields.Many2one('hr.department',compute='set_department',string="Department")


After creating compute field ,your code will be work.

Avatar
Discard
Related Posts Replies Views Activity
3
Sep 22
19162
4
Mar 21
13911
0
May 19
2621
2
Nov 24
267
1
Oct 24
335