0

Is there a way to keep track of changes made on workflow status so that users can follow through the process I'm implementing.

Ex:
Created on March 1st, by User 1.
Submitted on March 1st, by User 1.
Reviewing on March 2nd, by Admin.
Evaluating on March 4th, by SuperUser.
Accepted on March 6th, by MegaUser.

So, the fists record would be inserted when the request is created, the second when the workflow button "submit" is clicked; the third when the workflow button "review" is clicked and so on.

Any thoughts or sugestions are more than welcome!

Using the records of Audit Trail is not an option for this.

Thanks in advance. -FC.


I've solved this using self.pool.get('obj_name').create(cr, uid,values) to create new entries in that second table.

used this function:

    def insert_trace(self, cr, uid, id_request, context=None):
    request = self.browse(cr, uid, id_request, context)
    values = { 
        'generic_request_id':  id_request[0],
        'executor': self._get_user(cr, uid, context),
        'state': request[0].state,
    }
    tracing_ids = self.pool.get('tracing').create(cr, uid,values)
    return True

and called it, each time workflow changed, e.g:

    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):
    self.write(cr, uid, ids, {'state': 'submitted'})
    self.insert_trace(cr, uid, ids, context)
    return True

I'll leave this here, to help anyone with the same problem that I was having. Thanks for your tips!

3 Answers3

0

Have your table inherit mail.thread, and have your buttons send messages to any followers.

Here's a stripped down version of one of the tables where I have this implemented:

class fnx_sr_shipping(osv.Model):
    _name = 'fnx.sr.shipping'
    _description = 'shipping & receiving'
    _inherit = ['mail.thread']
    _mail_flat_thread = False

    ...

    def create(self, cr, uid, values, context=None):
        ...
        body = "some message"
        follower_ids = [47, 29, 31] # actual ids here
        ...
        new_id = super(fnx_sr_shipping, self).create(cr, uid, values, context=context)
        self.message_post(cr, uid, new_id, body=body,
                partner_ids=follower_ids, subtype='mt_comment',
                context=context)
        return new_id

    def sr_complete(self, cr, uid, ids, context=None):
        ...
        for id in ids:
            current = self.browse(cr, uid, id, context=context)
            if self.write(cr, uid, id, values, context=context):
                context['mail_create_nosubscribe'] = True
                followers = self._get_followers(cr, uid, [id], None, None,
                        context=context)[id]['message_follower_ids']
                message = 'Complete:  ...'
                self.message_post(cr, uid, id, body=message, subtype='mt_comment',
                        partner_ids=followers, context=context)
        return True

and then in the XML file:

<button string="Complete" name="sr_complete" type="object"/>
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • Thanks for your answer, but I guess I wasn't clear on my explanation. I want the changes stored on database and display the trace of each request on a page in form view. This way, at any time, users can see process evolution, what is his current status and who is in charge at a given moment. – Filipe Castanheira Mar 25 '14 at 11:33
  • @FilipeCastanheira: Perhaps `OpenChatter` is what you want then. It displays all the messages that have been sent at the bottom of the form view. Otherwise you'll need to create a separate `history` table with a `one2many` link to it, log your entries there, and add it as a `notebook` `page`. – Ethan Furman Mar 25 '14 at 16:56
0

I've solved this using self.pool.get('obj_name').create(cr, uid,values) to create new entries in that second table.

used this function:

def insert_trace(self, cr, uid, id_request, context=None):
    request = self.browse(cr, uid, id_request, context)
    values = { 
        'generic_request_id':  id_request[0],
        'executor': self._get_user(cr, uid, context),
        'state': request[0].state,
    }
    tracing_ids = self.pool.get('tracing').create(cr, uid,values)
    return True

and called it, each time workflow changed, e.g:

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):
    self.write(cr, uid, ids, {'state': 'submitted'})
    self.insert_trace(cr, uid, ids, context)
    return True

I'll leave this here, to help anyone with the same problem that I was having.

-1

We have developed a module to perform this task, if someone else is in need can be downloaded from https://github.com/AC-Hoatzin/odoo-addons.