Odoo Help

0
3 Answers
2
Marius Stedjan
2/18/19, 10:01 PM

First off, "self" is the record generated by the wizard. So when you want to access fields from the wizard use: self.my_field

Second, you should use a Many2one field for user_id, because you can only assign one user to the field helpdesk.ticket.user_id (it's a Many2one field).

You don't have to add the field helpdesks_ids, because you are getting these records using browse on active_ids.

When writing the same values to multiple records, use the write() method instead of a loop. It's faster.

Try this:

user_id = fields.Many2one('res.users', string="IT Technicians", required=True)

@api.multi
def action_assign_tech(self):
    tickets = self.env['helpdesk.ticket'].browse(self._context.get('active_ids'))
    tickets.write({'user_id': self.user_id.id})
0
Avatar

Niyas Raphy

--Niyas Raphy--
15052
| 6 6 9
Calicut, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123

Happy to help :)

Niyas Raphy
2/18/19, 5:43 PM

Hi,

Update your code like this,


@api.multi
def action_assign_tech(self, vals):
      tickets = self.env['helpdesk.ticket'].browse(self._context.get('active_ids'))
      for tic in tickets:
#adjust the below line as per the need
#by tic you can access each tickets
           tic.user_id = tic.user_id

Thanks

0
Andrew Pearson
2/19/19, 9:29 AM

@Marius Stedjan

Very much appreciate your answer! Thanks a bunch!

Just so you know, when I tested it, I first got error "Unable to set NOT NULL on 'user_id'" to which I fixed by getting rid of "required=True".

Then I got error "Can't adapt type 'res.users'", to which I fixed by changing

tickets.write({'user_id': self.user_id})# previously

tickets.write({'user_id': self.user_id.id})# revised

Thanks so much for putting me on the right path!

1 Comment
NST Gardermoen MC AS, Marius Stedjan
2/20/19, 4:48 AM

You’re welcome!

Sorry about forgetting the .id. It was too late at night, hehe. I’ve updated the answer.

As for the required=True;

I suppose you got this when you didn’t set a user in the wizard? The point of required is to force the user to set a user.. which makes sense in a wizard like this.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now