2009-10-14 11:15:34 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-24 14:45:43 +00:00
|
|
|
|
##############################################################################
|
|
|
|
|
#
|
2009-09-24 10:46:21 +00:00
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# GNU Affero General Public License for more details.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2008-11-03 19:18:56 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-24 14:45:43 +00:00
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
from osv import osv
|
|
|
|
|
from osv import fields
|
|
|
|
|
from tools.translate import _
|
2010-05-20 14:22:57 +00:00
|
|
|
|
import time
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
VoteValues = [('-1', 'Not Voted'), ('0', 'Very Bad'), ('25', 'Bad'), \
|
|
|
|
|
('50', 'Normal'), ('75', 'Good'), ('100', 'Very Good') ]
|
2008-08-24 14:45:43 +00:00
|
|
|
|
DefaultVoteValue = '50'
|
|
|
|
|
|
|
|
|
|
class idea_category(osv.osv):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
""" Category of Idea """
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = "idea.category"
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = "Idea Category"
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
|
|
|
|
'name': fields.char('Category', size=64, required=True),
|
|
|
|
|
'summary': fields.text('Summary'),
|
2010-03-17 10:44:02 +00:00
|
|
|
|
'parent_id': fields.many2one('idea.category', 'Parent Categories', ondelete='set null'),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
'child_ids': fields.one2many('idea.category', 'parent_id', 'Child Categories'),
|
2010-05-20 18:34:22 +00:00
|
|
|
|
'visibility':fields.boolean('Open Idea?', required=False, help="If True creator of the idea will be visible to others"),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
_sql_constraints = [
|
|
|
|
|
('name', 'unique(parent_id,name)', 'The name of the category must be unique' )
|
|
|
|
|
]
|
|
|
|
|
_order = 'parent_id,name asc'
|
2010-03-16 14:02:07 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
idea_category()
|
|
|
|
|
|
|
|
|
|
class idea_idea(osv.osv):
|
2010-03-17 10:44:02 +00:00
|
|
|
|
""" Idea """
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = 'idea.idea'
|
2010-08-30 05:48:41 +00:00
|
|
|
|
_rec_name = 'name'
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
|
|
def _vote_avg_compute(self, cr, uid, ids, name, arg, context = None):
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
|
|
|
|
""" compute average for voting
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of voting’s IDs
|
|
|
|
|
@return: dictionay of Idea """
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
if not ids:
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
sql = """SELECT i.id, avg(v.score::integer)
|
2010-05-05 14:45:41 +00:00
|
|
|
|
FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
|
2010-06-10 13:34:19 +00:00
|
|
|
|
WHERE i.id IN %s
|
2010-05-05 14:45:41 +00:00
|
|
|
|
GROUP BY i.id
|
|
|
|
|
"""
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
2010-06-10 13:34:19 +00:00
|
|
|
|
cr.execute(sql, (tuple(ids),))
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return dict(cr.fetchall())
|
|
|
|
|
|
2010-03-17 10:44:02 +00:00
|
|
|
|
def _vote_count(self, cr, uid, ids, name, arg, context=None):
|
|
|
|
|
|
|
|
|
|
""" count number of vote
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of voting count’s IDs
|
|
|
|
|
@return: dictionay of Idea """
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
if not ids:
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
sql = """SELECT i.id, COUNT(1)
|
2010-05-05 14:45:41 +00:00
|
|
|
|
FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
|
2010-06-10 13:34:19 +00:00
|
|
|
|
WHERE i.id IN %s
|
2010-05-05 14:45:41 +00:00
|
|
|
|
GROUP BY i.id
|
|
|
|
|
"""
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
2010-06-10 13:34:19 +00:00
|
|
|
|
cr.execute(sql, (tuple(ids),))
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return dict(cr.fetchall())
|
|
|
|
|
|
2010-03-17 10:44:02 +00:00
|
|
|
|
def _comment_count(self, cr, uid, ids, name, arg, context=None):
|
|
|
|
|
|
|
|
|
|
""" count number of comment
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of comment’s IDs
|
|
|
|
|
@return: dictionay of Idea """
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
if not ids:
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return {}
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
sql = """SELECT i.id, COUNT(1)
|
2010-05-05 14:45:41 +00:00
|
|
|
|
FROM idea_idea i LEFT OUTER JOIN idea_comment c ON i.id = c.idea_id
|
2010-06-10 13:34:19 +00:00
|
|
|
|
WHERE i.id IN %s
|
2010-05-05 14:45:41 +00:00
|
|
|
|
GROUP BY i.id
|
|
|
|
|
"""
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
2010-06-10 13:34:19 +00:00
|
|
|
|
cr.execute(sql, (tuple(ids),))
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return dict(cr.fetchall())
|
|
|
|
|
|
|
|
|
|
def _vote_read(self, cr, uid, ids, name, arg, context = None):
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
|
|
|
|
""" Read Vote
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of vote read’s IDs """
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res = {}
|
|
|
|
|
for id in ids:
|
|
|
|
|
res[id] = '-1'
|
|
|
|
|
vote_obj = self.pool.get('idea.vote')
|
|
|
|
|
votes_ids = vote_obj.search(cr, uid, [('idea_id', 'in', ids), ('user_id', '=', uid)])
|
2010-03-16 14:02:07 +00:00
|
|
|
|
vote_obj_id = vote_obj.browse(cr, uid, votes_ids, context)
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
for vote in vote_obj_id:
|
2008-08-24 14:45:43 +00:00
|
|
|
|
res[vote.idea_id.id] = vote.score
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
def _vote_save(self, cr, uid, id, field_name, field_value, arg, context = None):
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
|
|
|
|
""" save Vote
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of vote save’s IDs """
|
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
vote_obj = self.pool.get('idea.vote')
|
2010-03-17 10:44:02 +00:00
|
|
|
|
vote = vote_obj.search(cr, uid, [('idea_id', '=', id), ('user_id', '=', uid)])
|
2008-08-24 14:45:43 +00:00
|
|
|
|
textual_value = str(field_value)
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
if vote:
|
2010-03-17 10:44:02 +00:00
|
|
|
|
if int(field_value) >= 0:
|
|
|
|
|
vote_obj.write(cr, uid, vote, {'score': textual_value })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
else:
|
2010-03-17 10:44:02 +00:00
|
|
|
|
vote_obj.unlink(cr, uid, vote)
|
2008-08-24 14:45:43 +00:00
|
|
|
|
else:
|
2010-03-17 10:44:02 +00:00
|
|
|
|
if int(field_value) >= 0:
|
|
|
|
|
vote_obj.create(cr, uid, {'idea_id': id, 'user_id': uid, 'score': textual_value })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
|
'user_id': fields.many2one('res.users', 'Creator', required=True, readonly=True),
|
2010-08-30 05:48:41 +00:00
|
|
|
|
'name': fields.char('Idea Summary', size=64, required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
2010-05-20 18:34:22 +00:00
|
|
|
|
'description': fields.text('Description', help='Content of the idea', readonly=True, states={'draft':[('readonly',False)]}),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
'comment_ids': fields.one2many('idea.comment', 'idea_id', 'Comments'),
|
2010-05-20 14:22:57 +00:00
|
|
|
|
'created_date': fields.datetime('Creation date', readonly=True),
|
2010-03-16 14:02:07 +00:00
|
|
|
|
'vote_ids': fields.one2many('idea.vote', 'idea_id', 'Vote'),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
'my_vote': fields.function(_vote_read, fnct_inv = _vote_save, string="My Vote", method=True, type="selection", selection=VoteValues),
|
2010-03-16 14:02:07 +00:00
|
|
|
|
'vote_avg': fields.function(_vote_avg_compute, method=True, string="Average Score", type="float"),
|
|
|
|
|
'count_votes': fields.function(_vote_count, method=True, string="Count of votes", type="integer"),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
'count_comments': fields.function(_comment_count, method=True, string="Count of comments", type="integer"),
|
2010-05-20 18:34:22 +00:00
|
|
|
|
'category_id': fields.many2one('idea.category', 'Category', required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
2010-06-01 08:42:16 +00:00
|
|
|
|
'state': fields.selection([('draft', 'Draft'),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
('open', 'Opened'),
|
2010-06-01 08:42:16 +00:00
|
|
|
|
('close', 'Accepted'),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
('cancel', 'Cancelled')],
|
|
|
|
|
'State', readonly=True,
|
|
|
|
|
help='When the Idea is created the state is \'Draft\'.\n It is \
|
|
|
|
|
opened by the user, the state is \'Opened\'.\
|
|
|
|
|
\nIf the idea is accepted, the state is \'Accepted\'.'
|
|
|
|
|
),
|
|
|
|
|
'visibility':fields.boolean('Open Idea?', required=False),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
'stat_vote_ids': fields.one2many('idea.vote.stat', 'idea_id', 'Statistics', readonly=True),
|
2010-05-14 09:54:28 +00:00
|
|
|
|
'vote_limit': fields.integer('Maximum Vote per User',
|
2010-05-06 12:18:54 +00:00
|
|
|
|
help="Set to one if you require only one Vote per user"),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_defaults = {
|
|
|
|
|
'user_id': lambda self,cr,uid,context: uid,
|
2009-09-24 10:46:21 +00:00
|
|
|
|
'my_vote': lambda *a: '-1',
|
2010-05-05 14:45:41 +00:00
|
|
|
|
'state': lambda *a: 'draft',
|
2010-05-14 09:54:28 +00:00
|
|
|
|
'vote_limit': lambda * a: 1,
|
2010-06-01 08:42:16 +00:00
|
|
|
|
'created_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
2010-05-05 14:45:41 +00:00
|
|
|
|
'visibility': lambda *a: True,
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
_order = 'id desc'
|
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
def create(self, cr, user, vals, context={}):
|
|
|
|
|
"""
|
|
|
|
|
Create a new record for a model idea_idea
|
|
|
|
|
@param cr: A database cursor
|
|
|
|
|
@param user: ID of the user currently logged in
|
|
|
|
|
@param vals: provides data for new record
|
|
|
|
|
@param context: context arguments, like lang, time zone
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
@return: Returns an id of the new record
|
|
|
|
|
"""
|
|
|
|
|
visibility = False
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
if vals.get('category_id', False):
|
|
|
|
|
category_pool = self.pool.get('idea.category')
|
|
|
|
|
category = category_pool.browse(cr, user, vals.get('category_id'), context)
|
|
|
|
|
visibility = category.visibility
|
|
|
|
|
|
|
|
|
|
vals.update({
|
|
|
|
|
'visibility':visibility
|
|
|
|
|
})
|
2010-05-20 18:34:22 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
res_id = super(idea_idea, self).create(cr, user, vals, context)
|
|
|
|
|
return res_id
|
2010-05-20 18:34:22 +00:00
|
|
|
|
|
|
|
|
|
def copy(self, cr, uid, id, default={}, context={}):
|
|
|
|
|
"""
|
|
|
|
|
Create the new record in idea_idea model from existing one
|
|
|
|
|
@param cr: A database cursor
|
|
|
|
|
@param user: ID of the user currently logged in
|
|
|
|
|
@param id: list of record ids on which copy method executes
|
|
|
|
|
@param default: dict type contains the values to be overridden during copy of object
|
|
|
|
|
@param context: context arguments, like lang, time zone
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-20 18:34:22 +00:00
|
|
|
|
@return: Returns the id of the new record
|
|
|
|
|
"""
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-20 18:34:22 +00:00
|
|
|
|
default.update({
|
|
|
|
|
'comment_ids':False,
|
|
|
|
|
'vote_ids':False,
|
|
|
|
|
'stat_vote_ids':False
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-20 18:34:22 +00:00
|
|
|
|
})
|
|
|
|
|
res_id = super(idea_idea, self).copy(cr, uid, id, default, context)
|
|
|
|
|
return res_id
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
def write(self, cr, user, ids, vals, context=None):
|
|
|
|
|
"""
|
|
|
|
|
Update redord(s) exist in {ids}, with new value provided in {vals}
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
@param cr: A database cursor
|
|
|
|
|
@param user: ID of the user currently logged in
|
|
|
|
|
@param ids: list of record ids to update
|
|
|
|
|
@param vals: dict of new values to be set
|
|
|
|
|
@param context: context arguments, like lang, time zone
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
@return: Returns True on success, False otherwise
|
|
|
|
|
"""
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
state = self.browse(cr, user, ids[0]).state
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
if vals.get('my_vote', False):
|
|
|
|
|
if vals.get('state', state) != 'open':
|
|
|
|
|
raise osv.except_osv(_("Warning !"), _("Draft/Accepted/Cancelled ideas Could not be voted"))
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2010-05-05 14:45:41 +00:00
|
|
|
|
res = super(idea_idea, self).write(cr, user, ids, vals, context)
|
|
|
|
|
return res
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
def idea_cancel(self, cr, uid, ids):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
self.write(cr, uid, ids, { 'state': 'cancel' })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def idea_open(self, cr, uid, ids):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
self.write(cr, uid, ids, { 'state': 'open' })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def idea_close(self, cr, uid, ids):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
self.write(cr, uid, ids, { 'state': 'close' })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return True
|
2010-06-01 08:42:16 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
def idea_draft(self, cr, uid, ids):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
self.write(cr, uid, ids, { 'state': 'draft' })
|
2008-08-24 14:45:43 +00:00
|
|
|
|
return True
|
|
|
|
|
idea_idea()
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
class idea_comment(osv.osv):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
""" Apply Idea for Comment """
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = 'idea.comment'
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = 'Comment'
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_rec_name = 'content'
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
2010-03-17 10:44:02 +00:00
|
|
|
|
'idea_id': fields.many2one('idea.idea', 'Idea', required=True, ondelete='cascade'),
|
|
|
|
|
'user_id': fields.many2one('res.users', 'User', required=True),
|
|
|
|
|
'content': fields.text('Comment', required=True),
|
|
|
|
|
'create_date': fields.datetime('Creation date', readonly=True),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_defaults = {
|
|
|
|
|
'user_id': lambda self, cr, uid, context: uid
|
|
|
|
|
}
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_order = 'id desc'
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
idea_comment()
|
|
|
|
|
|
2010-03-16 14:02:07 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
class idea_vote(osv.osv):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
""" Apply Idea for Vote """
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = 'idea.vote'
|
2010-05-19 18:32:32 +00:00
|
|
|
|
_description = 'Idea Vote'
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_rec_name = 'score'
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
2010-06-22 12:26:04 +00:00
|
|
|
|
'user_id': fields.many2one('res.users', 'User', readonly="True"),
|
2010-05-14 09:54:28 +00:00
|
|
|
|
'idea_id': fields.many2one('idea.idea', 'Idea', readonly="True", ondelete='cascade'),
|
|
|
|
|
'score': fields.selection(VoteValues, 'Vote Status', readonly="True"),
|
|
|
|
|
'date': fields.datetime('Date', readonly="True"),
|
|
|
|
|
'comment': fields.text('Comment', readonly="True"),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
_defaults = {
|
|
|
|
|
'score': lambda *a: DefaultVoteValue,
|
2010-06-01 08:42:16 +00:00
|
|
|
|
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
}
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
idea_vote()
|
|
|
|
|
|
|
|
|
|
class idea_vote_stat(osv.osv):
|
2010-03-16 14:02:07 +00:00
|
|
|
|
""" Idea votes Statistics """
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_name = 'idea.vote.stat'
|
|
|
|
|
_description = 'Idea Votes Statistics'
|
|
|
|
|
_auto = False
|
|
|
|
|
_rec_name = 'idea_id'
|
2010-03-17 10:44:02 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
_columns = {
|
|
|
|
|
'idea_id': fields.many2one('idea.idea', 'Idea', readonly=True),
|
2010-03-16 14:02:07 +00:00
|
|
|
|
'score': fields.selection(VoteValues, 'Score', readonly=True),
|
2008-08-24 14:45:43 +00:00
|
|
|
|
'nbr': fields.integer('Number of Votes', readonly=True),
|
|
|
|
|
}
|
2010-03-16 14:02:07 +00:00
|
|
|
|
|
2010-03-17 10:44:02 +00:00
|
|
|
|
def init(self, cr):
|
2008-08-24 14:45:43 +00:00
|
|
|
|
"""
|
|
|
|
|
initialize the sql view for the stats
|
2009-09-24 10:46:21 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
cr -- the cursor
|
|
|
|
|
"""
|
|
|
|
|
cr.execute("""
|
2009-11-26 13:54:00 +00:00
|
|
|
|
CREATE OR REPLACE VIEW idea_vote_stat AS (
|
|
|
|
|
SELECT
|
|
|
|
|
MIN(v.id) AS id,
|
|
|
|
|
i.id AS idea_id,
|
2008-08-24 14:45:43 +00:00
|
|
|
|
v.score,
|
2009-11-26 13:54:00 +00:00
|
|
|
|
COUNT(1) AS nbr
|
|
|
|
|
FROM
|
2008-08-24 14:45:43 +00:00
|
|
|
|
idea_vote v
|
2009-11-26 13:54:00 +00:00
|
|
|
|
LEFT JOIN idea_idea i ON (v.idea_id = i.id)
|
|
|
|
|
GROUP BY
|
|
|
|
|
i.id, v.score, i.id )
|
|
|
|
|
""")
|
2010-03-16 14:02:07 +00:00
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
|
idea_vote_stat()
|
|
|
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|
|