使用odoo old api

时间:2016-06-03 16:04:55

标签: python openerp odoo-8

我正在尝试编辑odoo inbuilt hr_attendance.py.My问题是在特定记录的验证运行之后,而不是整个记录集。在新的api中,我们使用@api multi来执行记录集。所以如何使用odoo 8的旧api方法执行类似的操作

  def _altern_si_so(self, cr, uid, ids, context=None):
    """ Alternance sign_in/sign_out check.
    Previous (if exists) must be of opposite action.
    Next (if exists) must be of opposite action.
    """
    for att in self.browse(cr, uid, ids, context=context):
        # search and browse for first previous and first next records
        prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name),
                                             ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')
        next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name),
                                             ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')
        prev_atts = self.browse(cr, uid, prev_att_ids, context=context)
        next_atts = self.browse(cr, uid, next_add_ids, context=context)
        # check for alternance, return False if at least one condition is not satisfied
        if prev_atts and prev_atts[0].action == att.action:

            return self.write(cr, uid, ids, {'state': True})

        if next_atts and next_atts[0].action == att.action:  # next exists and is same action.

            return self.write(cr, uid, ids, {'state': True})

        if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in

             return self.write(cr, uid, ids, {'state': True})
        else:
            return self.write(cr, uid, ids, {'state':False})

        return True

_constraints = [          (_altern_si_so,'错误!登录(resp。退出)必须遵循退出(resp。登录)',['action'])]

我想执行此方法来检查整个记录集的验证,而不仅仅是正在编辑或创建的特定记录。

0 个答案:

没有答案