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

Executing a method at recordset level using old api method

By
inian
on 6/3/16, 11:59 AM 267 views

I am trying to edit odoo inbuilt hr_attendance.py.My problem is following  validation runs for particular record and not the entire recordset. In new api we use @api multi to execute a  recordset.So how can I execute similarly using old api method of odoo 8

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


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/3/16, 11:59 AM
Seen: 267 times
Last updated: 6/3/16, 3:06 PM