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

Workflow not working when following one specific path

By
Luis Filipe Castanheira
on 4/30/14, 11:26 AM 1,320 views

I''m using OpenERP 7.0 to develop a new module. I have this workflow with two path to reach one same state "confirmed". One path is submitting a request from wich you are not responsible, thus it has to be submitted and then confirmed by the responsible person, or submit a resquest and, if you are responsible, the confirmation step is skipped and goes directly to the "confirmed" case. When I try to send the request to be treated , it work if the process came from the first path (through confirmation) and doesn't if it went directly from "draft" to "confirmed".

A screenshot of the workflow is available at (no sufficient karma to publish links or upload an image) h t tp://s14.postimg.org/uou6g9l1d/Workflows_Open_ERP_2014_04_30_12_07_34.png

My workflow definition:

<?xml version="1.0"?>
<openerp>
    <data>
        <record model="workflow" id="wkf_request">
            <field name="name">request.wkf</field>
            <field name="osv">generic.request</field>
            <field name="on_create">True</field>
        </record>

        <!-- actividades -->
        <record model="workflow.activity" id="act_draft">
            <field name="wkf_id" ref="wkf_request" />
            <field name="flow_start">True</field>
            <field name="name">request_draft</field>
            <field name="kind">function</field>
            <field name="action">request_draft()</field>
        </record>

        <record model="workflow.activity" id="act_submit">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_submitted</field>
            <field name="kind">function</field>
            <field name="action">submit_request()</field>
        </record>

        <record model="workflow.activity" id="act_confirm">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_confirmed</field>
            <field name="kind">function</field>
            <field name="action">confirm_request()</field>
        </record>

        <record model="workflow.activity" id="act_closed_nconf">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed_nconf</field>
            <field name="kind">function</field>
            <field name="action">close_nconf_request()</field>
            <field name="flow_stop">True</field>
        </record>

        <record model="workflow.activity" id="act_req_reformulate">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_reformulation</field>
            <field name="kind">function</field>
            <field name="action">req_reformulate_request()</field>
        </record>

        <record model="workflow.activity" id="act_treatment">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_treatment</field>
            <field name="kind">function</field>
            <field name="action">tratamento()</field>
        </record>

        <record model="workflow.activity" id="act_closed">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed</field>
            <field name="kind">function</field>
            <field name="action">close_request()</field>
            <field name="flow_stop">True</field>
        </record>

        <!-- transições -->
        <record model="workflow.transition" id="request_t1">
            <field name="act_from" ref="act_draft" />
            <field name="act_to" ref="act_submit" />
            <field name="signal">submit_request</field>
        </record>

        <record model="workflow.transition" id="request_t101">
            <field name="act_from" ref="act_draft" />
            <field name="act_to" ref="act_confirm" />
            <field name="signal">confirm_request</field>
        </record>

        <record model="workflow.transition" id="request_t2">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_req_reformulate" />
            <field name="signal">req_reformulate_request</field>
        </record>

        <record model="workflow.transition" id="request_t3">
            <field name="act_from" ref="act_req_reformulate" />
            <field name="act_to" ref="act_submit" />
            <field name="signal">submit_request</field>
        </record>

        <record model="workflow.transition" id="request_t4">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_confirm" />
            <field name="signal">confirm_request</field>
        </record>

        <record model="workflow.transition" id="request_t5">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_closed_nconf" />
            <field name="signal">close_nconf_request</field>
        </record>

        <record model="workflow.transition" id="request_t6">
            <field name="act_from" ref="act_confirm" />
            <field name="act_to" ref="act_treatment" />
            <field name="signal">tratamento</field>
        </record>

        <record model="workflow.transition" id="request_t7">
            <field name="act_from" ref="act_treatment" />
            <field name="act_to" ref="act_closed" />
            <field name="signal">close_request</field>
        </record>

    </data>
</openerp>

Button in the view definition:

<button name="tratamento" class="oe_highlight oe_view_mode_only" string="Send to processing!" type="workflow" states="confirmed" />

And finaly, here is the code of the relevant funcions in my py object

def request_draft(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'draft'})
    self.insert_trace(cr, uid, ids,  context)
    return True

def submit_request(self, cr, uid, ids, context=None):
    resp = self.browse(cr,uid,ids,context)
    if resp[0].needs_reformulation:
        self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings

    if resp[0].goto:
        self.write(cr, uid, ids, {'goto':'','state': resp[0].goto}) # if request is already in motion, clean up the goto tag and go to where it came from
    elif resp[0].is_responsible:                                    # else check if requestor is responsible
        self.write(cr, uid, ids, {'state': 'confirmed'})
    else:                                                           # if not
        self.write(cr, uid, ids, {'state': 'submitted'})

    self.insert_trace(cr, uid, ids, context)
    return True

def confirm_request(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'confirmed'})
    self.insert_trace(cr, uid, ids, context)
    return True

(...)

# this function works when state is confirmed and came through confirmation, and doesn't when requestor is responsible and is directly confirmed
def tratamento(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'treatment'})
    self.insert_trace(cr, uid, ids, context)
    return True

def close_request(self, cr, uid, ids, context=None):
    req = self.browse(cr, uid, ids, context=context)
    if(req[0].authorized):                                      #check if request has been authorized
        self.write(cr, uid, ids, {'state': 'closed_auth'})
    elif(req[0].approved):                                      #or approved
        self.write(cr, uid, ids, {'state': 'closed_appr'})
    else:                                                       #if not, simply close the request!
        self.write(cr, uid, ids, {'state': 'closed'})
    self.insert_trace(cr, uid, ids, context)
    return True

Anyone has any clue of what is causing this? Thanks in advance!

0

It wasn't working because I was jumping to that state through a "shortcut" in my python code, bypassing a workflow transition.

To solve this I added some conditions to the workflow (and thus some new transitions) and now it is working fine.

Since I find that OpenERP documentation is so poor, I'll let here my solution, hoping this will eventually help someone in the future.

Workflow screenshot:

h t tp ://s14.postimg.org/4es7btz4x/Workflows_Open_ERP_2014_05_06_12_12_26.png

Workflow definition:
<?xml version="1.0"?>
<openerp>
    <data>
        <record model="workflow" id="wkf_request">
            <field name="name">request.wkf</field>
            <field name="osv">generic.request</field>
            <field name="on_create">True</field>
        </record>

        <!-- actividades -->
        <record model="workflow.activity" id="act_draft">
            <field name="wkf_id" ref="wkf_request" />
            <field name="flow_start">True</field>
            <field name="name">request_draft</field>
            <field name="kind">function</field>
            <field name="action">request_draft()</field>
        </record>

        <record model="workflow.activity" id="act_submit">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_submitted</field>
            <field name="kind">function</field>
            <field name="action">submit_request()</field>
        </record>

        <record model="workflow.activity" id="act_confirm">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_confirmed</field>
            <field name="kind">function</field>
            <field name="action">confirm_request()</field>
        </record>

        <record model="workflow.activity" id="act_closed_nconf">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed_nconf</field>
            <field name="kind">function</field>
            <field name="action">close_nconf_request()</field>
            <field name="flow_stop">True</field>
        </record>

        <record model="workflow.activity" id="act_req_reformulate">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_reformulation</field>
            <field name="kind">function</field>
            <field name="action">req_reformulate_request()</field>
        </record>

        <record model="workflow.activity" id="act_treatment">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_treatment</field>
            <field name="kind">function</field>
            <field name="action">treat_request()</field>
        </record>

        <record model="workflow.activity" id="act_closed">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed</field>
            <field name="kind">function</field>
            <field name="action">close_request()</field>
            <field name="flow_stop">True</field>
        </record>

        <record model="workflow.activity" id="act_awaiting_auth">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_awaiting_authorization</field>
            <field name="kind">function</field>
            <field name="action">wait_auth_request()</field>
        </record>

        <record model="workflow.activity" id="act_closed_ref">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed_ref</field>
            <field name="kind">function</field>
            <field name="action">close_ref_request()</field>
            <field name="flow_stop">True</field>
        </record>

        <record model="workflow.activity" id="act_awaiting_appr">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_awainting_approval</field>
            <field name="kind">function</field>
            <field name="action">wait_appr_request()</field>
        </record>

        <record model="workflow.activity" id="act_closed_disappr">
            <field name="wkf_id" ref="wkf_request" />
            <field name="name">request_closed_disappr</field>
            <field name="kind">function</field>
            <field name="action">close_disappr_request()</field>
            <field name="flow_stop">True</field>
        </record>
        <!-- transições -->
        <record model="workflow.transition" id="request_t1">
            <field name="act_from" ref="act_draft" />
            <field name="act_to" ref="act_submit" />
            <field name="signal">submit_request</field>
        </record>

    <!-- this transition appens when condition is satisfied (function returns true if requestor is responsible) -->
        <record model="workflow.transition" id="request_t102">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_confirm" />
            <field name="condition">check_responsible()</field>
        </record>

        <record model="workflow.transition" id="request_t2">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_req_reformulate" />
            <field name="signal">req_reformulate_request</field>
        </record>

        <record model="workflow.transition" id="request_t3">
            <field name="act_from" ref="act_req_reformulate" />
            <field name="act_to" ref="act_submit" />
            <field name="signal">submit_request</field>
        </record>

        <record model="workflow.transition" id="request_t1001">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_confirm" />
            <field name="condition">ref_goto_confirmed()</field>
        </record>

        <record model="workflow.transition" id="request_t1002">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_treatment" />
            <field name="condition">ref_goto_treatment()</field>
        </record>


        <record model="workflow.transition" id="request_t4">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_confirm" />
            <field name="signal">confirm_request</field>
        </record>

        <record model="workflow.transition" id="request_t5">
            <field name="act_from" ref="act_submit" />
            <field name="act_to" ref="act_closed_nconf" />
            <field name="signal">close_nconf_request</field>
        </record>

        <record model="workflow.transition" id="request_t6">
            <field name="act_from" ref="act_confirm" />
            <field name="act_to" ref="act_treatment" />
            <field name="signal">treat_request</field>
        </record>

        <record model="workflow.transition" id="request_t7">
            <field name="act_from" ref="act_treatment" />
            <field name="act_to" ref="act_closed" />
            <field name="signal">close_request</field>
        </record>

        <record model="workflow.transition" id="request_t8">
            <field name="act_from" ref="act_treatment" />
            <field name="act_to" ref="act_awaiting_auth" />
            <field name="signal">wait_auth_request</field>
        </record>

        <record model="workflow.transition" id="request_t9">
            <field name="act_from" ref="act_awaiting_auth" />
            <field name="act_to" ref="act_closed_ref" />
            <field name="signal">close_ref_request</field>
        </record>

        <record model="workflow.transition" id="request_t10">
            <field name="act_from" ref="act_awaiting_auth" />
            <field name="act_to" ref="act_treatment" />
            <field name="signal">auth_send_processing</field>
        </record>

        <record model="workflow.transition" id="request_t11">
            <field name="act_from" ref="act_treatment" />
            <field name="act_to" ref="act_req_reformulate" />
            <field name="signal">req_reformulate_request</field>
        </record>

        <record model="workflow.transition" id="request_t12">
            <field name="act_from" ref="act_treatment" />
            <field name="act_to" ref="act_awaiting_appr" />
            <field name="signal">wait_appr_request</field>
        </record>

        <record model="workflow.transition" id="request_t13">
            <field name="act_from" ref="act_awaiting_appr" />
            <field name="act_to" ref="act_closed_disappr" />
            <field name="signal">close_disappr_request</field>
        </record>

        <record model="workflow.transition" id="request_t14">
            <field name="act_from" ref="act_awaiting_appr" />
            <field name="act_to" ref="act_treatment" />
            <field name="signal">appr_send_processing</field>
        </record>

    </data>
