Odoo Help


Unable to Inherit function field in v8

Sairam Bandaru
on 10/19/15, 3:59 AM 937 views


I want inherit these field to modify the result in functional field but inherited function not calling

class hr_employee_inherit(osv.osv):
_inherit = 'hr.employee'

def _get_leave_status(self, cr, uid, ids, name, args, context=None):
holidays_obj = self.pool.get('hr.holidays')
holidays_id = holidays_obj.search(cr, uid,
[('employee_id', 'in', ids), ('leave_from','<=',fields.date.context_today),
('leave_to','>=',time.strftime('%Y-%m-%d')),('type','=','remove'),('state','not in',('cancel','refuse'))],
print holidays_id,ids,'holidays_id****In INHERIT***********-------------------------',time.strftime('%Y-%m-%d'),fields.date.context_today
result = {}
for id in ids:
result[id] = {
'current_leave_state': False,
'current_leave_id': False,
for holiday in self.pool.get('hr.holidays').browse(cr, uid, holidays_id, context=context):
result[holiday.employee_id.id]['leave_date_from'] = holiday.date_from
result[holiday.employee_id.id]['leave_date_to'] = holiday.date_to
result[holiday.employee_id.id]['current_leave_state'] = holiday.state
result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id
print result,'Reslu leave status---------------******-----------'
return result

_columns = {
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),

help me out



Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/19/15, 7:18 AM


If you want to inherit the functional fields and make some changes, you may redefine the fields and function in new api and make the changes you need. For eg, you may try like this:

class hr_employee(models.Model):

current_leave_id = fields.Many2one('hr.holidays.status', compute='_get_leave_status', string="Current Leave Type")
leave_date_from = fields.Date(compute='_get_leave_status', string='From Date')
leave_date_to = fields.Date(compute='_get_leave_status', string='To Date')

def _get_leave_status(self):
holidays_obj = self.env['hr.holidays']
holidays = holidays_obj.search([('employee_id', 'in', self.ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')),
('date_to','>=',time.strftime('%Y-%m-%d 23:59:59')),('type','=','remove'),('state','not in',('cancel','refuse'))])

for holiday in holidays:
self.leave_date_from = holiday.date_from
self.leave_date_to = holiday.date_to
self.current_leave_state = holiday.state
self.current_leave_id = holiday.holiday_status_id.id

Please check it n let me know.

Sairam Bandaru
On 10/19/15, 7:57 AM

Hi, that's fine now able to inherit but in the function I have changed main code because 'self' contained all employees ,So I looped on self instead of holidays as per this code it raising error, So I modified like this working fine  


def _get_leave_status(self):

holidays_obj = self.env['hr.holidays']

print self.ids,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

print self.env.context,'Context ***********8-------------------------',self,self.env.cr,self.env.uid

holidays_id = holidays_obj.search(

[('employee_id', 'in', self.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],


print holidays_id,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

#result = {}


for id in ids:

result[id] = {

'current_leave_state': False,

'current_leave_id': False,





for holiday in holidays_id:

print holiday,'****************************',holiday.holiday_status_id.id

for rec in self:

print rec.ids,'Rec*88888888888888888888'

holidays_id = holidays_obj.search(

[('employee_id', 'in', rec.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],


rec.leave_date_from = holidays_id and holidays_id[0].date_from or None

rec.leave_date_to = holidays_id and holidays_id[0].date_to or None

rec.current_leave_state = holidays_id and holidays_id[0].state or None

rec.current_leave_id = holidays_id and holidays_id[0].holiday_status_id.id or None


Hi did you manage to solve it? Is it working now?

Akhil P Sivan
on 10/19/15, 8:24 AM

Yes working fine.Resolved I inherited fields along with function as computed fields Thanks.

Sairam Bandaru
on 10/19/15, 8:37 AM

Instead of looping on self, I used "@api.one" decorator. Both should have same effect. Anyway I didn't get time to check by running the above. Hope, it helped you in solving the problem.

Akhil P Sivan
on 10/19/15, 8:47 AM

Thanks Akhil.

Sairam Bandaru
on 10/20/15, 1:35 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/19/15, 3:59 AM
Seen: 937 times
Last updated: 10/19/15, 8:27 AM