This question has been flagged

I'm trying to make it so when an IT tech is assigned to a Helpdesk ticket, the Ticket's stage goes from 'New' to 'Assigned'.  However, when I add the tech, the stage doesn't change.  I have seen that 'onchange' doesn't work in the event that you have a clickable Statusbar widget, which we have set up for our tickets.  Unfortunately, I haven't seen a good workaround, but perhaps I'm missing something.  Can anyone give me some suggestions?

@api.onchange('user_id')
def tmg_assigned_user_id(self)
        self.ensure_one()
        for ticket in self:
                if ticket.user_id:
                    ticket.stage_id.sequence = 1

Avatar
Discard

Why are you changing the sequence of the stage_id? What happens if you just change the stage_id to 1? (Also, tip: Ideally you should SEARCH for the Assigned status to make sure you have the correct ID)

Author

We wanted to make the stage change automatically when a tech is assigned to a ticket, so that way, the ticket status just doesn't stay as 'New'. If I just change the stage_id to 1, nothing happens as well. Our 'Assigned' status is under sequence 1, while 'New' is 0 and so on

I understand what you want to do, I just wanted to point out that what your code is trying to do is change the sequence of the stage, not change the stage. Seems like you've tried ticket.stage_id = {something} also?

Author

Thanks for bringing that up. I actually did just notice that today. I didn't realize that's what was happening. I have tried ticket.stage_id = 'In Progress' but unfortunately to no avail. I think this also just ended up changing the ticket status name in sequence 0 to "In Progress"

Author Best Answer

@subbarao

I wasn't able to get it to work.  It must be my logic at this point.

@api.multi
def write(self,vals):
      if vals.get('user_id'):
           vals['stage_id] = 1
      return super(HelpdeskTicket, self).write(vals)
Avatar
Discard
Author

I actually was able to get this to work. The write method also needed the create method to go along with it. Turns out my code was right after all. Thanks for the help

Author

The create method looks exactly the same but just has @api.model instead

Best Answer

Hello Andrew,

Instead of doing it on onchange use write method.

@api.multi

def write(self, vals):

    if vals.get('user_id',False):

    ###        write your logic here

    return super(your_class_name, self).write(vals)



Avatar
Discard