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

How to export a xml file?

By
Anabela Damas
on 7/30/13, 12:19 PM 3,457 views

Hi,

I'm trying to export an xml file that I done the function that generate this file, but I wanted that when I click on the button "generate xml" this will generate the file and do the download of the file.

The download part I just can if I go to the form of the object containing the filedata field.

I've like this :

class my_class(osv.osv_memory):

    _name = "my.class"
    _columns = {
            'name': fields.char('Filename', 16, readonly=True),
            'filedata': fields.binary('File', readonly=True),
           }

    def generate_xml(self, cr, uid, ids, context=None):
        ..... compute data to write in xml...
        xml_data = text_to_write_in_xml
        file=base64.encodestring( xml_data )
        return self.write(cr, uid, ids, {'state':'get', 'filedata':file, 'name':"file.xml"}, context=context)

     <record id="wizard_file" model="ir.ui.view">
            <field name="name">Xml File export</field>
            <field name="model">my.class</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form col="3" string="xml" >
                                ....
                                <button icon="gtk-ok" name="generate_xml"  string="Generate xml" type="object"/>
                               ....
               </form>
            </field>
        </record>

With this code the file is created and the wizard close. If I want the file I've to go to the list of all records of the object my.class and click "Download". I want to make the download when click in the button generate_xml. How do I do that?

As an option I try to keep the wizard open in the record that I had created the file ... but I just manage to go to a form to create a new record, I couldn't stay in the record that I was before click in "generate xml". I tried this way :

 def generate_xml(self, cr, uid, ids, context=None):
    ..... compute data to write in xml...
    xml_data = text_to_write_in_xml
    file=base64.encodestring( xml_data )
    self.write(cr, uid, ids, { 'filedata':file, 'name':"file.xml"}, context=context)
    return {
        'type': 'ir.actions.act_window',
        'res_model': 'my.class',
        'view_mode': 'form',
        'view_type': 'form',
        'target': ids, 
        'context': dict(context, active_ids=ids)
        }
0
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 6/19/14, 1:12 AM

In the Python return type add 'target':'new' it allow to download in the wizard pop-up itself.

return {
        'type': 'ir.actions.act_window',
        'res_model': 'my.class',
        'view_mode': 'form',
        'view_type': 'form',
        'target': ids,
        'context': dict(context, active_ids=ids)
        'views': [(False, 'form')],
        target': 'new',
        }
        

In the xml file add filename tag it allow to download with filename.

<field name="data" filename="name"/>   

0
Adrian Beloqui
On 6/18/14, 12:16 PM

Hi Anabela,

Did you solve this problem? I am trying to create a custom xml file using some of the information from the fields of my module, but I just can find the right information in order to have a guide of how to achieve this. I hope you can help me.

Thanks

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

0 follower(s)

Stats

Asked: 7/30/13, 12:19 PM
Seen: 3457 times
Last updated: 5/29/15, 7:29 AM