In odoo 10, using the UI I cannot get my "Server action +Automated action" to work

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

Upvotes: 2

Views: 501

Answers (2)

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

Upvotes: 1

Travis Waelbroeck
Travis Waelbroeck

Reputation: 2135

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

Upvotes: 0

Related Questions