我想在unlink()函数的新api中调用hr_attendance的旧api函数。
我的旧api代码是:
double mm1 = 1200/2.54;
double zoom=mm1;
double szer=99;
double wys=210;
QPixmap pixmap(szer*zoom,wys*zoom);
QPainter painter;
QPen DarkGray(Qt::gray,1);
此函数由约束调用。在验证导入的数据期间将调用此函数。
我希望在unlink()中调用此函数,以便在ORM中执行delete操作时,应调用上面的旧api函数。
如何在这个新的api功能中调用这个旧的api函数
def _altern_si_so(self, cr, uid, ids, context=None):
for att in self.browse(cr, uid, ids, context=context):
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)
if prev_atts and prev_atts[0].action == att.action:
x = self.write(cr, uid, ids, {'text': "Previous Action Is Not Valid?"})
return self.write(cr, uid, ids, {'state': True}), x
if prev_atts and prev_atts[0].action != att.action and next_atts and next_atts[0].action != att.action:
a = self.write(cr, uid, ids, {'state': False})
c = self.write(cr, uid, next_add_ids, {'state': False})
xx = self.write(cr, uid, next_add_ids, {'text': "Everything seems OK!"})
d = self.write(cr, uid, ids, {'text': "Everything seems OK!"})
return self.write(cr, uid, prev_att_ids, {'state': False}), a, c, xx, d
if next_atts and next_atts[0].action == att.action: # next exists and is same action
y = self.write(cr, uid, ids, {'text': "Next Action Is Not Valid?"})
return self.write(cr, uid, ids, {'state': True}), y
if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in
z = self.write(cr, uid, ids, {'text': "First Action Should be Sign In!"})
return self.write(cr, uid, ids, {'state': True}), z
else:
zz = self.write(cr, uid, ids, {'text': "Everything seems OK!"})
return self.write(cr, uid, ids, {'state': False}), zz
return True
_constraints = [(_altern_si_so, 'Error ! Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])]
我怎样才能做到这一点?
由于
答案 0 :(得分:0)
尝试这种方式:
class product_attribute(models.Model):
_inherit = "product.attribute"
@api.multi
def unlink(self):
res= super(product_attribute,self).unlink()
#do your code
return res
关于调用旧的api方法(现在用 @ api.multi 修饰)
传递self._cr,self._uid,self.ids,self._context
,如下所示。
希望它对您的情况有所帮助。