2

I have the "reviewer" field available in my task, and I want to switch the reviewer with the task assignee automatically when the task is moved from the 'In progress' stage to the 'Review' stage. I have the following Python code in my server action: picture of the code in context

def assignrev(self): for record in self: if record['project.task.type.stage_id.name']=='Review': a=self.res.users.reviewer_id.name b=self.res.users.user_id.name record['res.users.user_id.name']=a record['res.users.reviewer_id.name']=b 

and below are links to pictures of my automated action settings: Server action to run

"When to run" settings

Unfortunately, changing the task stage to 'Review' does not give the expected results. Any suggestion please?

Kazu

2 Answers 2

1

Ok I finally got the answer to this. below is a picture of the code in context for Odoo 10: enter image description here

No "def" of "for record" needed: the code will not run.

I just hope this will be helpful to someone else...

Kazu

Sign up to request clarification or add additional context in comments.

Comments

0

My guess is that you are incorrectly calling the fields you're trying to get.

# Instead of this a = self.res.users.reviewer_id.name b = self.res.users.user_id.name record['res.users.user_id.name']=a record['res.users.reviewer_id.name']=b # Try this # You don't need to update the name, you need to update the database ID reference record['user_id'] = record.reviewer_id.id record['reviewer_id'] = record.user_id.id 

Furthermore, why don't you try using an onchange method instead?

@api.multi def onchange_state(self): for record in self: if record.stage_id.name == 'Review': record.update({ 'user_id': record.reviewer_id.id, 'reviewer_id': record.user_id.id, }) 

If you're still having problems, you can use ipdb to debug your code more easily by triggering set_trace in your method.

def assignrev(self): # Triggers a break in code so that you can debug import ipdb; ipdb.set_trace() for record in self: # Test line by line with the terminal to see where your problem is 

5 Comments

Thank you for the answer travisw, the problem is that as you can see in the pictures, I am using the action server pyhton code which seems to be limited. when I try to 'from odoo import api' in order to use the onchange method, I get the error: forbidden opcode(s) in u. It feels like I can only use a trimmed down version of python...
Also, changing the syntax as indicated in your first suggestion didn't yield any result unfortunately...I guess I will have to study more about Odoo's modules...
@ンドング一信ndong My answer is actually assuming you were programming in Python and not directly on a server action. The server action must be done a bit differently. I'll try to update my answer with specifics. At the minimum, you do not need any @api call, nor a def ...: statement.
Hello Travis, and happy new year. Anything new about the python syntax in the server action?
Still no answer for this problem? I read that only simple python code can be use in the server action python code box: How simple? what do I have to change in my syntax? the documentation on this subject is really close to nothing...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.