I finally managed to solve this in a very tortuous way. If anyone has a more straight forward way to do this, please help!
So, what I did was, create and save the opinion request and, in the function called by the workflow (request_opinion), I call an other function that checks the id of the request associated to this opinion an then it's actual state and, finally, updates the value in the opinion table.
Here is the code:
class opinion(osv.osv):
_name='opinion'
_description='opinion'
_columns={
(...)
'state': fields.selection([('requested','Requested'),
('reviewing','Reviewing'),
('issued','Issued'),
('added','Added to the request')],
'Status', readonly=True, track_visibility='onchange',
),
(...)
'request_state': fields.selection([('draft','Draft'),
('submitted','Submitted - Waiting for confirmation'),
('req_reformulation', 'Reformulation'),
('confirmed', 'Confirmed - Processing'),
('treatment', 'Processing'),
('wauth', 'Awaiting authorization'),
('wappr', 'Awaiting approval'),
('authorized','Authorized'),
('closed', 'Request closed'),
('closed_auth', 'Closed - Authorized'),
('closed_appr', 'Closed - Approved'),
('closed_disappr', 'Closed - Disapproved'),
('closed_nconf', 'Closed - Not confirmed'),
('closed_ref', 'Closed - Refused'),
('denied','Denied')],
'Request Status', help="Status of the request when the opinion was requested", readonly=True, track_visibility='onchange',
),
'generic_request_id': fields.many2one('generic.request', 'Request', required=True),
}
def _get_request_state(self, cr, uid, ids, context=None):
res={}
op = self.browse(cr, uid, ids, context=context)
req_id = op[0].generic_request_id.id
req = self.pool.get('generic.request').browse(cr, uid, req_id, context)
#import pdb; pdb.set_trace()
self.write(cr, uid, ids, {'request_state': req.state })
return True
def request_opinion(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'requested'})
self._get_request_state(cr, uid, ids, context=context)
return True
As I said before, if someone has a better sugestion to do this a more effective way, feel free to share!
Edit:
Changed it to be a little more effective (no need to call the _get_request_state() anymore). But still if anyone has better way to do this, fill free to share!
def request_opinion(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'state': 'requested', 'request_state': self.browse(cr, uid, ids, context=context)[0].generic_request_id.state })
#self._get_request_state(cr, uid, ids, context=context)
return True