Odoo Help


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.


Assigning True to a boolean field inside a method

on 5/20/16, 5:40 AM 459 views

Hello guys,

I altered the attendance validation in odoo to implement in my custom class.I used @api.constrain that triggers  following method when there is change to 's2' field

@api.constrains('s2')def constraint_action(self,cr, uid, ids, context=None):        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, [('EID', '=', att.EID), ('date', '<', att.date),                                                 ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='date DESC')            next_add_ids = self.search(cr, uid, [('EID', '=', att.EID), ('date', '>', att.date),                                                 ('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='date 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:  # previous exists and is same action                self._state = True;                self._columns        return True

I declared following variables at starting

class attendance(models.Model):    _name = "attendance.analysis"    _description = "attendance analysis"    _state = fields.boolean("state?",default = False)    _columns = {             'EID': fields.integer('Employee ID', required=True),             'action': fields.selection([('sign_in', 'Sign In'), ('sign_out', 'Sign Out')], 'Employee Action'),             'date': fields.datetime('Employee Date', required=True, select=1),             's1':fields.char("s1"),             's2':fields.char("s2", required=True),             's3':fields.char("s3"),             's4':fields.char("s4"),             'state':fields.boolean("state?",default = False)              }

I want to access the state field on columns to change its boolean value. odoo doesn't recognize the state field inside columns but was able to detect the other _state.

I want to change this boolean so that tree color can be changed on the view.xml. How can i call this state method inside the if condition. Thanks in advance

your code is insane, pls format it

Prakash Sharma
on 5/20/16, 7:33 AM

Sorry prakash please refer to my correct post here https://www.odoo.com/forum/help-1/question/acessing-a-columns-field-from-in-a-method-102318

on 5/20/16, 8:37 AM

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)


Asked: 5/20/16, 5:40 AM
Seen: 459 times
Last updated: 5/20/16, 6:57 AM