[REF] hr_timesheet: unused piece of code
[odoo/odoo.git] / addons / idea / models / idea.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-Today OpenERP S.A. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import osv
23 from openerp.osv import fields
24
25
26 class IdeaCategory(osv.Model):
27     """ Category of Idea """
28     _name = "idea.category"
29     _description = "Idea Category"
30
31     _order = 'name asc'
32
33     _columns = {
34         'name': fields.char('Category Name', size=64, required=True),
35     }
36
37     _sql_constraints = [
38         ('name', 'unique(name)', 'The name of the category must be unique')
39     ]
40
41
42 class IdeaIdea(osv.Model):
43     """ Model of an Idea """
44     _name = 'idea.idea'
45     _description = 'Propose and Share your Ideas'
46
47     _rec_name = 'name'
48     _order = 'name asc'
49
50     def _get_state_list(self, cr, uid, context=None):
51         return [('draft', 'New'),
52                     ('open', 'In discussion'),
53                     ('close', 'Accepted'),
54                     ('cancel', 'Refused')]
55
56     def _get_color(self, cr, uid, ids, fields, args, context=None):
57         res = dict.fromkeys(ids, 3)
58         for idea in self.browse(cr, uid, ids, context=context):
59             if idea.priority == 'low':
60                 res[idea.id] = 0
61             elif idea.priority == 'high':
62                 res[idea.id] = 7
63         return res
64
65     _columns = {
66         'user_id': fields.many2one('res.users', 'Responsible', required=True),
67         'name': fields.char('Summary', required=True, readonly=True,
68             states={'draft': [('readonly', False)]},
69             oldname='title'),
70         'description': fields.text('Description', required=True,
71             states={'draft': [('readonly', False)]},
72             help='Content of the idea'),
73         'category_ids': fields.many2many('idea.category', string='Tags'),
74         'state': fields.selection(_get_state_list, string='Status', required=True),
75         'priority': fields.selection([('low', 'Low'), ('normal', 'Normal'), ('high', 'High')],
76             string='Priority', required=True),
77         'color': fields.function(_get_color, type='integer', string='Color Index'),
78     }
79
80     _sql_constraints = [
81         ('name', 'unique(name)', 'The name of the idea must be unique')
82     ]
83
84     _defaults = {
85         'user_id': lambda self, cr, uid, ctx=None: uid,
86         'state': lambda self, cr, uid, ctx=None: self._get_state_list(cr, uid, ctx)[0][0],
87         'priority': 'normal',
88     }
89
90     #------------------------------------------------------
91     # Technical stuff
92     #------------------------------------------------------
93
94     def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
95         """ Override read_group to always display all states. """
96         if groupby and groupby[0] == "state":
97             # Default result structure
98             states = self._get_state_list(cr, uid, context=context)
99             read_group_all_states = [{
100                         '__context': {'group_by': groupby[1:]},
101                         '__domain': domain + [('state', '=', state_value)],
102                         'state': state_value,
103                         'state_count': 0,
104                     } for state_value, state_name in states]
105             # Get standard results
106             read_group_res = super(IdeaIdea, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby, lazy)
107             # Update standard results with default results
108             result = []
109             for state_value, state_name in states:
110                 res = filter(lambda x: x['state'] == state_value, read_group_res)
111                 if not res:
112                     res = filter(lambda x: x['state'] == state_value, read_group_all_states)
113                 res[0]['state'] = [state_value, state_name]
114                 result.append(res[0])
115             return result
116         else:
117             return super(IdeaIdea, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy)
118
119     #------------------------------------------------------
120     # Workflow / Actions
121     #------------------------------------------------------
122
123     def idea_set_low_priority(self, cr, uid, ids, context=None):
124         return self.write(cr, uid, ids, {'priority': 'low'}, context=context)
125
126     def idea_set_normal_priority(self, cr, uid, ids, context={}):
127         return self.write(cr, uid, ids, {'priority': 'normal'}, context=context)
128
129     def idea_set_high_priority(self, cr, uid, ids, context={}):
130         return self.write(cr, uid, ids, {'priority': 'high'}, context=context)