1
##############################################################################
3
# Copyright (c) 2007 Zikzakmedia SL (http://www.zikzakmedia.com) All Rights Reserved.
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
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.
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.
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.
26
##############################################################################
30
from report import report_sxw
33
class broadcast_compact_report(report_sxw.rml_parse):
35
_day_of_week = ('Dilluns', 'Dimarts', 'Dimecres', 'Dijous', 'Divendres', 'Dissabte', 'Diumenge')
37
def __init__(self, cr, uid, name, context):
38
super(broadcast_compact_report, self).__init__(cr, uid, name, context)
39
self.localcontext.update({
41
'obt_channel': self.obt_channel,
42
'obt_days': self.obt_days,
43
'obt_broadcasts': self.obt_broadcasts,
44
'lang': context['lang'],
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
50
def obt_days(self, d_from, d_to):
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]]})
61
def obt_broadcasts(self, channel_id, day, pday=0):
63
pool = pooler.get_pool(self.cr.dbname)
64
day = day[6:]+'-'+day[3:5]+'-'+day[:2]
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)])
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)])
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)])
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,})
78
res.insert(0, {'time': '', 'p_name': '', 'p_introduction': '', 'description': '',})
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)