Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
22535 Lượt xem

HI

I'm with some troubles when I'm downloading some files. The name I set to the file is for example "123456.xml" and when I download it the file name is the name of my model....

I store the name and the filedata on a database to set as default on the new wizard after I click on a button (I have some images to help you understand :) )

My .py 

I create the columns 

class Saft_Export_Transporte(osv.osv_memory):
    _name = 'saft.export.transporte'
    _description = 'Saft Export'
    

 
    def get_filedata_transporte(self, cr, uid, context=None):
      cr.execute("SELECT filedata from Saft_Export_Transporte where id=1")
      output=cr.fetchone()
      output=str(output[0])
      return output

    def get_name_transporte(self, cr, uid,context=None):
      cr.execute("SELECT name from Saft_Export_Transporte")
      output=cr.fetchone()
      output=str(output[0])
      return output

    _columns = {
             'name': fields.char('Nome',size=25, readonly=True),
              'filedata': fields.binary('Texto',filters='*.xml'),
    }
    _defaults = {
            'filedata': get_filedata_transporte,
            'name': get_name_transporte
    }

My .xml

<record id="saft_export_transporte" model="ir.ui.view">
            <field name="name">Saft Export Transporte</field>
            <field name="model">saft.export.transporte</field>
            <field name="arch" type="xml">
                <form string="Saft Export Transporte" version="7.0">
                    <group col="1">
                    <separator string="Concluido"/>
                    <field name="name" invisible="1"/>
                    <label string="Guarde o ficheiro resumido saft"/>
                    <newline/>
                    <field name="filedata" nolabel="1" readonly="1" filename="name"/>
                    </group>
                    
                            
                    <footer>
            
                        <button string="Fechar" class="oe_link" special="cancel"/>
                    </footer>
                </form>
            </field>
        </record>

        <record id="saft_export_action" model="ir.actions.act_window">
            <field name="name">saft.export</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">saft.export.transporte</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
        </record>

 

http://tinypic.com/r/oasuvl/8

http://tinypic.com/r/nprr7d/8

Can you help me?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

An example with contract_file and contract_file_name (file name depends on code of contracts throw a function for this example).

in python class :

_columns = {

'contract_file':fields.binary("Contract file (PDF)"),

'contract_file_name': fields.function(_get_contract_file_name, type="char", size=255, readonly=True, method=True),

}

contract_file_name can be a simple char field

 

in xml : 

<field name="contract_file" filename="contract_file_name"/> 
<field name="contract_file_name" invisible="1"/>

don't set invisible="1" if you want a field to set explicitly the file name

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Refer the following link for filename. It may help you. 
https://bugs.launchpad.net/openerp-web/+bug/1252458

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Does " filters='*.xml') " work? It does not work in my odoo 14.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

it raises an error your solution

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 23
479
2
thg 2 24
2041
1
thg 3 15
8900
0
thg 3 15
5889
1
thg 6 23
4358