ช่วยเหลือ

0

Using @api.onchange for Helpdesk ticket stage changes

Avatar
Andrew Pearson

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

4 ความคิดเห็น
Avatar
Discard
Avatar
Ray Carnes (ray)
-

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)

Avatar
Andrew Pearson
-

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

Avatar
Ray Carnes (ray)
-

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?

Avatar
Andrew Pearson
-

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"

2 Answers
0
Avatar
Andrew Pearson
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)
2 ความคิดเห็น
Avatar
Discard
Avatar
Andrew Pearson
-

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

Avatar
Andrew Pearson
-

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

1
Avatar
subbarao
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