'Send a signal to parenrt workflow (signal: subflow.signal_name)'

def _execute(self, activity, stack):

    result = True
    cr = self.session.cr
    signal_todo = []
    if ((self.workitem['state'] == 'active') and activity['signal_send']):
        cr.execute('select    i.id,w.osv,i.res_id    from    wkf_instance    i    left    join    wkf    w    on    (i.wkf_id=w.id)    where    i.id    IN    (select    inst_id    from    wkf_workitem    where    subflow_id=%s)', (self.workitem['inst_id'],))
        for (instance_id, model_name, record_id) in cr.fetchall():
            record = Record(model_name, record_id)
            signal_todo.append((instance_id, record, activity['signal_send']))
    if (activity['kind'] == WorkflowActivity.KIND_DUMMY):
        if (self.workitem['state'] == 'active'):
            self._state_set(activity, 'complete')
            if activity['action_id']:
                res2 = self.wkf_expr_execute_action(activity)
                if res2:
                    stack.append(res2)
                    result = res2
    elif (activity['kind'] == WorkflowActivity.KIND_FUNCTION):
        if (self.workitem['state'] == 'active'):
            self._state_set(activity, 'running')
            returned_action = self.wkf_expr_execute(activity)
            if (type(returned_action) in (dict,)):
                stack.append(returned_action)
            if activity['action_id']:
                res2 = self.wkf_expr_execute_action(activity)
                if res2:
                    stack.append(res2)
                    result = res2
            self._state_set(activity, 'complete')
    elif (activity['kind'] == WorkflowActivity.KIND_STOPALL):
        if (self.workitem['state'] == 'active'):
            self._state_set(activity, 'running')
            cr.execute('delete    from    wkf_workitem    where    inst_id=%s    and    id<>%s', (self.workitem['inst_id'], self.workitem['id']))
            if activity['action']:
                self.wkf_expr_execute(activity)
            self._state_set(activity, 'complete')
    elif (activity['kind'] == WorkflowActivity.KIND_SUBFLOW):
        if (self.workitem['state'] == 'active'):
            self._state_set(activity, 'running')
            if activity.get('action', False):
                id_new = self.wkf_expr_execute(activity)
                if (not id_new):
                    cr.execute('delete    from    wkf_workitem    where    id=%s', (self.workitem['id'],))
                    return False
                assert ((type(id_new) == type(1)) or (type(id_new) == type(1L))), ((('Wrong    return    value:    ' + str(id_new)) + '    ') + str(type(id_new)))
                cr.execute('select    id    from    wkf_instance    where    res_id=%s    and    wkf_id=%s', (id_new, activity['subflow_id']))
                id_new = cr.fetchone()[0]
            else:
                inst = instance.WorkflowInstance(self.session, self.record)
                id_new = inst.create(activity['subflow_id'])
            cr.execute('update    wkf_workitem    set    subflow_id=%s    where    id=%s', (id_new, self.workitem['id']))
            self.workitem['subflow_id'] = id_new
        if (self.workitem['state'] == 'running'):
            cr.execute('select    state    from    wkf_instance    where    id=%s', (self.workitem['subflow_id'],))
            state = cr.fetchone()[0]
            if (state == 'complete'):
                self._state_set(activity, 'complete')
    for (instance_id, record, signal_send) in signal_todo:
        wi = instance.WorkflowInstance(self.session, record, {'id': instance_id})
        wi.validate(signal_send, force_running=True)
    return result
