def create_from_template(self,cr,uid,info_template,context=None): temp = Template() temp.read(info_template['path_template'] + info_template['template_file_name']) #if not info_template.has_key('name'): info_template = temp.get_definition_report(info_template) if(info_template.has_key('name')): print 'info_template ',info_template report_id = self.search(cr,uid,[('name','=',info_template['name'])],context=context) vals={ 'name':info_template['name'], 'title':info_template['title'] or info_template['name'], 'format': info_template['format'], 'module_id':info_template['module_id'], 'template_file_name':end_file(info_template['template_file_name'],'.html'), 'json_file_name':end_file(info_template['template_file_name'],'.json'), 'type':info_template.get('type','form'), 'viewer_type':info_template['viewer_type'], } print 'etat record report ', report_id if(report_id): #set report definition self.write(cr,uid,report_id,vals,context=context) self.write_report_def(cr,uid,temp,report_id[0],context=context) return report_id[0] else: #add new report definition report_id = self.create(cr,uid,vals,context=context) col_deferreds = self.create_report_def(cr,uid,temp,report_id,context=context) if len(col_deferreds): self.pool.get('report.def').upadate_deferred_totals(cr,uid,report_id,col_deferreds) return report_id else: raise osv.except_osv('Action Error !',"No report definition in template " + info_template['template_file_name'])
def csv_convert_xml(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids, context=context)[0] xml_file_name = end_file(this.name,'.xml') data_file = str(base64.decodestring(this['data'])) my_csv = xml_from_csv(data_file,this.model_id.model) print my_csv.convert() # Save file binary encoded_string = base64.b64encode(my_csv.xml) set_data={ 'xml_file':encoded_string, 'name':xml_file_name, 'state':'get' } this.write(set_data) return { 'type': 'ir.actions.act_window', 'res_model': 'rdef.csv2xml', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def csv_convert_xml(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids, context=context)[0] xml_file_name = end_file(this.name, '.xml') data_file = str(base64.decodestring(this['data'])) my_csv = xml_from_csv(data_file, this.model_id.model) print my_csv.convert() # Save file binary encoded_string = base64.b64encode(my_csv.xml) set_data = { 'xml_file': encoded_string, 'name': xml_file_name, 'state': 'get' } this.write(set_data) return { 'type': 'ir.actions.act_window', 'res_model': 'rdef.csv2xml', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def xml_export_report(self, cr, uid, ids, context=None): """ To get the date and print the report @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param context: A standard dictionary @return : retrun report """ if context is None: context = {} values = self.read(cr, uid, ids, context=context)[0] report_ids = values['report_ids'] pool_rep = self.pool.get('report.def') for report_id in report_ids: report = pool_rep.browse(cr,uid, report_id) if report.xml_file_name: xml_file_name = end_file(report.xml_file_name,'.xml') my_xml = xml_gen_model(self.pool,cr,uid,xml_file_name) my_xml.add_model('report.def','report') my_xml.xml_gen_basic('report.def',report) else: print "nom de fichier xml invalide ",report.xml_file_name
def export_models(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids, context=context)[0] xml_file_name=end_file(this.name,'.xml') my_xml = xml_gen_model(self.pool,cr,uid,xml_file_name) for model_id in this.model_ids: ir_model = self.pool.get('ir.model').read(cr, uid, model_id.id, context=context) field_id_model = {} for field in model_id.field_id: field_id_model.update({field.name:field.relation}) # print "d : ",field_id_model model_name=ir_model['model'] pool_model = self.pool.get(model_name) model_ids = pool_model.search(cr,uid,[],context=context) records=pool_model.browse(cr,uid,model_ids,context=context) my_xml.add_model(model_name,'report') for record in records: val = my_xml.xml_generate(model_name,record) node = etree.fromstring(str(val)) # id_val = model_name.replace('.','_')+"_"+node.get('id') id_val = node.get('id') node.set('id',id_val) for child in node: if child.attrib.get('ref',''): mod_name = field_id_model.get(child.attrib.get('name','')) ref_val = mod_name.replace('.','_')+"_"+child.attrib.get('ref','') child.set('ref',ref_val) xmlstr = ET.tostring(node, method='xml') my_xml.xml += xmlstr # print "my_xml : ",my_xml.xml # generate childs models #my_xml.scan_field_one2many(model_name) my_xml.xml_terminate() # Save file binary encoded_string = base64.b64encode(my_xml.xml) set_data={ 'xml_file':encoded_string, 'name':xml_file_name, 'state':'get' } this.write(set_data) return { 'type': 'ir.actions.act_window', 'res_model': 'rdef.model.export.xml', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def create_dynamic_report(self,cr,uid,report_name,context): report_def_ids = self.search(cr,uid,[('name','=',report_name)],context=context) report_def_id = None if(report_def_ids): report_def_id = report_def_ids[0] else: info_template = { 'name':report_name, 'title':context.get('title',report_name), 'module_id':context.get('module_id',0), 'template_file_name':end_file(report_name,'.html'), 'json_file_name':end_file(report_name,".json"), 'format':context.get('type_doc','Landscape'), 'type':context.get('type_doc','form'), 'viewer_type':context.get('viewer_type','html'), } report_def_id = self.create(cr,uid,info_template,context=context) return report_def_id
def to_dict(self,cr,uid,name=None,id=None): dict_report = {} if name: print 'recherche par Nom',name ids = self.search(cr,uid, [('name','=',name)]) else: print 'recherche par id',id ids = self.search(cr,uid, [('id','=',id)]) if ids: print "Id trouve de defreport",ids report = self.browse(cr,uid, ids)[0] dict_report['id']=report.id dict_report['name']=report.name dict_report['title']=report.title dict_report['module_id']=report.module_id.id dict_report['query']=report.query dict_report['format']=report.format dict_report['type']=report.type dict_report['template_html'] = report.template_html dict_report['template_file_name'] = end_file(report.template_file_name,'.html') dict_report['json_file_name'] = end_file(report.json_file_name,'.json') dict_report['viewer_type'] = report.viewer_type dict_report['col_fields']=[] for field_id in report.field_ids: dict_report['col_fields'].append(field_id.to_dict()) dict_report['col_sections']=[] for section_bloc_id in report.section_bloc_ids: dict_report['col_sections'].append(section_bloc_id.to_dict()) return dict_report else: return dict_report
def to_dict(self,cr,uid,name=None,id=None): dict_report={} if name: id = self.search(cr,uid, [('name','=',name)]) else: id = self.search(cr,uid, [('id','=',id)]) if id: report = self.browse(cr,uid, id)[0] dict_report['name']=report.name dict_report['title']=report.titile dict_report['module']=report.module_id.name dict_report['query']=report.query dict_report['format']=report.format dict_report['template_html']=report.template_html dict_report['template_file_name'] = end_file(report.template_file_name,'.html') return dict_report else: return dict_report
def export_models(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids, context=context)[0] xml_file_name = end_file(this.name, '.xml') my_xml = xml_gen_model(self.pool, cr, uid, xml_file_name) for model_id in this.model_ids: ir_model = self.pool.get('ir.model').read(cr, uid, model_id.id, context=context) field_id_model = {} for field in model_id.field_id: field_id_model.update({field.name: field.relation}) # print "d : ",field_id_model model_name = ir_model['model'] pool_model = self.pool.get(model_name) model_ids = pool_model.search(cr, uid, [], context=context) records = pool_model.browse(cr, uid, model_ids, context=context) my_xml.add_model(model_name, 'report') for record in records: val = my_xml.xml_generate(model_name, record) node = etree.fromstring(str(val)) # id_val = model_name.replace('.','_')+"_"+node.get('id') id_val = node.get('id') node.set('id', id_val) for child in node: if child.attrib.get('ref', ''): mod_name = field_id_model.get( child.attrib.get('name', '')) ref_val = mod_name.replace( '.', '_') + "_" + child.attrib.get('ref', '') child.set('ref', ref_val) xmlstr = ET.tostring(node, method='xml') my_xml.xml += xmlstr # print "my_xml : ",my_xml.xml # generate childs models #my_xml.scan_field_one2many(model_name) my_xml.xml_terminate() # Save file binary encoded_string = base64.b64encode(my_xml.xml) set_data = { 'xml_file': encoded_string, 'name': xml_file_name, 'state': 'get' } this.write(set_data) return { 'type': 'ir.actions.act_window', 'res_model': 'rdef.model.export.xml', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def get_path_template_name(self,cr,uid,report_id,template_name,context=None): module_rep = self.pool.get("ir.module.module").browse(cr,uid,report_id,context) module_folder_name = ao_register.CD_ODOO_ADDONS + module_rep.name + '/templates/' template_name = end_file(template_name,'.html') return module_folder_name + template_name