~sergio-incaser/openerp-spain/openerp-spain

« back to all changes in this revision

Viewing changes to extra_addons/radiotv/report/broadcast_compact_report.py

  • Committer: Jordi Esteve
  • Date: 2009-12-14 17:53:50 UTC
  • mfrom: (81.1.90 lp-openerp-spain-5.0)
  • Revision ID: jesteve@zikzakmedia.com-20091214175350-6vzzt3avtsof25a2
Recuperación del estado actual del repositorio de localización española de OpenERP: Aplicación de todos los merges pendientes desde la versión 81 (15-11-2008) hasta la actual (02-12-2009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
##############################################################################
2
 
#
3
 
# Copyright (c) 2007 Zikzakmedia SL (http://www.zikzakmedia.com) All Rights Reserved.
4
 
#
5
 
# WARNING: This program as such is intended to be used by professional
6
 
# programmers who take the whole responsability of assessing all potential
7
 
# consequences resulting from its eventual inadequacies and bugs
8
 
# End users who are looking for a ready-to-use solution with commercial
9
 
# garantees and support are strongly adviced to contract a Free Software
10
 
# Service Company
11
 
#
12
 
# This program is Free Software; you can redistribute it and/or
13
 
# modify it under the terms of the GNU General Public License
14
 
# as published by the Free Software Foundation; either version 2
15
 
# of the License, or (at your option) any later version.
16
 
#
17
 
# This program is distributed in the hope that it will be useful,
18
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
# GNU General Public License for more details.
21
 
#
22
 
# You should have received a copy of the GNU General Public License
23
 
# along with this program; if not, write to the Free Software
24
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
 
#
26
 
##############################################################################
27
 
 
28
 
import pooler
29
 
import time
30
 
from report import report_sxw
31
 
import common
32
 
 
33
 
class broadcast_compact_report(report_sxw.rml_parse):
34
 
 
35
 
        _day_of_week = ('Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte', 'Diumenge')
36
 
 
37
 
        def __init__(self, cr, uid, name, context):
38
 
                super(broadcast_compact_report, self).__init__(cr, uid, name, context)
39
 
                self.localcontext.update({
40
 
                        'time': time,
41
 
                        'obt_channel': self.obt_channel,
42
 
                        'obt_days': self.obt_days,
43
 
                        'obt_broadcasts': self.obt_broadcasts,
44
 
                        'lang': context['lang'],
45
 
                })
46
 
 
47
 
        def obt_channel(self, channel_id):
48
 
                return pooler.get_pool(self.cr.dbname).get('radiotv.channel').browse(self.cr, self.uid, channel_id).name
49
 
 
50
 
        def obt_days(self, d_from, d_to):
51
 
                res = []
52
 
                dfrom = time.strptime(d_from, '%Y-%m-%d')
53
 
                dto = time.strptime(d_to, '%Y-%m-%d')
54
 
                for n in range(int(time.mktime(dfrom)), int(time.mktime(dto))+1, 2*86400):
55
 
                        d1 = time.localtime(n) # Today
56
 
                        d2 = time.localtime(n+86400) # Tomorrow
57
 
                        res.append({'day1': time.strftime('%d-%m-%Y',d1) , 'dow1': self._day_of_week[d1[6]],
58
 
                                                'day2': time.strftime('%d-%m-%Y',d2) , 'dow2': self._day_of_week[d2[6]]})
59
 
                return res
60
 
 
61
 
        def obt_broadcasts(self, channel_id, day, pday=0):
62
 
                res = []
63
 
                pool = pooler.get_pool(self.cr.dbname)
64
 
                day = day[6:]+'-'+day[3:5]+'-'+day[:2]
65
 
 
66
 
                if pday==0:
67
 
                        broadcast_ids = pool.get('radiotv.broadcast').search(self.cr, self.uid, [('channel_id','=',channel_id),('dt_start','>=','%s 00:00:00' % day),('dt_start','<=','%s 23:59:59' % day)])
68
 
                elif pday==1:
69
 
                        broadcast_ids = pool.get('radiotv.broadcast').search(self.cr, self.uid, [('channel_id','=',channel_id),('dt_start','>=','%s 00:00:00' % day),('dt_start','<=','%s 13:59:59' % day)])
70
 
                elif pday==2:
71
 
                        broadcast_ids = pool.get('radiotv.broadcast').search(self.cr, self.uid, [('channel_id','=',channel_id),('dt_start','>=','%s 14:00:00' % day),('dt_start','<=','%s 19:59:59' % day)])
72
 
                else:
73
 
                        broadcast_ids = pool.get('radiotv.broadcast').search(self.cr, self.uid, [('channel_id','=',channel_id),('dt_start','>=','%s 20:00:00' % day),('dt_start','<=','%s 23:59:59' % day)])
74
 
                for bc in pool.get('radiotv.broadcast').browse(self.cr, self.uid, broadcast_ids):
75
 
                        # Insert at the begining of the list to invert the order
76
 
                        res.insert(0, {'time': bc.dt_start[11:13]+':'+bc.dt_start[14:16], 'p_name': bc.program_id.name, 'p_introduction': bc.program_id.introduction, 'description': bc.description,})
77
 
                if not res:
78
 
                        res.insert(0, {'time': '', 'p_name': '', 'p_introduction': '', 'description': '',})
79
 
                #print res
80
 
                return res
81
 
 
82
 
report_sxw.report_sxw('report.radiotv.broadcast.compact.report', 'radiotv.broadcast',
83
 
                'addons/radiotv/report/broadcast_compact_report.rml',
84
 
                parser=broadcast_compact_report, header=False)