Odoo Help

0

0
3 Answers
2
Marius Stedjan
18‏/2‏/2019 10:01 م

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})
1
Avatar

Niyas Raphy

--Niyas Raphy--
24330
| 7 7 11
Wayanad, الهند
--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
18‏/2‏/2019 5:43 م

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
19‏/2‏/2019 9:29 ص

@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
20‏/2‏/2019 4:48 ص

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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now