如何在odoo 9中知道当前用户的最后一次考勤动作('sign_in'或'sign_out')?

How to know the last attendance action of the current user ('sign_in' or 'sign_out') in odoo 9?

我扩展了hr_attendance模块,我想获取当前登录用户'action'的最后一个值(可以是'sign_in'或'sign_out')

我不知道如何访问该值。

考勤模块中有以下功能:

def _altern_si_so(self, cr, uid, ids, context=None):
...

def _state(self, cr, uid, ids, name, args, context=None)
...

但我不知道如何在扩展模块中调用该函数,或者是否有其他方法可以获取该值。

查看数据库表我找到了解决方案:

首先我们获取与登录用户

关联的employee_id
employee_id = {}
cr.execute('SELECT hr.id \
            FROM resource_resource AS res JOIN hr_employee AS hr \
            ON res.id = hr.resource_id \
            WHERE res.user_id = %s',[uid])
for res in cr.fetchall():
    employee_id = res[0]

然后,我们得到employee_id

的最后一个动作
last_action = {}
cr.execute('SELECT hr_attendance.action \
            FROM hr_attendance \
            WHERE employee_id = %s',[employee_id])
for res in cr.fetchall():
    last_action = res[0]

'last_action'现在有"sign_in"或"sign_out"(当前用户在考勤模块完成的最后一个动作)