def create_img(self, cr, uid, employee_id, img_data, finger, context=None): fp = self.pool.get('finger.print') compare = fp.fingerprint_search(cr, uid, img_data, finger) if compare: return False save_path = addons.get_module_resource( 'GDS', 'static/src/img/emp_finger_print') img_name = str(employee_id) + "_" + finger + ".png" fileTosave = save_path + "/" + img_name fh = open(fileTosave, "wb") fh.write(img_data.decode('base64')) fh.close() field = finger + '_lc' field_val = '/GDS/static/src/img/emp_finger_print/' + img_name self.pool.get('hr.employee').write(cr, uid, [employee_id], {field: field_val}) xyt_name = addons.get_module_resource( 'GDS', 'static/src/img/xyt_finger_print') + "/" + str( employee_id) + "_" + finger shell.execute('mindtct', fileTosave, xyt_name) self.clean('xyt_finger_print/*.brw', 'xyt_finger_print/*.dm', 'xyt_finger_print/*.hcm', 'xyt_finger_print/*.lcm', 'xyt_finger_print/*.lfm', 'xyt_finger_print/*.qm', 'xyt_finger_print/*.min') return img_name
def upload_report(self, cr, uid, report_id, file_sxw, file_type, context=None): """ Untested function """ pool = pooler.get_pool(cr.dbname) sxwval = StringIO(base64.decodestring(file_sxw)) if file_type == "sxw": fp = open( addons.get_module_resource("base_report_designer", "openerp_sxw2rml", "normalized_oo2rml.xsl"), "rb" ) if file_type == "odt": fp = open( addons.get_module_resource("base_report_designer", "openerp_sxw2rml", "normalized_odt2rml.xsl"), "rb" ) report = pool.get("ir.actions.report.xml").write( cr, uid, [report_id], { "report_sxw_content": base64.decodestring(file_sxw), "report_rml_content": str(sxw2rml(sxwval, xsl=fp.read())), }, ) pool.get("ir.actions.report.xml").register_all(cr) return True
def upload_report(self, cr, uid, report_id, file_sxw, file_type, context=None): ''' Untested function ''' pool = pooler.get_pool(cr.dbname) sxwval = StringIO(base64.decodestring(file_sxw)) if file_type == 'sxw': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_oo2rml.xsl'), 'rb') if file_type == 'odt': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_odt2rml.xsl'), 'rb') report = pool.get('ir.actions.report.xml').write( cr, uid, [report_id], { 'report_sxw_content': base64.decodestring(file_sxw), 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())), }) # FIXME: this should be moved to an override of the ir.actions.report_xml.create() method cr.commit() pool.get('ir.actions.report.xml').register_all(cr) openerp.modules.registry.RegistryManager.signal_registry_change( cr.dbname) return True
def upload_report(self, cr, uid, report_id, file_sxw, file_type, context=None): ''' Untested function ''' pool = pooler.get_pool(cr.dbname) sxwval = StringIO(base64.decodestring(file_sxw)) if file_type == 'sxw': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_oo2rml.xsl'), 'rb') if file_type == 'odt': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_odt2rml.xsl'), 'rb') report = pool.get('ir.actions.report.xml').write( cr, uid, [report_id], { 'report_sxw_content': base64.decodestring(file_sxw), 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())), }) pool.get('ir.actions.report.xml').register_all(cr) return True
def sxwtorml(self, cr, uid, file_sxw, file_type): ''' The use of this function is to get rml file from sxw file. ''' sxwval = StringIO(base64.decodestring(file_sxw)) if file_type=='sxw': fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb') if file_type=='odt': fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb') return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
def init(self, cr): sql_path = get_module_resource("budget_analysis", "sql", "function_c2c_xrate_conversion.sql") with file(sql_path) as sql_file: cr.execute(sql_file.read()) sql_path = get_module_resource("budget_analysis", "sql", "view_c2c_ytd_dpt.sql") with file(sql_path) as sql_file: cr.execute(sql_file.read()) sql_path = get_module_resource("budget_analysis", "sql", "view_c2c_budget_analytic.sql") with file(sql_path) as sql_file: cr.execute(sql_file.read())
def sxwtorml(self, cr, uid, file_sxw, file_type): """ The use of this function is to get rml file from sxw file. """ sxwval = StringIO(base64.decodestring(file_sxw)) if file_type == "sxw": fp = open( addons.get_module_resource("base_report_designer", "openerp_sxw2rml", "normalized_oo2rml.xsl"), "rb" ) if file_type == "odt": fp = open( addons.get_module_resource("base_report_designer", "openerp_sxw2rml", "normalized_odt2rml.xsl"), "rb" ) return {"report_rml_content": str(sxw2rml(sxwval, xsl=fp.read()))}
def _get_desc(self, cr, uid, ids, field_name=None, arg=None, context=None): res = dict.fromkeys(ids, '') for module in self.browse(cr, uid, ids, context=context): path = addons.get_module_resource(module.name, 'static/description/index.html') if path: with tools.file_open(path, 'rb') as desc_file: doc = desc_file.read() html = lxml.html.document_fromstring(doc) for element, attribute, link, pos in html.iterlinks(): if element.get('src') and not '//' in element.get( 'src') and not 'static/' in element.get('src'): element.set( 'src', "/%s/static/description/%s" % (module.name, element.get('src'))) res[module.id] = lxml.html.tostring(html) else: overrides = dict(embed_stylesheet=False, doctitle_xform=False, output_encoding='unicode') output = publish_string(source=module.description, settings_overrides=overrides, writer=MyWriter()) res[module.id] = output return res
def _get_icon(self, cr, uid, ids, name, value, args, context=None): if context is None: context = {} res = {} src = 'tg_box/static/src/img/fileext/' for obj in self.browse(cr, uid, ids, context=context): if obj.datas_fname: ext = os.path.splitext(obj.datas_fname)[1][1:] ext = ext.lower() icon_filename = "%s.png" % (ext) else: icon_filename = "web.png" path = addons.get_module_resource('tg_box', 'static', 'src', 'img', 'fileext', icon_filename) if path: icon_path = "%s%s" % (src, icon_filename) else: icon_path = "%s_blank.png" % (src) image_file = tools.file_open(icon_path, 'rb') try: res[obj.id] = image_file.read().encode('base64') finally: image_file.close() return res
def pdf_fill(orig_pdf,vals): #vals = decode_vals(vals) orig_pdf_abs = os.path.join(os.getcwd(),orig_pdf) tmp = tempfile.mkstemp(".pdf")[1] print "=========" print 'orig_pdf = ',orig_pdf print "=========" print 'vals = ',vals print "=========" print 'orig_pdf_abs = ',orig_pdf_abs print "=========" tools.pdf_utils.fill_pdf(addons.get_module_resource('ad_account_indonesia','report','pdf','spt_masa_ppn_1111a.pdf'), tmp, vals) #tools.pdf_utils.fill_pdf(orig_pdf, tmp, vals) print 'rrrrrrrrrrrrrrrrrrr' try: tools.pdf_utils.fill_pdf(orig_pdf, tmp, vals) with open(tmp, "r") as ofile: self.obj = external_pdf(ofile.read()) finally: try: os.remove(tmp_file) except: pass # nothing to do print "=========" print "aaaaa" print "=========" self.obj.render() pdf = self.obj.pdf return pdf
def init(self, cr): sql_path = get_module_resource('budget_analysis', 'sql', 'function_c2c_xrate_conversion.sql') with file(sql_path) as sql_file: cr.execute(sql_file.read()) sql_path = get_module_resource('budget_analysis', 'sql', 'view_c2c_ytd_dpt.sql') with file(sql_path) as sql_file: cr.execute(sql_file.read()) sql_path = get_module_resource('budget_analysis', 'sql', 'view_c2c_budget_analytic.sql') with file(sql_path) as sql_file: cr.execute(sql_file.read())
def get_plugin_zipfile(self, cr, uid, context=None): def addFolderToZip(myZipFile, folder, path): # http://stackoverflow.com/questions/458436/adding-folders-to-a- # zip-file-using-python/459419#459419 #convert path to ascii for ZipFile Method folder = folder.encode('ascii') for file in glob.glob(folder + "/*"): relpath = os.path.join(path, os.path.basename(file)) if os.path.isfile(file): myZipFile.write(file, relpath, zipfile.ZIP_DEFLATED) elif os.path.isdir(file): addFolderToZip(myZipFile, file, relpath) # http://stackoverflow.com/questions/3610221/how-to-create-an-in- # memory-zip-file-with-directories-without-touching-the-disk inMemoryOutputFile = StringIO() zipFile = zipfile.ZipFile(inMemoryOutputFile, 'w') addFolderToZip( zipFile, get_module_resource('report_aeroo_ooo_plugin', 'plugin'), '') zipFile.close() inMemoryOutputFile.seek(0) data = base64.encodestring(inMemoryOutputFile.getvalue()) if context and context.get('bin_size'): return human_size(len(data)) return base64.encodestring(inMemoryOutputFile.getvalue())
def delCopyOfFiles(self, srcfile): path = addons.get_module_resource('seedoo_protocollo', 'tests', 'data', srcfile) currDir = os.path.dirname(path) for fname in glob.glob(currDir + '/*.' + srcfile.split('.')[1]): if os.path.basename(fname) != srcfile: os.remove(fname)
def getAttacment(self, name): path = addons.get_module_resource('l10n_it_einvoice_out', 'tests', 'data', 'attach_base.pdf') currDir = os.path.dirname(path) new_file = '%s/%s' % (currDir, name) shutil.copyfile(path, new_file) return self.getFilePath(new_file)
def clean(self, *files): save_path = addons.get_module_resource('GDS', 'static/src/img/') for i in files: os.popen(''' rm %s%s ''' % (save_path, i))
def default_get(self, cr, uid, fields, context=None): data = super(base_report_designer_installer, self).default_get(cr, uid, fields, context=context) plugin_file = open( addons.get_module_resource("base_report_designer", "plugin", "openerp_report_designer.zip"), "rb" ) data["plugin_file"] = base64.encodestring(plugin_file.read()) return data
def default_get(self, cr, uid, fields_list=None, context=None): """ Default value to the config_logo field """ defaults = super(split_invoice_config, self).default_get(cr, uid, fields_list=fields_list, context=context) logo = open(addons.get_module_resource('l10n_ve_split_invoice', 'images', 'puente-maracaibo.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def sxwtorml(self, cr, uid, file_sxw, file_type): ''' The use of this function is to get rml file from sxw file. ''' sxwval = StringIO(base64.decodestring(file_sxw)) if file_type == 'sxw': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_oo2rml.xsl'), 'rb') if file_type == 'odt': fp = open( addons.get_module_resource('base_report_designer', 'openerp_sxw2rml', 'normalized_odt2rml.xsl'), 'rb') return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
def default_get(self, cr, uid, fields, context=None): """ Return information relating to the withholding regime """ data = super(wh_vat_installer, self).default_get(cr, uid, fields, context=context) gaceta = open(addons.get_module_resource('l10n_ve_withholding_iva','files', 'RegimendeRetencionesdelIVA.odt'),'rb') data['gaceta'] = base64.encodestring(gaceta.read()) return data
def delCopyOfFiles(self, srcfile): path = addons.get_module_resource('seedoo_protocollo_zip', 'tests', 'data', srcfile) currDir = os.path.dirname(path) for fname in glob.glob(currDir + '/*.' + srcfile.split('.')[1]): if os.path.basename(fname) != srcfile: os.remove(fname)
def default_get(self, cr, uid, fields_list=None, context=None): """ Default value config_logo field """ defaults = super(wh_islr_config, self).default_get(cr, uid, fields_list=fields_list, context=context) logo = open(addons.get_module_resource('l10n_ve_withholding_islr', 'images', 'playa-medina.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def bvr_absolute_path(self): """Will get the ocrb police absolute path""" path = addons.get_module_resource( 'l10n_ch_payment_slip', 'report', 'bvr1.jpg' ) return path
def default_get(self, cr, uid, fields, context=None): data = super(base_report_designer_installer, self).default_get(cr, uid, fields, context=context) plugin_file = open( addons.get_module_resource('base_report_designer', 'plugin', 'openerp_report_designer.zip'), 'rb') data['plugin_file'] = base64.encodestring(plugin_file.read()) return data
def police_absolute_path(self, inner_path): """Will get the ocrb police absolute path""" path = addons.get_module_resource( 'l10n_ch_payment_slip', 'report', inner_path ) return path
def getFile(self, filename): path = addons.get_module_resource('l10n_it_fatturapa_in', 'tests', 'data', filename) with open(path) as test_data: with tempfile.TemporaryFile() as out: base64.encode(test_data, out) out.seek(0) return path, out.read()
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): """generate the PDF""" if context is None: context={} htmls = [] if report_xml.report_type != 'webkit': return super(HeaderFooterTextWebKitParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context) self.parser_instance = self.parser(cursor, uid, self.name2, context=context) self.pool = pooler.get_pool(cursor.dbname) objs = self.getObjects(cursor, uid, ids, context) self.parser_instance.set_context(objs, data, ids, report_xml.report_type) template = False if report_xml.report_file: path = addons.get_module_resource(*report_xml.report_file.split(os.path.sep)) if os.path.exists(path): template = file(path).read() if not template and report_xml.report_webkit_data: template = report_xml.report_webkit_data if not template: raise except_osv(_('Error!'), _('Webkit Report template not found !')) header = report_xml.webkit_header.html footer = report_xml.webkit_header.footer_html if not header and report_xml.header: raise except_osv( _('No header defined for this Webkit report!'), _('Please set a header in company settings') ) css = report_xml.webkit_header.css if not css: css = '' user = self.pool.get('res.users').browse(cursor, uid, uid) #default_filters=['unicode', 'entity'] can be used to set global filter template = unicode(template) body_mako_tpl = mako_template(template) helper = WebKitHelper(cursor, uid, report_xml.id, context) if report_xml.precise_mode: for obj in objs: self.parser_instance.localcontext['objects'] = [obj] try: html = body_mako_tpl.render(helper=helper, css=css, _=self.translate_call, **self.parser_instance.localcontext) htmls.append(html) except Exception, e: msg = exceptions.text_error_template().render() _logger.error(msg) raise except_osv(_('Webkit render'), msg)
def get_file(self, filename): """Retrive file from test data""" path = addons.get_module_resource('async_move_line_importer', 'tests', 'data', filename) with open(path) as test_data: with tempfile.TemporaryFile() as out: base64.encode(test_data, out) out.seek(0) return out.read()
def default_get(self, fields_list): """ Get default company if any, and the various other fields from the company's fields """ defaults = super(WhIvaConfig, self).default_get(fields_list) # Set Vauxoo logo on config Window. logo = open(addons.get_module_resource("l10n_ve_withholding_iva", "images", "angelfalls.jpg"), "rb") defaults["config_logo"] = base64.encodestring(logo.read()) return defaults
def default_get(self, cr, uid, fields_list=None, context=None): if context is None: context = {} defaults = super(facturae_config, self).default_get( cr, uid, fields_list=fields_list, context=context) logo = open(addons.get_module_resource( 'l10n_mx_facturae', 'images', 'piramide_azteca.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def process_bio(self, cr, uid, emp_id, img_data, img_name, finger, payment_id, state, model_name="payment.record", context={}): ''' print "########### state " , state print "########### model " , model_name print "########### payment_id " , payment_id self.create_img(cr , uid , img_data , img_name ) ref_data = self.read(cr , uid, emp_id,[finger])[finger] self.create_img(cr , uid , ref_data , 'ref.png' )''' save_path = addons.get_module_resource( 'GDS', 'static/src/img/emp_finger_print') img_name = str(emp_id) + "_" + "new.png" fileTosave = save_path + "/" + img_name fh = open(fileTosave, "wb") fh.write(img_data.decode('base64')) fh.close() xyt_name = addons.get_module_resource( 'GDS', 'static/src/img/xyt_finger_print') + "/new" shell.execute('mindtct', fileTosave, xyt_name) new_xyt = xyt_name + '.xyt' emp_xyt = addons.get_module_resource( 'GDS', 'static/src/img/xyt_finger_print') + "/" + str( emp_id) + "_" + finger + ".xyt" degree = shell.execute('bozorth', emp_xyt, new_xyt) try: degree = float(degree) if degree >= 30: self.pool.get(model_name).write(cr, uid, [payment_id], {'state': state}) return 0 except: return 1 return 1
def get_file(self, filename): """Retrieve file from test data, encode it as base64 and adjust it for current year """ path = addons.get_module_resource('async_move_line_importer', 'tests', 'data', filename) test_data = open(path).read() test_data = test_data.replace('2014', time.strftime('%Y')) return test_data.encode("base64")
def __init__(self, xsd_path=_DEFAULT_XSD_PATH, tmpl_dirs=None, tmpl_name=_DEFAULT_TMPL_NAME): '''tmpl_path : path to mako template''' if tmpl_dirs is None: tmpl_dirs = [] dirs = [addons.get_module_resource('l10n_ch_sepa', self._BASE_TMPL_DIR)] for dir in tmpl_dirs: dirs += [addons.get_module_resource('l10n_ch_sepa', dir)] lookup = TemplateLookup(directories=dirs, input_encoding='utf-8', output_encoding='unicode') self.mako_tpl = lookup.get_template(tmpl_name) self._xml_data = None xsd_path = addons.get_module_resource('l10n_ch_sepa', xsd_path) super(Pain001, self).__init__(xsd_path)
def _get_default_image(self, cr, uid, context=None): image_path = addons.get_module_resource('hr', 'static/src/img', 'default_image.png') return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64')) def confirm_entry(self,cr,uid,ids,context=None): self.write(cr,uid,ids,{'confirm_emp':'confirm'}) return True def approve_entry(self,cr,uid,ids,context=None): self.write(cr,uid,ids,{'confirm_emp':'approve'}) return True
def getCopyOfFile(self, filename, srcfile): path = addons.get_module_resource('seedoo_protocollo', 'tests', 'data', srcfile) currDir = os.path.dirname(path) new_file = '%s/%s.pdf' % (currDir, filename) shutil.copyfile(path, new_file) with open(new_file) as test_data: with tempfile.TemporaryFile() as out: base64.encode(test_data, out) out.seek(0) return path, out.read()
def default_get(self, field_list): """ Return information relating to the withholding regime """ # NOTE: use field_list argument instead of fields for fix the pylint # error W0621 Redefining name 'fields' from outer scope data = super(WhVatInstaller, self).default_get(field_list) gaceta = open( addons.get_module_resource("l10n_ve_withholding_iva", "files", "RegimendeRetencionesdelIVA.odt"), "rb" ) data["gaceta"] = base64.encodestring(gaceta.read()) return data
def default_get(self, cr, uid, fields_list=None, context=None): defaults = super(facturae_config, self).default_get(cr, uid, fields_list=fields_list, context=context) logo = open( addons.get_module_resource('l10n_mx_facturae', 'images', 'piramide_azteca.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def remove_image(self, cr, uid, ids, context={}): save_path = addons.get_module_resource('GDS', 'static/src/img/emp_images') for employee in self.pool.get('hr.employee').read( cr, uid, ids, ['image_lc']): employee_image = employee['image_lc'] image_path = save_path + '/' + employee_image.split('/')[-1] try: os.remove(image_path) except: pass
def _get_icon_image(self, cr, uid, ids, field_name=None, arg=None, context=None): res = dict.fromkeys(ids, '') for module in self.browse(cr, uid, ids, context=context): path = addons.get_module_resource(module.name, 'static', 'src', 'img', 'icon.png') if path: image_file = tools.file_open(path, 'rb') try: res[module.id] = image_file.read().encode('base64') finally: image_file.close() return res
def __init__(self, xsd_path=_DEFAULT_XSD_PATH, tmpl_dirs=None, tmpl_name=_DEFAULT_TMPL_NAME): '''tmpl_path : path to mako template''' if tmpl_dirs is None: tmpl_dirs = [] dirs = [addons.get_module_resource('l10n_ch_sepa', self._BASE_TMPL_DIR)] for dir in tmpl_dirs: dirs += [addons.get_module_resource('l10n_ch_sepa', dir)] lookup = TemplateLookup(directories=dirs, input_encoding='utf-8', output_encoding='unicode', default_filters=['unicode', 'x']) self.mako_tpl = lookup.get_template(tmpl_name) self._xml_data = None xsd_path = addons.get_module_resource('l10n_ch_sepa', xsd_path) super(Pain001, self).__init__(xsd_path)
def default_get(self, field_list): """ Return information relating to the withholding regime """ # NOTE: use field_list argument instead of fields for fix the pylint # error W0621 Redefining name 'fields' from outer scope data = super(WhVatInstaller, self).default_get(field_list) gaceta = open( addons.get_module_resource('l10n_ve_withholding_iva', 'files', 'RegimendeRetencionesdelIVA.odt'), 'rb') data['gaceta'] = base64.encodestring(gaceta.read()) return data
def default_get(self, fields_list): """ Get default company if any, and the various other fields from the company's fields """ defaults = super(WhIvaConfig, self).default_get(fields_list) # Set Vauxoo logo on config Window. logo = open( addons.get_module_resource('l10n_ve_withholding_iva', 'images', 'angelfalls.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def upload_report(self, cr, uid, report_id, file_sxw, file_type, context=None): ''' Untested function ''' pool = pooler.get_pool(cr.dbname) sxwval = StringIO(base64.decodestring(file_sxw)) if file_type=='sxw': fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb') if file_type=='odt': fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb') report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], { 'report_sxw_content': base64.decodestring(file_sxw), 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())), }) # FIXME: this should be moved to an override of the ir.actions.report_xml.create() method cr.commit() pool.get('ir.actions.report.xml').register_all(cr) openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname) return True
def default_get(self, cr, uid, fields_list=None, context=None): """ Default value to the config_logo field """ defaults = super(SplitInvoiceConfig, self).default_get(cr, uid, fields_list=fields_list, context=context) logo = open( addons.get_module_resource('l10n_ve_split_invoice', 'images', 'puente-maracaibo.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def default_get(self, cr, uid, fields_list=None, context=None): """ Default value config_logo field """ defaults = super(wh_islr_config, self).default_get(cr, uid, fields_list=fields_list, context=context) logo = open( addons.get_module_resource('l10n_ve_withholding_islr', 'images', 'playa-medina.jpg'), 'rb') defaults['config_logo'] = base64.encodestring(logo.read()) return defaults
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False): if not report_name or not res_ids: return (False, Exception('Report name and Resources ids are required !!!')) try: ret_file_name = addons.get_module_resource('survey', 'report') + file_name + '.pdf' service = netsvc.LocalService(report_name); (result, format) = service.create(cr, uid, res_ids, {}, {}) fp = open(ret_file_name, 'wb+'); fp.write(result); fp.close(); except Exception,e: print 'Exception in create report:',e return (False, str(e))
def test_0_prot_pdf_out(self): """ Testing send pdf File and protocol it with signature as typology_rac """ cr, uid = self.cr, self.uid partner_id = self.getIdDemoObj('base', 'main_partner') racc_id = self.getIdDemoObj('', 'protocollo_typology_rac') com_varie_id = self.getIdDemoObj('seedoo_gedoc', 'protocollo_classification_6') send_rec_id = self.modelProtSendRec.create( cr, uid, { 'name': 'test_partner', 'type': 'individual', 'partner_id': partner_id } ) prot_id = self.modelProtocollo.create( cr, uid, { 'type': 'out', 'subject': 'test out', 'typology': racc_id, 'sender_receivers': [(4, send_rec_id)], 'classification': com_varie_id, 'datas_fname': 'test0', 'datas': self.getCopyOfFile('test0', 'test_doc_src.pdf')[1], 'mimetype': 'application/pdf' } ) self.assertTrue(bool(prot_id)) prot_obj = self.modelProtocollo.browse(cr, uid, prot_id) self.assertEqual(prot_obj.state, 'draft') self.assertEqual(prot_obj.fingerprint, False) self.wf_service.trg_validate( uid, 'protocollo.protocollo', prot_id, 'register', cr) prot_obj.refresh() self.assertEqual(prot_obj.state, 'registered') prot_name = 'Protocollo_0000001_%d' % prot_obj.year self.assertEqual(prot_obj.doc_id.name, prot_name) sha1 = self.sha1OfFile(prot_obj.doc_id.id) self.assertEqual(prot_obj.fingerprint, sha1) self.assertTrue(prot_obj.xml_signature) path = addons.get_module_resource('seedoo_protocollo', 'data', "segnatura.dtd") dtdPath = os.path.dirname(path)+ "/segnatura.dtd" dtdfile = open(dtdPath, 'r') dtd = etree.DTD(dtdfile) signature_xml = etree.XML(prot_obj.xml_signature) self.assertTrue(dtd.validate(signature_xml))
def default_get(self, cr, uid, fields_list=None, context=None): """ Get default company if any, and the various other fields from the company's fields """ defaults = super(wh_iva_config, self)\ .default_get(cr, uid, fields_list=fields_list, context=context) user=self.pool.get('res.users').browse(cr,uid,[uid],context) #Set Vauxoo logo on config Window. logo = open(addons.get_module_resource('l10n_ve_withholding_iva', 'images', 'angelfalls.jpg'),'rb') defaults['config_logo'] = base64.encodestring(logo.read()) if not self._show_company_data(cr, uid, context=context): # defaults['add']='' # defaults['vat']='' return defaults return defaults
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): """generate the PDF""" if context is None: context={} if report_xml.report_type != 'latex': return super(LatexParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context) self.parser_instance = self.parser(cursor, uid, self.name2, context=context) self.pool = pooler.get_pool(cursor.dbname) objs = self.getObjects(cursor, uid, ids, context) self.parser_instance.set_context(objs, data, ids, report_xml.report_type) template = False resource_path = None if report_xml.report_file : # backward-compatible if path in Windows format report_path = report_xml.report_file.replace("\\", "/") path = addons.get_module_resource(*report_path.split('/')) if path and os.path.exists(path) : resource_path = os.path.dirname(path) template = file(path).read() if not template : raise osv.except_osv(_('Error!'), _('Latex report template not found!')) body_mako_tpl = mako_template(template) helper = LatexHelper(cursor, uid, report_xml.id, context) try : tex = body_mako_tpl.render(helper=helper, _=self.translate_call, tex=helper.texescape, **self.parser_instance.localcontext) except Exception: msg = exceptions.text_error_template().render() _logger.error(msg) raise osv.except_osv(_('Latex render!'), msg) finally: _logger.info("Removing temporal directory from helper.") del helper bin = self.get_lib(cursor, uid) pdf = self.generate_pdf(bin, report_xml, tex, resource_path=resource_path) return (pdf, 'pdf')
def _get_desc(self, cr, uid, ids, field_name=None, arg=None, context=None): res = dict.fromkeys(ids, '') for module in self.browse(cr, uid, ids, context=context): path = addons.get_module_resource(module.name, 'static/description/index.html') if path: with tools.file_open(path, 'rb') as desc_file: doc = desc_file.read() html = lxml.html.document_fromstring(doc) for element, attribute, link, pos in html.iterlinks(): if element.get('src') and not '//' in element.get('src') and not 'static/' in element.get('src'): element.set('src', "/%s/static/description/%s" % (module.name, element.get('src'))) res[module.id] = lxml.html.tostring(html) else: overrides = dict(embed_stylesheet=False, doctitle_xform=False, output_encoding='unicode') output = publish_string(source=module.description, settings_overrides=overrides, writer=MyWriter()) res[module.id] = output return res
def getCopyOfFile(self, filename, srcfile): """ this method get a copy of file , present in data folder of this tests. filename: the name of new file srcfile: the file which we want have a copy """ path = addons.get_module_resource('seedoo_protocollo_zip', 'tests', 'data', srcfile) currDir = os.path.dirname(path) new_file = '%s/%s.pdf' % (currDir, filename) shutil.copyfile(path, new_file) with open(new_file) as test_data: with tempfile.TemporaryFile() as out: base64.encode(test_data, out) out.seek(0) return path, out.read()
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): """generate the PDF""" if context is None: context={} if report_xml.report_type != 'orgmode': return super(OrgmodeParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context) self.parser_instance = self.parser(cursor, uid, self.name2, context=context) self.pool = pooler.get_pool(cursor.dbname) objs = self.getObjects(cursor, uid, ids, context) self.parser_instance.set_context(objs, data, ids, report_xml.report_type) template = False resource_path = None if report_xml.report_file : # backward-compatible if path in Windows format report_path = report_xml.report_file.replace("\\", "/") path = addons.get_module_resource(*report_path.split('/')) if path and os.path.exists(path) : resource_path = os.path.dirname(path) template = file(path).read() template_utf8 = unicode(template, 'utf-8') if not template : raise osv.except_osv(_('Error!'), _('Org-mode report template not found!')) try : org = pystache.render(template_utf8, self.parser_instance.localcontext).encode('utf-8') except Exception: msg = "Error en archivo ORG" _logger.error(msg) raise osv.except_osv(_('Orgmode render!'), msg) finally: _logger.info("Removing temporal directory from helper.") bin = self.get_lib(cursor, uid) pdf = self.generate_pdf(bin, report_xml, org, resource_path=resource_path) return (pdf, 'pdf')
def create(self, cr, uid, ids, datas, context=None): pool = pooler.get_pool(cr.dbname) taxobj = pool.get('account.tax.code') if context is None: context = {} code_ids = taxobj.search(cr, uid, [('parent_id','child_of',[datas['form']['tax_code_id']])]) result = {} for t in taxobj.browse(cr, uid, code_ids, {'period_id': datas['form']['period_id']}): if str(t.code): result['case_'+str(t.code)] = '%.2f' % (t.sum_period or 0.0, ) user = pool.get('res.users').browse(cr, uid, uid, context) # Not Clean, to be changed partner = user.company_id.partner_id result['info_name'] = user.company_id.name result['info_vatnum'] = partner.vat if partner: result['info_address'] = partner.street result['info_address2'] = (partner.zip or '') + ' ' + (partner.city or '') try: tmp_file = tempfile.mkstemp(".pdf")[1] try: tools.pdf_utils.fill_pdf(addons.get_module_resource('l10n_lu','wizard', '2008_DECL_F_M10.pdf'), tmp_file, result) with open(tmp_file, "r") as ofile: self.obj = external_pdf(ofile.read()) finally: try: os.remove(tmp_file) except: pass # nothing to do self.obj.render() return (self.obj.pdf, 'pdf') except Exception: raise osv.except_osv(_('pdf not created !'), _('Please check if package pdftk is installed!'))
def getDocFile(self, docname): path = addons.get_module_resource('seedoo_protocollo_zip', 'tests', 'data', docname) with open(path) as test_data: content = test_data.read() return base64.encodestring(content)