code: def logged_query(cr, query, args=None, skip_no_result=False):
      
      if args is None:
          args = ()
      args = tuple(args) if type(args) == list else args
      try:
          cr.execute(query, args)
      except (ProgrammingError, IntegrityError):
          logger.error('Error running %s' % cr.mogrify(query, args))
          raise
      if not skip_no_result or cr.rowcount:
          logger.debug('Running %s', query % args)
          logger.debug('%s rows affected', cr.rowcount)
      return cr.rowcount
docs: Logs query and affected rows at level DEBUG.
  
      :param query: a query string suitable to pass to cursor.execute()
      :param args: a list, tuple or dictionary passed as substitution values
        to cursor.execute().
      :param skip_no_result: If True, then logging details are only shown
        if there are affected records.