Loloi Hind Loloi Hind - 1 year ago 182
Python Question

inherited function odoo python

i want to inherit function in module 'hr_holidays' that calculate remaining leaves the function is :

def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
sum(h.number_of_days) as days,
hr_holidays h
join hr_holidays_status s on (
h.state='validate' and
s.limit=False and
h.employee_id in %s
group by h.employee_id""", (tuple(ids),))
res = cr.dictfetchall()
remaining = {}
for r in res:
remaining[r['employee_id']] = r['days']
for employee_id in ids:
if not remaining.get(employee_id):
remaining[employee_id] = 0.0
return remaining

i had create my own module that inherited to
and try this code to inherit but it isnt work

class HrHolidays(models.Model):
_inherit = 'hr.holidays'

interim = fields.Many2one(
partner_id = fields.Many2one('res.partner', string="Customer")
remaining_leaves = fields.Char(string='Leaves remaining')

def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
res = super(hr_holidays,self)._get_remaining_days(cr, uid, ids, name, args, context)
return res

please help me

Answer Source

You need to call super with HrHolidays and pass just name and args to _get_remaining_days method and override remaining_leaves field:


class HrHolidays(models.Model):
_inherit = 'hr.employee'

def _get_remaining_days(self):
    res = super(HrHolidays, self)._get_remaining_days(name='', args={})
    for record in self:
        if in res:
            record.remaining_leaves = res.get(

    return res

remaining_leaves = fields.Float(compute='_get_remaining_days',
                    string='Remaining Legal Leaves')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download