added from extra-addons
[odoo/odoo.git] / addons / auction / report / huissier.py
1 # -*- encoding: utf-8 -*-
2 # -*-encoding: iso8859-1 -*-
3 ##############################################################################
4 #
5 # Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 #                    Fabien Pinckaers <fp@tiny.Be>
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ####################################### i#######################################
30
31 import pooler
32 from osv.osv import osv, orm
33 from report.interface import report_rml
34 #FIXME: use the one from tools and delete the one from report
35 from report.int_to_text import int_to_text
36
37 def toxml(val):
38     return val.replace('&', '&amp;').replace('<','&lt;').replace('>','&gt;').decode('utf-8').encode('latin1', 'replace')
39
40 class report_custom(report_rml):
41     def __init__(self, name, table, tmpl, xsl):
42         report_rml.__init__(self, name, table, tmpl, xsl)
43
44     def create_xml(self,cr, uid, ids, datas, context={}):
45         pool= pooler.get_pool(cr.dbname)
46         lots = pool.get('auction.lots').browse(cr, uid, ids)
47         auction = lots[0].auction_id
48
49         xml = '''<?xml version="1.0" encoding="ISO-8859-1"?>
50 <report>
51     <auction>
52         <name>%s</name>
53         <date-au1>%s</date-au1>
54     </auction>''' % (toxml(auction['name']), toxml(auction['auction1']))
55     
56         i = 0
57         for l in lots:
58 #           l['id_cont'] = str(i)
59             if l['obj_price']==0:
60                 price_french = 'retirĂ©'
61             else:
62                 price_french = int_to_text(int(l['obj_price'] or 0.0))+' eur'
63             i+=1
64             xml += '''  <object>
65         <number>%d</number>
66         <obj_num>%d</obj_num>
67         <lot_desc>%s</lot_desc>
68         <price>%s</price>
69         <obj_price>%s</obj_price>
70     </object>''' % (i, l['obj_num'], toxml(l['name']), price_french, str(l['obj_price'] or '/'))
71         xml += '</report>'
72         
73 #       file('/tmp/terp.xml','wb+').write(xml)
74         return xml
75
76 report_custom('report.flagey.huissier', 'auction.lots', '', 'addons/auction/report/huissier.xsl')
77
78
79 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
80