</openerp>

Relevant python code:

def request_draft(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'draft'})
    self.insert_trace(cr, uid, ids,  context)
    return True

# workflow condition returns true if requestor is responsible 
def check_responsible(self, cr, uid, ids, context=None):
    return self.browse(cr, uid, ids, context)[0].is_responsible

# next two functions are also workflow conditions
def ref_goto_confirmed(self, cr, uid, ids, context=None):
    req = self.browse(cr, uid, ids, context)
    if req[0].needs_reformulation and req[0].goto == 'confirmed':
        self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
        self.write(cr, uid, ids, {'goto':'','state': 'confirmed'}) # if request is already in motion, clean up the goto tag and go to where it came from
        return True
    return False
def ref_goto_treatment(self, cr, uid, ids, context=None):
    req = self.browse(cr, uid, ids, context)
    if req[0].needs_reformulation and req[0].goto == 'treatment':
        self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
        self.write(cr, uid, ids, {'goto':'','state': 'treatment'}) # if request is already in motion, clean up the goto tag and go to where it came from
        #self.insert_trace(cr, uid, ids, context)
        return True
    return False

def confirm_request(self, cr, uid, ids, context=None):
    resp = self.browse(cr,uid,ids,context)
    self.write(cr, uid, ids, {'state': 'confirmed'})
    self.insert_trace(cr, uid, ids, context)
    return True

def submit_request(self, cr, uid, ids, context=None):
    req = self.browse(cr,uid,ids,context)
    if req[0].needs_reformulation: 
        if req[0].goto == 'submitted':
            self.write(cr, uid, ids, {'needs_reformulation': False, 'reformulation_info': ''}) #clean up reformulation settings
            self.write(cr, uid, ids, {'goto':'','state': 'submitted'})
            self.insert_trace(cr, uid, ids, context)
            return True
        return False
    else:
        self.write(cr, uid, ids, {'state': 'submitted'})
        self.insert_trace(cr, uid, ids, context)
        return True

def close_nconf_request(self, cr, uid, ids, context=None):
    self.write(cr, uid, ids, {'state': 'closed_nconf'})
    self.insert_trace(cr, uid, ids, context)
    return True

def req_reformulate_request(self, cr, uid, ids, context=None):
    req = self.browse(cr, uid, ids, context=context)
    goto = req[0].state
    if goto:
        self.write(cr, uid, ids, {'goto': goto, 'state': 'req_reformulation', 'needs_reformulation': True} )
    else:
        self.write(cr, uid, ids, {'state': 'req_reformulation', 'needs_reformulation': True})
    self.insert_trace(cr, uid, ids, context)
    return True

Hope this will help someone! :)

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

0 follower(s)

Stats

Asked: 4/30/14, 11:26 AM
Seen: 1320 times
Last updated: 3/16/15, 8:10 AM