# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ############################################################################## from openerp.osv import fields, osv import openerp.modules as addons import os import base64 class res_company(osv.osv): _inherit = 'res.company' def get_image(self, img): def _get_dir(): styles_dir = 'cam_reports/static/src/img' adps = addons.module.ad_paths for adp in adps: dir = os.path.join(adp, styles_dir) if os.path.isdir(dir): return dir return False def _get_file_data(filename): try: f = open(filename , 'rb') data = base64.b64encode(f.read()) f.close() return data except: print "Error openening file '%s'." % (filename) return False path = _get_dir() fname = os.path.join(path, img) img_data = _get_file_data(fname) return img_data def _get_rml_header(self, cr, uid, ids, _field_name, _args, context=None): result = dict.fromkeys(ids, False) # Get filename dirname = 'cam_reports/report' adps = addons.module.ad_paths for adp in adps: dir = os.path.join(adp, dirname) if os.path.isdir(dir): break if os.path.isdir(dir): filename = os.path.join(dir, 'page.rml') f = open(filename , 'rb') data = f.read() result = dict.fromkeys(ids, data) return result _columns = { 'rml_header': fields.function(_get_rml_header, type='text', string='RML Header'), }