← Back to team overview

openerp-india team mailing list archive

[Bug 1224419] Re: Audittrail 7.0 don't work properly with o2m fields

 

Hello Sergio,

Would you please provide more information on that? As I checked this
issue with trunk as well with stable 7.0 ,its working fine. So, please
check it again and provide more steps to reproduce it.

Thanks & waiting for your answer.

** Changed in: openobject-addons
       Status: New => Incomplete

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1224419

Title:
  Audittrail 7.0 don't work properly with o2m fields

Status in OpenERP Addons (modules):
  Incomplete

Bug description:
  Variable model must be defined:
   before than search of model name:
                                   "model = pool.get('ir.model').browse(cr, uid, model_id)"
                                   "name = pool.get(model.model).name_get(cr, uid, [resource_id])[0][1]"
  otherwise can fail in some case.

  Less important is that "if lines[(model_id, resource_id)]:" must condition all content inside block "for":
                                   "for model_id, resource_id in lines:
                                         if lines[(model_id, resource_id)]:"


  def process_data(self, cr, uid, pool, res_ids, model, method, old_values=None, new_values=None, field_list=None):
          """
          This function processes and iterates recursively to log the difference between the old
          data (i.e before the method was executed) and the new data and creates audittrail log
          accordingly.

          :param cr: the current row, from the database cursor,
          :param uid: the current user’s ID,
          :param pool: current db's pooler object.
          :param res_ids: Id's of resource to be logged/compared.
          :param model: model object which values are being changed
          :param method: method to log: create, read, unlink, write, actions, workflow actions
          :param old_values: dict of values read before execution of the method
          :param new_values: dict of values read after execution of the method
          :param field_list: optional argument containing the list of fields to log. Currently only
              used when performing a read, it could be usefull later on if we want to log the write
              on specific fields only.
          :return: True
          """
          if field_list is None:
              field_list = []
          # loop on all the given ids
          for res_id in res_ids:
              # compare old and new values and get audittrail log lines accordingly
              lines = self.prepare_audittrail_log_line(cr, uid, pool, model, res_id, method, old_values, new_values, field_list)

              # if at least one modification has been found
              for model_id, resource_id in lines:
  ++++++++++++++++++++++++++++++++++++++++++++++++++
                  model = pool.get('ir.model').browse(cr, uid, model_id)
  ++++++++++++++++++++++++++++++++++++++++++++++++++
                  name = pool.get(model.model).name_get(cr, uid, [resource_id])[0][1]
                  vals = {
                      'method': method,
                      'object_id': model_id,
                      'user_id': uid,
                      'res_id': resource_id,
                      'name': name,
                  }
                  if (model_id, resource_id) not in old_values and method not in ('copy', 'read'):
                      # the resource was not existing so we are forcing the method to 'create'
                      # (because it could also come with the value 'write' if we are creating
                      #  new record through a one2many field)
                      vals.update({'method': 'create'})
                  if (model_id, resource_id) not in new_values and method not in ('copy', 'read'):
                      # the resource is not existing anymore so we are forcing the method to 'unlink'
                      # (because it could also come with the value 'write' if we are deleting the
                      #  record through a one2many field)
                      vals.update({'method': 'unlink'})
                  # create the audittrail log in super admin mode, only if a change has been detected
                  if lines[(model_id, resource_id)]:
                      log_id = pool.get('audittrail.log').create(cr, SUPERUSER_ID, vals)
  ------------------------------------------------------------------------------------------
  #                    model = pool.get('ir.model').browse(cr, uid, model_id)
  ------------------------------------------------------------------------------------------
                      self.create_log_line(cr, SUPERUSER_ID, log_id, model, lines[(model_id, resource_id)])
          return True

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1224419/+subscriptions


References