~jfb-tempo-consulting/unifield-wm/US-968

« back to all changes in this revision

Viewing changes to msf_audittrail/audittrail.py

  • Committer: jf
  • Date: 2016-03-01 16:03:02 UTC
  • Revision ID: jfb@tempo-consulting.fr-20160301160302-oiifyp0tv8n98m0w
US-968 [FIX] Track changes: display a tree view with a pager
Rewrite search method on auditrail.log.line to use offset and pager

Show diffs side-by-side

added added

removed removed

Lines of Context:
859
859
        if context is None:
860
860
            context = {}
861
861
 
862
 
        search_ids = super(audittrail_log_line, self).search(cr, uid, args, offset=0,
863
 
                                                             limit=None, order=order,
864
 
                                                             context=context, count=count)
865
 
        # US-313: check if the context provides active_model in order to search for inherited models for other fields, if not just return 
866
 
        if 'active_model' not in context:
867
 
            return search_ids
868
 
 
869
 
        id_model_obj = self.pool.get('ir.model')
870
 
        model_id = context['active_model']
871
 
        current_obj = self.pool.get(model_id)
872
 
        inherit = False
873
 
        for obj_class in current_obj._inherits:
874
 
            inherit = True
875
 
            args_inherit = [('model', '=', obj_class)]
876
 
            obj_inherit = id_model_obj.search(cr, uid, args_inherit, context=context)
877
 
            new_args = [('object_id', '=', obj_inherit[0]),
878
 
                        ('res_id', '=', context['active_id'])]
879
 
            ids = super(audittrail_log_line, self).search(cr, uid, new_args, offset=0,
880
 
                                                          limit=None, order=order,
881
 
                                                          context=context, count=count)
882
 
            search_ids = search_ids + ids
883
 
 
884
 
        if inherit and not isinstance(search_ids, (int, long)):
885
 
            args_final = [('id', 'in', search_ids)]
886
 
            search_ids = super(audittrail_log_line, self).search(cr, uid, args_final, offset=offset,
887
 
                                                                 limit=limit, order=order,
888
 
                                                                 context=context, count=count)
889
 
        return search_ids
 
862
        if context.get('active_model') and context.get('active_id'):
 
863
            id_model_obj = self.pool.get('ir.model')
 
864
            current_obj = self.pool.get(context['active_model'])
 
865
            add_obj = []
 
866
            num = 0
 
867
            for obj_class in current_obj._inherits:
 
868
                # get inherits object and inherits id
 
869
                obj_inherit = id_model_obj.search(cr, uid, [('model', '=', obj_class)], context=context)
 
870
 
 
871
                inherit_field = current_obj._inherits[obj_class]
 
872
                rel_obj = current_obj.read(cr, uid, [context['active_id']], [inherit_field], context=context)[0]
 
873
                if rel_obj[inherit_field]:
 
874
                    add_obj += ['&', ('object_id', '=', obj_inherit[0]), ('res_id', '=', rel_obj[inherit_field][0])]
 
875
                    num += 1
 
876
 
 
877
            if add_obj:
 
878
                # build the new domain
 
879
                new_args = []
 
880
                target_model = id_model_obj.search(cr, uid, [('model', '=', context['active_model'])], context=context)
 
881
                current_filter = ['&', ('res_id', '=', context['active_id']), ('object_id', '=', target_model[0])]
 
882
                for arg in args:
 
883
                    if arg[0] == 'object_id':
 
884
                        new_args += ['|' * num] + current_filter + add_obj
 
885
                    elif arg[0] == 'res_id':
 
886
                        pass
 
887
                    else:
 
888
                        new_args += [arg]
 
889
                args = new_args
 
890
 
 
891
 
 
892
        return super(audittrail_log_line, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count)
890
893
 
891
894
 
892
895
    _columns = {