1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# school module for OpenERP
5
# Copyright (C) 2010 Tecnoba S.L. (http://www.tecnoba.com)
6
# Pere Ramon Erro Mas <pereerro@tecnoba.com> All Rights Reserved.
8
# This file is a part of school module
10
# school OpenERP module is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 3 of the License, or
13
# (at your option) any later version.
15
# school OpenERP module is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
##############################################################################
26
from osv import osv, fields
27
from datetime import datetime, timedelta
30
class school_room(osv.osv):
32
_inherit = 'school.room'
34
'substitutions' : fields.one2many('school.program_substitutions', 'room_id', string='Program substitutions', help='Program substitutions'),
39
class school_program_substitutions(osv.osv):
40
_name = 'school.program_substitutions'
42
'classe_id': fields.many2one('school.classe','Class',select=1,required=True,ondelete='cascade',),
43
'room_id': fields.many2one('school.room','Room',select=1,required=True,ondelete='cascade',),
44
'sequence': fields.integer('Priority',),
47
'sequence': lambda *a: 1,
49
school_program_substitutions()
51
class school_seance(osv.osv):
52
_name = 'school.seance'
53
_inherit = 'school.seance'
55
def _get_substitutes(self, cr, uid, ids, field_name, arg, context=None):
57
for id in ids: ret[id]=[]
58
query="SELECT s.id,ts.teacher_id FROM school_seance AS s INNER JOIN school_program_substitutions AS ps ON s.room_id=ps.room_id INNER JOIN school_seance AS s1 ON ps.classe_id=s1.classe_id AND s1.date<=s.date AND s1.date_to >= s.date_to INNER JOIN school_teacher_seance AS ts ON ts.seance_id=s1.id WHERE s.id IN %s"
59
cr.execute(query, (tuple(ids),))
60
for (id,teacher_subst_id) in cr.fetchall(): ret[id].append(teacher_subst_id)
63
def _search_by_substitute(self, cr, uid, obj, name,args, context=None):
64
print "school_seance: _search_by_substitute: cr, uid, obj, name,args, context: ",cr, uid, obj, name,args, context
68
'substitutes': fields.function(_get_substitutes, type='many2many', obj='school.teacher', method=True, fnct_search=_search_by_substitute, string="Substitutes",),
73
#class open_seances_to_substitute(wizard.interface):
74
# def _open_seances_to_substitute(self, cr, uid, data, context=None):
75
# if not context: context={}
76
# mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
77
# act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
79
# result = mod_obj._get_id(cr, uid, 'school_extension', 'school_seance_list_act')
80
# id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
81
# result = act_obj.read(cr, uid, [id], [])[0]
84
# SELECT s1.id FROM res_partner AS p
85
# INNER JOIN school_teacher AS t ON p.id=t.partner_id
86
# INNER JOIN school_teacher_seance AS ts ON p.id=ts.teacher_id
87
# INNER JOIN school_seance AS s ON ts.seance_id=s.id
88
# INNER JOIN school_program_substitutions AS ps ON s.classe_id=ps.classe_id
89
# INNER JOIN school_seance AS s1 ON ps.room_id=s1.room_id AND s.date<=s1.date AND
90
# s.date_to >= s1.date_to
93
# cr.execute(query, (uid,))
95
# for (id,) in cr.fetchall(): res_ids.append(id)
96
# result['name'] = 'Substitution seances'
97
# result['domain'] = "[('id','in',%s),('date','>','%s'),('date','<','%s'),('state','!=','closed')]" % (res_ids+[0],(datetime.today()-timedelta(days=7)).strftime('%Y-%m-%d %H:%M:%S'),(datetime.today()+timedelta(days=7)).strftime('%Y-%m-%d %H:%M:%S'))
98
# result.pop('search_view',False)
104
# 'result': {'type': 'action',
105
# 'action': _open_seances_to_substitute,
109
#open_seances_to_substitute('school_seances_to_substitute_ow')
112
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: