Skip to Content
Menu
This question has been flagged

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


Avatar
Discard

your code is insane, pls format it

Author

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

Related Posts Replies Views Activity
0
Feb 19
4599
0
May 15
5063
1
Apr 15
3237
1
Jul 19
2350
0
Nov 18
3378