继承函数odoo python [英] inherited function odoo python
本文介绍了继承函数odoo python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想继承模块'hr_holidays'中的函数,该函数计算剩余的叶子,该函数是:
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):
cr.execute("""SELECT
sum(h.number_of_days) as days,
h.employee_id
from
hr_holidays h
join hr_holidays_status s on (s.id=h.holiday_status_id)
where
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
我已经创建了自己的模块,该模块继承了hr_holidays
,并尝试继承此代码,但这是行不通的
i had create my own module that inherited to hr_holidays
and try this code to inherit but it isnt work
myclass.py
myclass.py
class HrHolidays(models.Model):
_inherit = 'hr.holidays'
interim = fields.Many2one(
'hr.employee',
string="Interim")
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
推荐答案
您需要使用HrHolidays
调用super,并将名称和参数仅传递给_get_remaining_days
方法并覆盖remaining_leaves
字段:
You need to call super with HrHolidays
and pass just name and args to _get_remaining_days
method and override remaining_leaves
field:
Python
class HrHolidays(models.Model):
_inherit = 'hr.employee'
@api.model
def _get_remaining_days(self):
res = super(HrHolidays, self)._get_remaining_days(name='', args={})
for record in self:
if record.id in res:
record.remaining_leaves = res.get(record.id)
return res
remaining_leaves = fields.Float(compute='_get_remaining_days',
string='Remaining Legal Leaves')
这篇关于继承函数odoo python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文