forked from OCA/project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject_categ_model.py
85 lines (72 loc) · 3.12 KB
/
project_categ_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Daniel Reis
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm
class ProjectProject(orm.Model):
_inherit = 'project.project'
_columns = {
'task_categ_id': fields.many2one(
'project.category', 'Root Category for Tasks'),
}
class ProjectCategory(orm.Model):
_inherit = 'project.category'
def _name_get(self, cr, uid, ids, context=None):
res = []
rows = self.read(cr, uid, ids, ['name', 'parent_id'], context=context)
for row in rows:
parent = row['parent_id'] and (row['parent_id'][1] + ' / ') or ''
res.append((row['id'], parent + row['name']))
return res
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
return dict(self._name_get(cr, uid, ids, context=context))
_columns = {
'parent_id': fields.many2one(
'project.category', 'Parent Category', select=True),
'child_ids': fields.one2many(
'project.category', 'parent_id', 'Child Categories'),
'complete_name': fields.function(
_name_get_fnc, method=True, type='char', string='Name'),
'code': fields.char('Code', size=10),
}
_order = 'parent_id,name'
class ProjectTask(orm.Model):
_inherit = 'project.task'
def onchange_project(self, cr, uid, id, project_id, context=None):
# on_change is necessary to populate fields on create, before saving
try:
res = super(ProjectTask, self).onchange_project(
cr, uid, id, project_id, context) or {}
except AttributeError:
res = {}
if project_id:
obj = self.pool.get('project.project').browse(
cr, uid, project_id, context=context)
if obj.task_categ_id:
res.setdefault('value', {})
res['value']['task_categ_id'] = obj.task_categ_id.id
return res
_columns = {
'task_categ_id': fields.related(
'project_id', 'task_categ_id', string="Category Root",
type='many2one', relation='project.category', readonly=True),
'categ_ids': fields.many2many(
'project.category', string='Tags',
domain="[('id','child_of',task_categ_id)"
",('id','!=',task_categ_id)]"),
}