Odoo Help

Welcome!

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

0

How to re-evaluate a workflow transition condition when One2many field changes.

By
Habib
on 7/5/16, 8:15 AM 467 views

I'm trying to create a workflow which transitions to the next step when answer_count > 5. Answers are in a separate model

class Question(models.Model):
    answer_ids = fields.One2many(comodel_name="module.answer", string="Answer", inverse_name="question_id")
    answer_count = fields.Integer(string="Answer Count", compute="_count_answers")
    
    @api.depends('answer_ids')
    def _count_answers(self):
      for rec in self:
          rec.answer_count = len(self.answer_ids)


I have tried:

<record model="workflow.transition" id="answers_received">
    <field name="act_from" ref="waiting"/>
<field name="act_to" ref="done"/>
    <field name="condition">answer_count &gt;= 5</field>
</record>


But it seems like it doesn't re-evaluate when a new answer is received.

What would be the right way to re-test the transition condition? 

Does it require a trigger? If so, how would I re-install the triggers on every try that the condition is not met? The documentation says: triggers are not re-installed whenever the transition is re-tried.



Interesting question, could you provide more info about the whole scenario so we could get the big picture here? Seems that you wanna build an automaton with Odoo workflows

Axel Mendoza
on 7/5/16, 7:01 PM

I'm not sure what more info to provide - basically when a new record is inserted into the related model (one2many) it should re-evaluate the transition condition. Does this make sense?

Habib
on 7/5/16, 7:17 PM

Let me give an example which is related to the code above: visitors to the site are allowed to post answers to questions. When a question has 5 answers, the state should change to "answered". The answers are stored in a separate model related using a one2many field

Habib
on 7/5/16, 7:21 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/5/16, 8:15 AM
Seen: 467 times
Last updated: 7/11/16, 9:04 AM