Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to call old api function in new api function(unlink)?

By
Uppili Arivukkannu
on 6/16/16, 1:43 AM 440 views

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
0
Juan Vicente Pascual
On 6/16/16, 4:02 AM

Try:

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


Kind regards.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/16/16, 1:43 AM
Seen: 440 times
Last updated: 6/16/16, 4:02 AM