Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
4712 Visualizzazioni

I want to call the old api function of hr_attendance in new api of unlink() function.

My old api code is:


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:

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'])]


This function is call by a constraint. This function will be called during the validation of imported data.

I want this function to be called in unlink() so that when delete action is performed in ORM the above old api function should be called.


How can I call this old api function in this new api  fuction

How can I achieve this?

@api.multi
def unlink(self):
#how to call the old api here
return models.Model.unlink(self
Avatar
Abbandona
Risposta migliore

Try:

_altern_si_so( self.env.cr, self.env.uid, [your.ids], self.env.context))


Kind regards.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
5
lug 20
10543
2
ott 15
10583
2
set 15
5381
1
ago 24
6240
2
set 21
3746