This question has been flagged
3 Replies
11742 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)
        }
Avatar
Discard
Best Answer

You need a Controller for that. See example in source of mail.message.

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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"/>   

Avatar
Discard