1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 MSF, TeMPO Consulting.
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.
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.
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/>.
20
##############################################################################
22
from osv import fields, osv
24
class msf_instance(osv.osv):
25
_name = 'msf.instance'
28
'level': fields.selection([('section', 'Section'),
30
('project', 'Project')], 'Level', required=True),
31
'code': fields.char('Code', size=64, required=True),
32
'mission': fields.char('Mission', size=64),
33
'instance': fields.char('Instance', size=64),
34
'parent_id': fields.many2one('msf.instance', 'Parent', domain=[('level', '!=', 'project'), ('state', '=', 'active')]),
35
'name': fields.char('Name', size=64, required=True),
36
'note': fields.char('Note', size=256),
37
'cost_center_id': fields.many2one('account.analytic.account', 'Cost Center', domain=[('category', '=', 'OC')], required=True),
38
'state': fields.selection([('draft', 'Draft'),
40
('inactive', 'Inactive')], 'State', required=True),
47
def _check_name_code_unicity(self, cr, uid, ids, context=None):
50
for instance in self.browse(cr, uid, ids, context=context):
51
bad_ids = self.search(cr, uid, [('&'),
52
('state', '!=', 'inactive'),
54
('name', '=ilike', instance.name),
55
('code', '=ilike', instance.code)])
56
if len(bad_ids) and len(bad_ids) > 1:
60
def _check_cost_center_unicity(self, cr, uid, ids, context=None):
63
for instance in self.browse(cr, uid, ids, context=context):
64
bad_ids = self.search(cr, uid, [('&'),
65
('state', '!=', 'inactive'),
66
('cost_center_id','=',instance.cost_center_id.id)])
67
if len(bad_ids) and len(bad_ids) > 1:
71
def _check_database_unicity(self, cr, uid, ids, context=None):
74
for instance in self.browse(cr, uid, ids, context=context):
75
bad_ids = self.search(cr, uid, [('&'),
76
('state', '!=', 'inactive'),
78
('instance', '!=', False),
79
('instance', '=', instance.instance)])
80
if len(bad_ids) and len(bad_ids) > 1:
85
(_check_name_code_unicity, 'You cannot have the same code or name than an active instance!', ['code', 'name']),
86
(_check_cost_center_unicity, 'You cannot have the same cost_center than an active instance!', ['cost_center_id']),
87
(_check_database_unicity, 'You cannot have the same database than an active instance!', ['instance']),
90
def name_get(self, cr, user, ids, context=None):
91
result = self.browse(cr, user, ids, context=context)
98
def button_deactivate(self, cr, uid, ids, context=None):
102
self.write(cr, uid, ids, {'state': 'inactive'}, context=context)
106
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: