Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Generate Custom Xml file on button click ???

By
saibaba
on 9/20/13, 4:36 AM 2,627 views

How can we generate custom xml file as same as how we generate pdf report on button click in openerp ? pls anyone guide me on custom xml file generation process ???

1
saibaba
On 9/20/13, 7:54 AM

@pinakinnayi : thank you for the reply, yes i have done the same thing already actually my question is how to write that into a new file and ask the user where to save same like pdf report where it shows the dialog box to save it into the disk ???

The steps i followed ..... python code :

class xmlFile_Creation(osv.osv):  
#this function "generate_xml " is called from button click on view.xml and stores the encoded xml data into database coloumn
    def generate_xml(self,cr, uid, ids, context=None):
        root = ET.Element("root")
        doc = ET.SubElement(root, "doc")                
        field1 = ET.SubElement(doc, "field1")
        field1.set("name", "blah")
        field1.text = "some value1"        
        field2 = ET.SubElement(doc, "field2")
        field2.set("name", "asdfasd")
        field2.text = "some vlaue2"        
        xmlstr = ET.tostring(root)            
        file=base64.encodestring( xmlstr )
        return self.write(cr, uid, ids, {'filedata':file, 'name':"filenew"}, context=context)          
    _name="sample.xmlfile.creation"
    _columns={
              'trader':fields.many2one('sample.traders','SelectTrader'),
              'name': fields.char('Filename', 16, readonly=True),
              'filedata': fields.binary('File', readonly=True), 
              }
xmlFile_Creation()
0
Pinakin Nayi (pna)
On 9/20/13, 5:21 AM

Hello,

You can do something like below.

Using lxml:

from lxml import etree

create XML

root = etree.Element('root') root.append(etree.Element('child'))

another child with text

child = etree.Element('child') child.text = 'some text' root.append(child)

pretty string

s = etree.tostring(root, pretty_print=True) print s

Output: <root> <child/> <child>some text</child> </root>

@pinakinnayi : thank you for the reply, yes i have done the same thing already actually my question is how to write that into a new file and ask the user where to save same like pdf report where it shows the dialog box to save it into the disk ???

saibaba
on 9/20/13, 8:27 AM

I too have this same question? Can openerp directly serve up a .txt or .html or .xml or really any other plain text format? Seems odd that we can do pdf and not raw text...

tim diamond
on 12/9/13, 7:03 PM

Hello, #sai , #tim there is one community module Jasper report that have same functionality, you can refer that module that may be useful to you. https://code.launchpad.net/~jasper-reports-commiters/openobject-jasper-reports/7.0

Pinakin Nayi (pna)
on 12/10/13, 1:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/20/13, 4:36 AM
Seen: 2627 times
Last updated: 4/12/16, 5:32 AM