1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from report.interface import report_rml
25 from report.interface import toxml
27 from osv import osv,orm
28 from time import strptime
29 from xml.dom import minidom
37 from tools import config
41 return s.decode('utf-8')
44 return s.decode('latin')
47 return s.encode('ascii')
53 return s.encode('utf-8')
56 return s.encode('latin')
59 return s.decode('ascii')
64 class auction_catalog(report_rml):
66 def create_xml(self, cr, uid, ids, data, context):
68 xml = self.catalog_xml(cr, uid, ids, data, context)
69 temp=self.post_process_xml_data(cr, uid, xml, context)
72 def catalog_xml(self,cr,uid,ids,data,context,cwid="0"):
73 impl = minidom.getDOMImplementation()
75 doc = impl.createDocument(None, "report", None)
77 catalog=doc.createElement('catalog')
78 doc.documentElement.appendChild(catalog)
86 lot_ids=pooler.get_pool(cr.dbname).get('auction.lots').search(cr, uid, [('auction_id', '=', id)])
87 ab=pooler.get_pool(cr.dbname).get('auction.lots').read(cr,uid,lot_ids,['auction_id','name','lot_num','lot_est1','lot_est2'],context)
88 auction_dates_ids = [x["auction_id"][0] for x in ab]
90 res=pooler.get_pool(cr.dbname).get('auction.dates').read(cr,uid,ids,['name','auction1','auction2'],context)
93 categ = doc.createElement(key)
94 categ.appendChild(doc.createTextNode(_to_decode(res[0]["name"])))
95 catalog.appendChild(categ)
97 #Auctuion Date element
98 categ = doc.createElement("AuctionDate1")
99 categ.appendChild(doc.createTextNode(_to_decode(res[0]['auction1'])))
100 catalog.appendChild(categ)
102 # Action Date 2 element
103 categ = doc.createElement("AuctionDate2")
104 categ.appendChild(doc.createTextNode(_to_decode(res[0]['auction2'])))
105 catalog.appendChild(categ)
108 promo = doc.createElement('promotion1')
110 fp = file(config['addons_path']+'/auction/report/images/flagey_logo.jpg','r')
111 file_data = fp.read()
112 promo.appendChild(doc.createTextNode(base64.encodestring(file_data)))
113 catalog.appendChild(promo)
114 promo = doc.createElement('promotion2')
115 fp = file(config['addons_path']+'/auction/report/images/flagey_logo.jpg','r')
116 file_data = fp.read()
117 promo.appendChild(doc.createTextNode(base64.encodestring(file_data)))
118 catalog.appendChild(promo)
121 products = doc.createElement('products')
122 catalog.appendChild(products)
127 if test.has_key('auction_id'):
128 auction_ids.append(test['auction_id'][0])
129 cr.execute('select * from auction_lots where auction_id IN %s',(tuple(auction_ids),))
130 res = cr.dictfetchall()
132 product =doc.createElement('product')
133 products.appendChild(product)
135 infos = doc.createElement('infos')
136 lines = re.split('<br/>|\n', _to_unicode(cat['obj_desc']))
138 xline = doc.createElement('info')
139 xline.appendChild(doc.createTextNode(_to_decode(line)))
140 infos.appendChild(xline)
141 product.appendChild(infos)
143 lnum = doc.createElement('lot_num')
144 lnum.appendChild(doc.createTextNode(_to_decode(str(cat['lot_num']))))
145 infos.appendChild(lnum)
150 limg = doc.createElement('photo_small')
152 file_name = tempfile.mktemp(prefix='openerp_auction_', suffix='.jpg')
153 fp = file(file_name, 'w')
154 content = base64.decodestring(cat['image'])
157 fp = file(file_name,'r')
158 test_file_name = tempfile.mktemp(prefix='openerp_auction_test_', suffix='.jpg')
159 size = photo_shadow.convert_catalog(fp, test_file_name,110)
160 fp = file(test_file_name)
161 file_data = fp.read()
162 test_data = base64.encodestring(file_data)
164 limg.appendChild(doc.createTextNode(test_data))
165 infos.appendChild(limg)
167 for key in ('lot_est1','lot_est2'):
168 ref2 = doc.createElement(key)
169 ref2.appendChild(doc.createTextNode( _to_decode(str(cat[key] or 0.0))))
170 product.appendChild(ref2)
175 length = length - oldlength
176 ref3 = doc.createElement('newpage')
177 ref3.appendChild(doc.createTextNode( "1" ))
178 product.appendChild(ref3)
180 ref4 = doc.createElement('side')
181 ref4.appendChild(doc.createTextNode( "1" ))
182 product.appendChild(ref4)
185 auction_catalog('report.auction.cat_flagy', 'auction.dates','','addons/auction/report/catalog2.xsl')
187 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: