0

I have a time difference field

time_diff = fields.Char(string="Time Difference", required=False, )

and a sla field in odoo

sla_state = fields.Selection(string="SLA", selection=[('past sla', 'Past SLA'), ('within sla', 'Within SLA'), ], required=False, )

i want to set a condition where if time difference is greater than 1 the sla state automatically populates to Past SLA Below is my function

@api.onchange('time_diff')
    def get_sla(self):
        if self.time_diff >= 1:
            self.sla_state == 'past sla'
        else:
            self.sla_state == 'within sla'

But its not working what might be the issue Please help.

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70

1 Answers1

0

The problem is you are comparing the string with integer. Data type of 'time_diff' is string. So string can not be compared with integer. Convert the string to integer using int()

@api.onchange('time_diff')
def get_sla(self):
    if self.time_dif:
        if int(self.time_diff) >= 1:
           self.sla_state == 'past sla'
        else:
           self.sla_state == 'within sla'
sfx
  • 1,793
  • 17
  • 24