27
27
from openerp.report import report_sxw
28
28
from report.report_sxw import *
29
from report.report_sxw import _format
30
from report.report_sxw import _float_format
31
from report.report_sxw import _int_format
32
from report.report_sxw import _date_format
33
from report.report_sxw import _dttime_format
34
from report.report_sxw import browse_record_list
35
29
from report.report_sxw import rml_parse
36
30
from lxml import etree
48
37
import openerp.netsvc as netsvc
49
from openerp.osv import osv
50
38
import openerp.tools as tools
53
39
import openerp.netsvc as netsvc
55
41
logger = netsvc.Logger()
72
#~ def search_model(self,cr,uid,model)
73
#~ pool = pooler.get_pool(cr.dbname)
74
#~ print_report_obj =pool.get('print.model.reports')
75
#~ file_data =get_file(cr,uid,report_data)
77
#~ for pt_re in ptre_obj.browse(cr,uid,[('report_id.id','=',report_xml_id)])
78
#~ print 'ID PRINT REPORT', pt_re
80
#~ self.create_single_pdf(cr, uid, ids, data, report_xml, context)
58
#~ def search_model(self,cr,uid,model)
59
#~ pool = pooler.get_pool(cr.dbname)
60
#~ print_report_obj =pool.get('print.model.reports')
61
#~ file_data =get_file(cr,uid,report_data)
63
#~ for pt_re in ptre_obj.browse(cr,uid,[('report_id.id','=',report_xml_id)])
64
#~ print 'ID PRINT REPORT', pt_re
66
#~ self.create_single_pdf(cr, uid, ids, data, report_xml, context)
84
70
class Printer(object):
85
72
def __init__(self, opts={}):
86
73
"""initializes the printer with options"""
133
120
def get_file(cr, uid, report_data):
134
121
file_print = open('mi_archivo.pdf', 'wb+')
135
122
file_print.write(report_data)
137
123
return file_print
220
206
#~ print 'HEADER',self.header
221
207
#~ print 'STORE',self.store
222
208
pool = pooler.get_pool(cr.dbname)
223
company_obj = pool.get('res.company')
225
210
ir_obj = pool.get('ir.actions.report.xml')
226
211
report_xml_ids = ir_obj.search(cr, uid,
234
219
report_type = data.get('report_type', 'pdf')
237
223
def __init__(self, *args, **argv):
238
224
for key, arg in argv.items():
239
225
setattr(self, key, arg)
267
253
#~ be printed or not
268
254
#~ if context.get('allow',False):
269
255
validate_report(cr, uid, result['brw'], fnct_ret[0], data['id'])
270
#~ self.create_ir_print(cr,uid,report_xml.id,data['id'])
256
#~ self.create_ir_print(cr,uid,report_xml.id,data['id'])
273
259
def create_ir_print(self, cr, uid, report_xml_id, id_obj):
277
263
'report_id': report_xml_id,
278
264
'model_id': id_obj,
280
ir_print_id = ir_print_obj.create(cr, uid, res)
266
ir_print_obj.create(cr, uid, res)
282
268
def validate_report(self, cr, uid, report_xml_id, id_obj, context):
283
269
pool = pooler.get_pool(cr.dbname)
361
347
def _add_header_bank(self, rml_dom, bank_header):
362
348
head_dom = etree.XML(bank_header)
363
349
for tag in head_dom:
364
found = rml_dom.find('.//'+tag.tag)
350
found = rml_dom.find('.//' + tag.tag)
365
351
if found is not None and len(found):
366
352
if tag.get('position'):
367
353
found.append(tag)
386
372
aname = eval(attach, {'object': obj, 'time': time})
388
374
if report_xml.attachment_use and aname and context.get('attachment_use', True):
389
aids = pool.get('ir.attachment').search(cr, uid, [('datas_fname', '=', aname+'.pdf'), (
375
aids = pool.get('ir.attachment').search(cr, uid, [('datas_fname', '=', aname + '.pdf'), (
390
376
'res_model', '=', self.table), ('res_id', '=', obj.id)])
392
378
brow_rec = pool.get(
405
391
flag = True # ya que entra solo la primera vez sin attachment
406
name = aname+'.'+result[1]
392
name = aname + '.' + result[1]
407
393
pool.get('ir.attachment').create(cr, uid, {
409
395
'datas': base64.encodestring(result[0]),
417
403
except Exception, e:
420
tb_s = reduce(lambda x, y: x+y, traceback.format_exception(
406
tb_s = reduce(lambda x, y: x + y, traceback.format_exception(
421
407
sys.exc_type, sys.exc_value, sys.exc_traceback))
422
408
netsvc.Logger().notifyChannel(
423
409
'report', netsvc.LOG_ERROR, str(e))