Exemplo n.º 1
0
    def create(cls, session, record, workflow_id):
        assert isinstance(session, Session)
        assert isinstance(record, Record)
        assert isinstance(workflow_id, (int, long))

        cr = session.cr
        cr.execute(
            'insert into wkf_instance (res_type,res_id,uid,wkf_id,state) values (%s,%s,%s,%s,%s) RETURNING id',
            (record.model, record.id, session.uid, workflow_id, 'active'))
        instance_id = cr.fetchone()[0]

        cr.execute(
            'select * from wkf_activity where flow_start=True and wkf_id=%s',
            (workflow_id, ))
        stack = []

        activities = cr.dictfetchall()
        for activity in activities:
            WorkflowItem.create(session, record, activity, instance_id, stack)

        cr.execute('SELECT * FROM wkf_instance WHERE id = %s', (instance_id, ))
        values = cr.dictfetchone()
        wi = WorkflowInstance(session, record, values)
        wi.update()

        return wi
Exemplo n.º 2
0
    def create(cls, session, record, workflow_id):
        assert isinstance(session, Session)
        assert isinstance(record, Record)
        assert isinstance(workflow_id, int)

        cr = session.cr
        cr.execute(
            'insert into wkf_instance (res_type,res_id,uid,wkf_id,state) values (%s,%s,%s,%s,%s) RETURNING id',
            (record.model, record.id, session.uid, workflow_id, 'active'))
        instance_id = cr.fetchone()[0]

        cr.execute(
            'select * from wkf_activity where flow_start=True and wkf_id=%s',
            (workflow_id, ))
        stack = []

        activities = cr.dictfetchall()
        for activity in activities:
            WorkflowItem.create(session, record, activity, instance_id, stack)

        cr.execute('SELECT * FROM wkf_instance WHERE id = %s', (instance_id, ))
        values = cr.dictfetchone()
        wi = WorkflowInstance(session, record, values)
        wi.update()

        return wi
Exemplo n.º 3
0
def i_create(cls, session, record, workflow_id):
    assert isinstance(session, Session)
    assert isinstance(record, Record)
    assert isinstance(workflow_id, (int, long))

    cr = session.cr
    cr.execute(
        'SELECT flow_start, id, name, required, sequence FROM wkf_activity WHERE wkf_id=%s ORDER BY flow_start',
        (workflow_id, ))
    activities = cr.dictfetchall()
    wi = False
    stack = []
    instance_id = False
    for activity in activities:
        if activity['flow_start']:
            cr.execute(
                """INSERT INTO wkf_instance (name, 
                                                    activity_id, 
                                                    required, 
                                                    sequence, 
                                                    res_type, 
                                                    res_id, 
                                                    uid, 
                                                    wkf_id, 
                                                    state, 
                                                    progress, 
                                                    date, 
                                                    is_active) 
                            VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, true, now(), true) RETURNING id""",
                (activity['name'], activity['id'], activity['required'],
                 activity['sequence'], record.model, record.id, session.uid,
                 workflow_id, 'active'))
            instance_id = cr.fetchone()[0]
            WorkflowItem.create(session, record, activity, instance_id, stack)
            cr.execute('SELECT * FROM wkf_instance WHERE id = %s',
                       (instance_id, ))
            values = cr.dictfetchone()
            wi = WorkflowInstance(session, record, values)
            wi.update()
        else:
            cr.execute(
                """INSERT INTO wkf_instance (name, 
                                                    activity_id, 
                                                    required, 
                                                    sequence, 
                                                    res_type, 
                                                    res_id, 
                                                    wkf_id, 
                                                    state, 
                                                    is_active) 
                            VALUES (%s, %s, %s, %s, %s, %s, %s, %s, true) RETURNING id""",
                (activity['name'], activity['id'], activity['required'],
                 activity['sequence'], record.model, record.id, workflow_id,
                 'active'))

    return wi
Exemplo n.º 4
0
    def validate(self, signal, force_running=False):
        assert isinstance(signal, basestring)
        assert isinstance(force_running, bool)

        cr = self.session.cr
        cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],))
        stack = []
        for work_item_values in cr.dictfetchall():
            wi = WorkflowItem(self.session, self.record, work_item_values)
            wi.process(signal=signal, force_running=force_running, stack=stack)
            # An action is returned
        self._update_end()
        return stack and stack[0] or False
Exemplo n.º 5
0
    def validate(self, signal, force_running=False):
        assert isinstance(signal, basestring)
        assert isinstance(force_running, bool)

        cr = self.session.cr
        cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],))
        stack = []
        for work_item_values in cr.dictfetchall():
            wi = WorkflowItem(self.session, self.record, work_item_values)
            wi.process(signal=signal, force_running=force_running, stack=stack)
            # An action is returned
        self._update_end()
        return stack and stack[0] or False
Exemplo n.º 6
0
    def update(self):
        cr = self.session.cr

        cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],))
        for work_item_values in cr.dictfetchall():
            stack = []
            WorkflowItem(self.session, self.record, work_item_values).process(stack=stack)
        return self._update_end()
Exemplo n.º 7
0
    def validate(self, signal, force_running=False):
        assert isinstance(signal, basestring)
        assert isinstance(force_running, bool)

        cr = self.session.cr
        cr.execute("select * from wkf_workitem where inst_id=%s", (self.instance['id'],))
        stack = []
        for i, work_item_values in enumerate(cr.dictfetchall()):
            if i > 0:
                # test if previous workitem has already processed this one
                cr.execute("select id from wkf_workitem where id=%s", (work_item_values['id'],))
                if not cr.fetchone():
                    continue
            wi = WorkflowItem(self.session, self.record, work_item_values)
            wi.process(signal=signal, force_running=force_running, stack=stack)
            # An action is returned
        self._update_end()
        return stack and stack[0] or False
Exemplo n.º 8
0
    def validate(self, signal, force_running=False):
        assert isinstance(signal, str)
        assert isinstance(force_running, bool)

        cr = self.session.cr
        cr.execute("select * from wkf_workitem where inst_id=%s",
                   (self.instance['id'], ))
        stack = []
        for i, work_item_values in enumerate(cr.dictfetchall()):
            if i > 0:
                # test if previous workitem has already processed this one
                cr.execute("select id from wkf_workitem where id=%s",
                           (work_item_values['id'], ))
                if not cr.fetchone():
                    continue
            wi = WorkflowItem(self.session, self.record, work_item_values)
            wi.process(signal=signal, force_running=force_running, stack=stack)
            # An action is returned
        self._update_end()
        return stack and stack[0] or False
Exemplo n.º 9
0
    def create_override(cls, session, record, activity, instance_id, stack):
        assert isinstance(session, Session)
        assert isinstance(record, Record)
        assert isinstance(activity, dict)
        assert isinstance(instance_id, (long, int))
        assert isinstance(stack, list)

        cr = session.cr
         # DECOD.IO- db_uid cr.execute("select nextval('wkf_workitem_id_seq')")
        cr.execute("select nextval('ir_serial_id_seq')")  # DECOD.IO+ db_uid
        id_new = cr.fetchone()[0]
        cr.execute("insert into wkf_workitem (id,act_id,inst_id,state) values (%s,%s,%s,'active')", (id_new, activity['id'], instance_id))
        cr.execute('select * from wkf_workitem where id=%s',(id_new,))
        work_item_values = cr.dictfetchone()
        logger.info('Created workflow item in activity %s',
                    activity['id'],
                    extra={'ident': (session.uid, record.model, record.id)})

        workflow_item = WorkflowItem(session, record, work_item_values)
        workflow_item.process(stack=stack)
Exemplo n.º 10
0
def wi_create(cls, session, record, activity, instance_id, stack):
    assert isinstance(session, Session)
    assert isinstance(record, Record)
    assert isinstance(activity, dict)
    assert isinstance(instance_id, (long, int))
    assert isinstance(stack, list)

    cr = session.cr
    cr.execute(
        "UPDATE wkf_instance SET progress=true, uid=%s, date=now() WHERE activity_id=%s AND res_id = %s and res_type = %s",
        (session.uid, activity['id'], record.id, record.model))
    cr.execute("select nextval('wkf_workitem_id_seq')")
    id_new = cr.fetchone()[0]
    cr.execute(
        "insert into wkf_workitem (id,act_id,inst_id,state) values (%s,%s,%s,'active')",
        (id_new, activity['id'], instance_id))
    cr.execute('select * from wkf_workitem where id=%s', (id_new, ))
    work_item_values = cr.dictfetchone()
    logger.info('Created workflow item in activity %s',
                activity['id'],
                extra={'ident': (session.uid, record.model, record.id)})

    workflow_item = WorkflowItem(session, record, work_item_values)
    workflow_item.process(stack=stack)
Exemplo n.º 11
0
def _join_test(self, trans_id, inst_id, stack):
    def get_activity(transition_id):
        res = False
        cr.execute(
            'SELECT is_active, activity_id FROM wkf_instance WHERE activity_id=(SELECT act_to FROM wkf_transition WHERE id=%s) AND res_id=%s AND res_type=%s LIMIT 1',
            (transition_id, self.record.id, self.record.model))
        instance = cr.dictfetchone()
        if instance:
            if instance['is_active']:
                act_id = instance['activity_id']
                cr.execute("SELECT * FROM wkf_activity WHERE id = %s",
                           (act_id, ))
                res = cr.dictfetchone()
            else:
                cr.execute(
                    "SELECT id from wkf_transition WHERE act_from=%s AND is_default=true LIMIT 1",
                    (instance['activity_id'], ))
                new_transition_id = cr.dictfetchone()
                if new_transition_id:
                    res = get_activity(new_transition_id['id'])

        return res

    cr = self.session.cr
    #     cr.execute('select * from wkf_activity where id=(select act_to from wkf_transition where id=%s)', (trans_id,))
    #     cr.dictfetchone()
    activity = get_activity(trans_id)
    if activity:
        cr.execute(
            "SELECT id FROM wkf_instance WHERE activity_id=%s AND res_id=%s AND res_type=%s",
            (activity['id'], self.record.id, self.record.model))
        instance = cr.dictfetchone()
        if activity['join_mode'] == 'XOR':
            WorkflowItem.create(self.session,
                                self.record,
                                activity,
                                instance['id'],
                                stack=stack)
            cr.execute(
                'delete from wkf_witm_trans where inst_id=%s and trans_id=%s',
                (inst_id, trans_id))
        else:
            cr.execute(
                'select id from wkf_transition where act_to=%s ORDER BY sequence,id',
                (activity['id'], ))
            trans_ids = cr.fetchall()
            ok = True
            for (id, ) in trans_ids:
                cr.execute(
                    'select count(*) from wkf_witm_trans where trans_id=%s and inst_id=%s',
                    (id, inst_id))
                res = cr.fetchone()[0]
                if not res:
                    ok = False
                    break
            if ok:
                for (id, ) in trans_ids:
                    cr.execute(
                        'delete from wkf_witm_trans where trans_id=%s and inst_id=%s',
                        (id, inst_id))

                WorkflowItem.create(self.session,
                                    self.record,
                                    activity,
                                    instance['id'],
                                    stack=stack)