From 7a72294603d0c3501b5c3d7845165f2fcdd48330 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Thu, 7 Jun 2012 19:51:58 +0200 Subject: [PATCH] [IMP] improved idea module bzr revid: fp@tinyerp.com-20120607175158-pspvowjp3hnbn09m --- addons/crm/crm_lead.py | 2 +- addons/idea/__init__.py | 3 - addons/idea/__openerp__.py | 6 +- addons/idea/idea.py | 336 ++------------------- addons/idea/idea_data.xml | 27 +- addons/idea/idea_view.xml | 274 ++--------------- addons/idea/report/__init__.py | 23 -- addons/idea/report/report_vote.py | 78 ----- addons/idea/report/report_vote_view.xml | 89 ------ addons/idea/security/idea_security.xml | 6 - addons/idea/security/ir.model.access.csv | 4 - addons/idea/test/test_idea.yml | 42 --- addons/idea/wizard/__init__.py | 24 -- addons/idea/wizard/idea_post_vote.py | 178 ----------- addons/idea/wizard/idea_post_vote_view.xml | 69 ----- 15 files changed, 51 insertions(+), 1110 deletions(-) delete mode 100644 addons/idea/report/__init__.py delete mode 100644 addons/idea/report/report_vote.py delete mode 100644 addons/idea/report/report_vote_view.xml delete mode 100644 addons/idea/test/test_idea.yml delete mode 100644 addons/idea/wizard/__init__.py delete mode 100644 addons/idea/wizard/idea_post_vote.py delete mode 100644 addons/idea/wizard/idea_post_vote_view.xml diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 82bc50eafea..addd26785a1 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -910,7 +910,7 @@ class crm_lead(base_stage, osv.osv): if action == 'log': prefix = 'Logged' else: prefix = 'Scheduled' message = _("%s a call for the %s.") % (prefix, phonecall.date) - return self. message_append_note(cr, uid, ids, body=message, context=context) + return self.message_append_note(cr, uid, ids, body=message, context=context) def _lead_set_partner_send_note(self, cr, uid, ids, context=None): for lead in self.browse(cr, uid, ids, context=context): diff --git a/addons/idea/__init__.py b/addons/idea/__init__.py index 3c359952022..e6f7333e055 100644 --- a/addons/idea/__init__.py +++ b/addons/idea/__init__.py @@ -20,7 +20,4 @@ ############################################################################## import idea -import wizard -import report -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/idea/__openerp__.py b/addons/idea/__openerp__.py index 8f65ea2eaa0..145f7cd185f 100644 --- a/addons/idea/__openerp__.py +++ b/addons/idea/__openerp__.py @@ -40,19 +40,15 @@ Once installed, check the menu 'Ideas' in the 'Tools' main menu.""", 'update_xml': [ 'security/idea_security.xml', 'security/ir.model.access.csv', - 'wizard/idea_post_vote_view.xml', 'idea_view.xml', 'idea_workflow.xml', - 'report/report_vote_view.xml', ], 'demo_xml': [ "idea_data.xml" ], 'test':[ - 'test/test_idea.yml' ], 'installable': True, - 'certificate': '0071515601309', - 'images': ['images/1_ideas.jpeg','images/2_idea_categories.jpeg','images/3_vote_idea.jpeg'], + 'images': [], } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/idea/idea.py b/addons/idea/idea.py index 660b54bd440..cc2c11bdd8a 100644 --- a/addons/idea/idea.py +++ b/addons/idea/idea.py @@ -30,349 +30,59 @@ DefaultVoteValue = '50' class idea_category(osv.osv): """ Category of Idea """ - - def name_get(self, cr, uid, ids, context=None): - if not len(ids): - return [] - reads = self.read(cr, uid, ids, ['name','parent_id'], context=context) - res = [] - for record in reads: - name = record['name'] - if record['parent_id']: - name = record['parent_id'][1]+' / '+name - res.append((record['id'], name)) - return res - - def _categ_name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): - res = self.name_get(cr, uid, ids, context=context) - return dict(res) - _name = "idea.category" _description = "Idea Category" - _columns = { - 'name': fields.char('Category', size=64, required=True), - 'complete_name': fields.function(_categ_name_get_fnc, type="char", string='Name'), - 'summary': fields.text('Summary'), - 'parent_id': fields.many2one('idea.category', 'Parent Categories', ondelete='set null', select=True), - 'child_ids': fields.one2many('idea.category', 'parent_id', 'Child Categories'), - 'visibility':fields.boolean('Open Idea?', required=False, help="If True creator of the idea will be visible to others"), + 'name': fields.char('Category Name', size=64, required=True), } _sql_constraints = [ - ('name', 'unique(parent_id,name)', 'The name of the category must be unique' ) + ('name', 'unique(name)', 'The name of the category must be unique' ) ] - _order = 'parent_id,name asc' - - _constraints = [ - (osv.osv._check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id']) - ] - + _order = 'name asc' idea_category() class idea_idea(osv.osv): """ Idea """ _name = 'idea.idea' - _rec_name = 'name' - - def _vote_avg_compute(self, cr, uid, ids, name, arg, context=None): - - """ 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 """ - - if not ids: - 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 IN %s - GROUP BY i.id - """ - - cr.execute(sql, (tuple(ids),)) - return dict(cr.fetchall()) - - 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 """ - - if not ids: - 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 IN %s - GROUP BY i.id - """ - - cr.execute(sql, (tuple(ids),)) - return dict(cr.fetchall()) - - 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 """ - - if not ids: - 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 IN %s - GROUP BY i.id - """ - - cr.execute(sql, (tuple(ids),)) - return dict(cr.fetchall()) - - def _vote_read(self, cr, uid, ids, name, arg, context=None): - - """ 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 """ - - 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)]) - vote_obj_id = vote_obj.browse(cr, uid, votes_ids, context=context) - - for vote in vote_obj_id: - res[vote.idea_id.id] = vote.score - return res - - def _vote_save(self, cr, uid, id, field_name, field_value, arg, context=None): - - """ 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 """ - - vote_obj = self.pool.get('idea.vote') - vote = vote_obj.search(cr, uid, [('idea_id', '=', id), ('user_id', '=', uid)]) - textual_value = str(field_value) - - if vote: - if int(field_value) >= 0: - vote_obj.write(cr, uid, vote, {'score': textual_value }) - else: - vote_obj.unlink(cr, uid, vote) - else: - if int(field_value) >= 0: - vote_obj.create(cr, uid, {'idea_id': id, 'user_id': uid, 'score': textual_value }) - + _inherit = ['mail.thread'] _columns = { - 'user_id': fields.many2one('res.users', 'Creator', required=True, readonly=True), + 'create_uid': fields.many2one('res.users', 'Creator', required=True, readonly=True), 'name': fields.char('Idea Summary', size=64, required=True, readonly=True, oldname='title', states={'draft':[('readonly',False)]}), 'description': fields.text('Description', help='Content of the idea', readonly=True, states={'draft':[('readonly',False)]}), - 'comment_ids': fields.one2many('idea.comment', 'idea_id', 'Comments'), - 'created_date': fields.datetime('Creation date', readonly=True), - 'open_date': fields.datetime('Open date', readonly=True, help="Date when an idea opened"), - 'vote_ids': fields.one2many('idea.vote', 'idea_id', 'Vote'), - 'my_vote': fields.function(_vote_read, fnct_inv = _vote_save, string="My Vote", type="selection", selection=VoteValues), - 'vote_avg': fields.function(_vote_avg_compute, string="Average Score", type="float"), - 'count_votes': fields.function(_vote_count, string="Count of votes", type="integer"), - 'count_comments': fields.function(_comment_count, string="Count of comments", type="integer"), - 'category_id': fields.many2one('idea.category', 'Category', required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'category_ids': fields.many2many('idea.category', 'Tags', readonly=True, states={'draft':[('readonly',False)]}), 'state': fields.selection([('draft', 'New'), - ('open', 'Opened'), + ('open', 'Accepted'), ('cancel', 'Refused'), - ('close', 'Accepted')], - 'Status', 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), - 'vote_limit': fields.integer('Maximum Vote per User', - help="Set to one if you require only one Vote per user"), + ('close', 'Done')], + 'Status', readonly=True + ) } - + _sql_constraints = [ + ('name', 'unique(name)', 'The name of the idea must be unique' ) + ] _defaults = { - 'user_id': lambda self,cr,uid,context: uid, - 'my_vote': lambda *a: '-1', 'state': lambda *a: 'draft', - 'vote_limit': lambda * a: 1, - 'created_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), - 'visibility': lambda *a: True, } - _order = 'id desc' + _order = 'name asc' - def create(self, cr, user, vals, context=None): - """ - 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=context) - visibility = category.visibility - - vals.update({ - 'visibility':visibility - }) - - res_id = super(idea_idea, self).create(cr, user, vals, context=context) - return res_id - - def copy(self, cr, uid, id, default={}, context=None): - """ - 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 - - @return: Returns the id of the new record - """ - - default.update({ - 'comment_ids':False, - 'vote_ids':False, - 'stat_vote_ids':False - - }) - res_id = super(idea_idea, self).copy(cr, uid, id, default, context=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], context=context).state - - if vals.get('my_vote', False): - if vals.get('state', state) != 'open': - raise osv.except_osv(_("Warning !"), _("You can not vote on a Draft/Accepted/Cancelled ideas.")) - - res = super(idea_idea, self).write(cr, user, ids, vals, context=context) - return res - - def idea_cancel(self, cr, uid, ids): + def idea_cancel(self, cr, uid, ids, context={}): self.write(cr, uid, ids, { 'state': 'cancel' }) + self.message_append_note(cr, uid, ids, body=_('Idea canceled.'), context=context) return True - def idea_open(self, cr, uid, ids): - self.write(cr, uid, ids, { 'state': 'open' ,'open_date': time.strftime('%Y-%m-%d %H:%M:%S')}) + def idea_open(self, cr, uid, ids, context={}): + self.write(cr, uid, ids, { 'state': 'open'}) + self.message_append_note(cr, uid, ids, body=_('Idea accepted.'), context=context) return True - def idea_close(self, cr, uid, ids): + def idea_close(self, cr, uid, ids, context={}): + self.message_append_note(cr, uid, ids, body=_('Idea done.'), context=context) self.write(cr, uid, ids, { 'state': 'close' }) return True - def idea_draft(self, cr, uid, ids): + def idea_draft(self, cr, uid, ids, context={}): + self.message_append_note(cr, uid, ids, body=_('Idea reset to draft.'), context=context) self.write(cr, uid, ids, { 'state': 'draft' }) return True idea_idea() - -class idea_comment(osv.osv): - """ Apply Idea for Comment """ - - _name = 'idea.comment' - _description = 'Comment' - _rec_name = 'content' - - _columns = { - '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), - } - - _defaults = { - 'user_id': lambda self, cr, uid, context: uid - } - - _order = 'id desc' - -idea_comment() - - -class idea_vote(osv.osv): - """ Apply Idea for Vote """ - - _name = 'idea.vote' - _description = 'Idea Vote' - _rec_name = 'score' - - _columns = { - 'user_id': fields.many2one('res.users', 'User', readonly="True"), - '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"), - } - _defaults = { - 'score': lambda *a: DefaultVoteValue, - 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), - } - -idea_vote() - -class idea_vote_stat(osv.osv): - """ Idea votes Statistics """ - - _name = 'idea.vote.stat' - _description = 'Idea Votes Statistics' - _auto = False - _rec_name = 'idea_id' - - _columns = { - 'idea_id': fields.many2one('idea.idea', 'Idea', readonly=True), - 'score': fields.selection(VoteValues, 'Score', readonly=True), - 'nbr': fields.integer('Number of Votes', readonly=True), - } - - def init(self, cr): - """ - initialize the sql view for the stats - - cr -- the cursor - """ - cr.execute(""" - CREATE OR REPLACE VIEW idea_vote_stat AS ( - SELECT - MIN(v.id) AS id, - i.id AS idea_id, - v.score, - COUNT(1) AS nbr - FROM - idea_vote v - LEFT JOIN idea_idea i ON (v.idea_id = i.id) - GROUP BY - i.id, v.score, i.id ) - """) - -idea_vote_stat() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/idea/idea_data.xml b/addons/idea/idea_data.xml index b1297442793..d63eb907ef8 100644 --- a/addons/idea/idea_data.xml +++ b/addons/idea/idea_data.xml @@ -2,31 +2,14 @@ - - General - General Ideas - True + + Sales + + + Organization - Technical - Technical Ideas - True - - - - TODO: Need to put a good idea on OpenERP - TODO: Need to put a good idea on OpenERP - - True - - - - Technical presentation for 1 hours in every day - Technical presentation for 1 hours in every day - - True - open diff --git a/addons/idea/idea_view.xml b/addons/idea/idea_view.xml index ffcacb3a8f6..527369093ef 100644 --- a/addons/idea/idea_view.xml +++ b/addons/idea/idea_view.xml @@ -8,14 +8,7 @@ search - - - - - - - - + @@ -26,14 +19,10 @@ idea.category form -
- + + - - - -
@@ -43,11 +32,10 @@ idea.category.tree idea.category tree - child_ids + - - + @@ -70,95 +58,6 @@ - - - - Ideas by Categories - idea.category - tree - [('parent_id','=',False)] - - - - - - - - - - Open Ideas - idea.idea - form - tree,form - [('state','=','open'),('category_id','child_of',[active_id])] - - - - - - Ideas - - - - - - - idea.vote.tree - idea.vote - tree - - - - - - - - - - - - - - idea.vote.form - idea.vote - form - -
- - - - - - - - - -
- - - - - idea.vote.search - idea.vote - search - - - - - - - - - - - - - - - - - - @@ -173,66 +72,17 @@