diff --git a/addons/idea/__openerp__.py b/addons/idea/__openerp__.py
index c5794346f4d..9f840cf0612 100644
--- a/addons/idea/__openerp__.py
+++ b/addons/idea/__openerp__.py
@@ -42,7 +42,9 @@
'security/idea_security.xml',
'security/ir.model.access.csv',
],
- 'demo_xml': [],
+ 'demo_xml': [
+ "idea_data.xml"
+ ],
'installable': True,
'certificate': '0071515601309',
}
diff --git a/addons/idea/idea.py b/addons/idea/idea.py
index e698c85d0b4..2a6aafe2989 100644
--- a/addons/idea/idea.py
+++ b/addons/idea/idea.py
@@ -19,7 +19,9 @@
#
##############################################################################
-from osv import osv, fields
+from osv import osv
+from osv import fields
+from tools.translate import _
VoteValues = [('-1', 'Not Voted'), ('0', 'Very Bad'), ('25', 'Bad'), \
('50', 'Normal'), ('75', 'Good'), ('100', 'Very Good') ]
@@ -35,7 +37,8 @@ class idea_category(osv.osv):
'name': fields.char('Category', size=64, required=True),
'summary': fields.text('Summary'),
'parent_id': fields.many2one('idea.category', 'Parent Categories', ondelete='set null'),
- 'child_ids': fields.one2many('idea.category', 'parent_id', 'Child Categories')
+ 'child_ids': fields.one2many('idea.category', 'parent_id', 'Child Categories'),
+ 'visibility':fields.boolean('Open Idea?', required=False),
}
_sql_constraints = [
('name', 'unique(parent_id,name)', 'The name of the category must be unique' )
@@ -44,7 +47,6 @@ class idea_category(osv.osv):
idea_category()
-
class idea_idea(osv.osv):
""" Idea """
_name = 'idea.idea'
@@ -62,10 +64,10 @@ class idea_idea(osv.osv):
return {}
sql = """SELECT i.id, avg(v.score::integer)
- FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
- WHERE i.id = ANY(%s)
- GROUP BY i.id
- """
+ FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
+ WHERE i.id = ANY(%s)
+ GROUP BY i.id
+ """
cr.execute(sql, (ids,))
return dict(cr.fetchall())
@@ -82,10 +84,10 @@ class idea_idea(osv.osv):
return {}
sql = """SELECT i.id, COUNT(1)
- FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
- WHERE i.id = ANY(%s)
- GROUP BY i.id
- """
+ FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
+ WHERE i.id = ANY(%s)
+ GROUP BY i.id
+ """
cr.execute(sql, (ids,))
return dict(cr.fetchall())
@@ -102,10 +104,10 @@ class idea_idea(osv.osv):
return {}
sql = """SELECT i.id, COUNT(1)
- FROM idea_idea i LEFT OUTER JOIN idea_comment c ON i.id = c.idea_id
- WHERE i.id = ANY(%s)
- GROUP BY i.id
- """
+ FROM idea_idea i LEFT OUTER JOIN idea_comment c ON i.id = c.idea_id
+ WHERE i.id = ANY(%s)
+ GROUP BY i.id
+ """
cr.execute(sql, (ids,))
return dict(cr.fetchall())
@@ -156,29 +158,77 @@ class idea_idea(osv.osv):
'comment_ids': fields.one2many('idea.comment', 'idea_id', 'Comments'),
'create_date': fields.datetime('Creation date', readonly=True),
'vote_ids': fields.one2many('idea.vote', 'idea_id', 'Vote'),
- 'my_vote': fields.function(_vote_read, fnct_inv = _vote_save, \
- string="My Vote", method=True, type="selection", selection=VoteValues),
+ 'my_vote': fields.function(_vote_read, fnct_inv = _vote_save, string="My Vote", method=True, type="selection", selection=VoteValues),
'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"),
- 'count_comments': fields.function(_comment_count, method=True, \
- string="Count of comments", type="integer"),
+ 'count_comments': fields.function(_comment_count, method=True, string="Count of comments", type="integer"),
'category_id': fields.many2one('idea.category', 'Category', required=True),
- 'state': fields.selection([('draft', 'Draft'), ('open', 'Opened'), \
- ('close', 'Accepted'), ('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\'.'),
+ 'state': fields.selection([('draft', 'Draft'),
+ ('open', 'Opened'),
+ ('close', 'Accepted'),
+ ('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),
'stat_vote_ids': fields.one2many('idea.vote.stat', 'idea_id', 'Statistics', readonly=True),
}
_defaults = {
'user_id': lambda self,cr,uid,context: uid,
'my_vote': lambda *a: '-1',
- 'state': lambda *a: 'draft'
+ 'state': lambda *a: 'draft',
+ 'visibility': lambda *a: True,
}
_order = 'id desc'
+ 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
+
+ @return: Returns an id of the new record
+ """
+ visibility = False
+
+ 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
+ })
+ res_id = super(idea_idea, self).create(cr, user, vals, context)
+ return res_id
+
+ def write(self, cr, user, ids, vals, context=None):
+ """
+ Update redord(s) exist in {ids}, with new value provided in {vals}
+
+ @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
+
+ @return: Returns True on success, False otherwise
+ """
+
+ state = self.browse(cr, user, ids[0]).state
+
+ 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"))
+
+ res = super(idea_idea, self).write(cr, user, ids, vals, context)
+ return res
+
def idea_cancel(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state': 'cancel' })
return True
@@ -190,7 +240,7 @@ class idea_idea(osv.osv):
def idea_close(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state': 'close' })
return True
-
+
def idea_draft(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state': 'draft' })
return True
@@ -238,7 +288,6 @@ class idea_vote(osv.osv):
idea_vote()
-
class idea_vote_stat(osv.osv):
""" Idea votes Statistics """
diff --git a/addons/idea/idea_data.xml b/addons/idea/idea_data.xml
new file mode 100644
index 00000000000..8c147c35d32
--- /dev/null
+++ b/addons/idea/idea_data.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+ General
+ General Ideas
+ True
+
+
+
+ TODO: Need to put a good idea on OpenERP
+ TODO: Need to put a good idea on OpenERP
+
+ True
+
+
+
+
diff --git a/addons/idea/idea_view.xml b/addons/idea/idea_view.xml
index 7dc0b5f7178..38ac9eda0a7 100644
--- a/addons/idea/idea_view.xml
+++ b/addons/idea/idea_view.xml
@@ -2,8 +2,7 @@
-
-
+
idea.category.form
@@ -11,16 +10,18 @@
form
-
-
+
idea.category.tree
idea.category
@@ -33,7 +34,7 @@
-
+
Categories
@@ -47,8 +48,7 @@
-
+
@@ -61,11 +61,6 @@
-
-
@@ -137,21 +132,18 @@
form
-
-
+
+
idea.idea.tree
@@ -187,40 +191,47 @@
tree
+
-
-
-
+
-
+
+
+
+
-
+
idea.idea.search
idea.idea
search
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -314,15 +325,15 @@
form
graph,tree
-
+
-
+
-
+
-
-
+
+
Idea's vote
idea.vote
form
diff --git a/addons/idea/wizard/idea_post_vote.py b/addons/idea/wizard/idea_post_vote.py
index c5e6c530334..73d917603a6 100644
--- a/addons/idea/wizard/idea_post_vote.py
+++ b/addons/idea/wizard/idea_post_vote.py
@@ -29,13 +29,36 @@ class idea_post_vote(osv.osv_memory):
_description = "Post vote"
_columns = {
- 'vote': fields.selection([('-1', 'Not Voted'),
- ('0', 'Very Bad'),
- ('25', 'Bad'),
- ('50', 'Normal'),
- ('75', 'Good'),
- ('100', 'Very Good') ], 'Post Vote', required=True)
- }
+ 'vote': fields.selection([('-1', 'Not Voted'),
+ ('0', 'Very Bad'),
+ ('25', 'Bad'),
+ ('50', 'Normal'),
+ ('75', 'Good'),
+ ('100', 'Very Good') ],
+ 'Post Vote', required=True),
+ 'note': fields.text('Description'),
+ }
+
+ def get_default(self, cr, uid, context={}):
+ """
+ This function checks for precondition before wizard executes
+ @param self: The object pointer
+ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks,
+ @param fields: List of fields for default value
+ @param context: A standard dictionary for contextual values
+ """
+ idea_obj = self.pool.get('idea.idea')
+
+ if context.get('active_id'):
+ idea = idea_obj.browse(cr, uid, context.get('active_id'))
+ return idea.my_vote
+ else:
+ return 75
+
+ _defaults = {
+ 'vote': get_default,
+ }
def view_init(self, cr, uid, fields, context=None):
"""
@@ -50,16 +73,12 @@ class idea_post_vote(osv.osv_memory):
for idea in idea_obj.browse(cr, uid, context.get('active_ids', [])):
if idea.state in ['draft', 'close', 'cancel']:
- raise osv.except_osv(_("Warning !"), _("Draft/Accepted/Cancelled \
-ideas Could not be voted"))
+ raise osv.except_osv(_("Warning !"), _("Draft/Accepted/Cancelled ideas Could not be voted"))
if idea.state != 'open':
- raise osv.except_osv(_('Warning !'), _('idea should be in \
-\'Open\' state before vote for that idea.'))
+ raise osv.except_osv(_('Warning !'), _('idea should be in \'Open\' state before vote for that idea.'))
return False
-
def do_vote(self, cr, uid, ids, context):
-
"""
Create idea vote.
@param cr: the current row, from the database cursor,
@@ -67,15 +86,26 @@ ideas Could not be voted"))
@param ids: List of Idea Post vote’s IDs.
@return: Dictionary {}
"""
-
- data = context and context.get('active_id', False) or False
- vote_obj = self.pool.get('idea.vote')
+
+ vote_id = context and context.get('active_id', False) or False
+ vote_pool = self.pool.get('idea.vote')
+ comment_pool = self.pool.get('idea.comment')
for do_vote_obj in self.read(cr, uid, ids):
score = str(do_vote_obj['vote'])
- dic = {'idea_id': data, 'user_id': uid, 'score': score }
-
- vote = vote_obj.create(cr, uid, dic)
+ comment = do_vote_obj['note']
+ vote = {
+ 'idea_id': vote_id,
+ 'user_id': uid,
+ 'score': score
+ }
+ comment = {
+ 'user_id':uid,
+ 'idea_id':vote_id,
+ 'content': comment,
+ }
+ vote = vote_pool.create(cr, uid, vote)
+ comment = comment_pool.create(cr, uid, comment)
return {}
idea_post_vote()
diff --git a/addons/idea/wizard/idea_post_vote_view.xml b/addons/idea/wizard/idea_post_vote_view.xml
index e49e91f5661..aa066cdffd3 100644
--- a/addons/idea/wizard/idea_post_vote_view.xml
+++ b/addons/idea/wizard/idea_post_vote_view.xml
@@ -2,43 +2,38 @@
-
+
-
- idea.post.vote.form
- idea.post.vote
- form
-
-
-
-
+
+ idea.post.vote.form
+ idea.post.vote
+ form
+
+
+
+
-
-
-
- Vote
- idea.post.vote
- form
- tree,form
-
- new
-
-
-
-
-
+
+
+ Vote
+ idea.post.vote
+ form
+ tree,form
+
+ new
+
+