I've set up a wizard in OpenERP 7.0 that is updating fields correctly and all is working fine. Now I would like that, after submitting and updating the information on my object, the wizard would send a signal to the workflow of the object it acted uppon, to check if there is any transition to be taken.
How should I do that?
Do I have to directly call the workflow action from inside the def save_info() (see code below)? (I've tried this call self.pool.get('generic.request').req_reformulate_request(cr, uid, context['active_id'], context) but it throws so many errors, that I quickly gave up this approach)
Do I have to return something like 'signal': 'generic.request.req_reformulate_request' ?
Since I didn't find any information on this, I'm completely lost here, so any help would be very appreciated!
Thanks!
My wizard python code is the following:
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.translate import _class ref_generic_request(osv.osv_memory):
_name='ref.generic.request'_columns = {
'reformulation_info': fields.text('Reformulation instructions', help='Instructions for the requestor justification the reformulation needs'),
}def save_info(self, cr, uid, ids, context=None):
if 'active_id' in context:
info=self.browse(cr,uid,ids)[0].reformulation_info
self.pool.get('generic.request').write(cr,uid,context['active_id'],{'reformulation_info' : info, 'needs_reformulation': 1})#self.pool.get('generic.request').req_reformulate_request(cr, uid, context['active_id'], context)
return {
'type': 'ir.actions.act_window_close',
}
ref_generic_request()
And this is the XML that defines wizard's view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_reformulate_generic_request_wizard" model="ir.ui.view">
<field name="name">reformulate_generic_request_wizard.form</field>
<field name="model">ref.generic.request</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Insert reformulation info" version="7.0">
<group >
<separator string="Please insert instruction for the reformulation of this request" colspan="2"/>
<field name="reformulation_info" string="Reformulation info"/>
<newline/>
</group>
<div style="text-align:right">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="save_info" string="Send to reformulation" type="object" />
</div>
</form>
</field>
</record>
<record id="action_reformulate_generic_request" model="ir.actions.act_window">
<field name="name">Reformulate Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ref.generic.request</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_reformulate_generic_request_wizard"/>
<field name="target">new</field>
</record>
<act_window id="action_reformulate_generic_request"
name="Reformulate Request"
res_model="ref.generic.request"
view_mode="form"
target="new"
/>
</data>
</openerp>
I have a workflow (I'll show here only the part that is relevant for this question):
<?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>
(...)
<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_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.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>
(...)
</data>
</openerp>
And after the wizard updates info in my generic.request object I would like it to signal a function that and is actually called from the workflow the make the transition:
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