~school-dev-team/school-base-openerp-module/v.3

« back to all changes in this revision

Viewing changes to school_attendance/school_substitute.py

  • Committer: Pere Erro
  • Date: 2013-03-09 23:37:13 UTC
  • Revision ID: pereerro@terra.es-20130309233713-5whtmdj6dg8ix06o
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
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.
 
7
#
 
8
#    This file is a part of school module
 
9
#
 
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.
 
14
#
 
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.
 
19
#
 
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/>.
 
22
#
 
23
##############################################################################
 
24
 
 
25
 
 
26
from osv import osv, fields
 
27
from datetime import datetime, timedelta
 
28
import pooler
 
29
 
 
30
class school_room(osv.osv):
 
31
    _name = 'school.room'
 
32
    _inherit = 'school.room'
 
33
    _columns = {
 
34
        'substitutions' : fields.one2many('school.program_substitutions', 'room_id', string='Program substitutions', help='Program substitutions'),
 
35
    }
 
36
school_room()
 
37
 
 
38
 
 
39
class school_program_substitutions(osv.osv):
 
40
    _name = 'school.program_substitutions'
 
41
    _columns = {
 
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',),
 
45
    }
 
46
    _defaults = {
 
47
        'sequence': lambda *a: 1,
 
48
    }
 
49
school_program_substitutions()
 
50
 
 
51
class school_seance(osv.osv):
 
52
    _name = 'school.seance'
 
53
    _inherit = 'school.seance'
 
54
 
 
55
    def _get_substitutes(self, cr, uid, ids, field_name, arg, context=None):
 
56
        ret={}
 
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)
 
61
        return ret
 
62
 
 
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
 
65
        return []
 
66
 
 
67
    _columns = {
 
68
        'substitutes': fields.function(_get_substitutes, type='many2many', obj='school.teacher', method=True, fnct_search=_search_by_substitute, string="Substitutes",),
 
69
    }
 
70
 
 
71
school_seance()
 
72
 
 
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')
 
78
#
 
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]
 
82
#
 
83
#        query="""
 
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
 
91
#        WHERE p.user_id=%s
 
92
#        """
 
93
#        cr.execute(query, (uid,))
 
94
#        res_ids=[]
 
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)
 
99
#        return result
 
100
#
 
101
#    states = {
 
102
#          'init': {
 
103
#                'actions': [],
 
104
#                'result': {'type': 'action',
 
105
#                           'action': _open_seances_to_substitute,
 
106
#                           'state':'end'}
 
107
#          },
 
108
#    }
 
109
#open_seances_to_substitute('school_seances_to_substitute_ow')
 
110
 
 
111
 
 
112
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: