Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
21356 มุมมอง

How can i add a field that upload file (.doc .pdf .xls) ? and how i can download this file after uploading it ?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

You can use Binary fields.

It stores all kinds of files like .doc, .excel, .xls, etc

Once you define the field, you will have a button near the field to Upload your file.


    field_name = fields.Binary(string=’Name of field’ )


    You can download it again by simply click on that field.

    Check the below links for getting more information about adding new fields.

    Check this Blog for adding fields by code: https://www.cybrosys.com/blog/adding-custom-fields-to-existing-views-in-odoo-v12

    Check this video for adding field without code: https://www.youtube.com/watch?v=uSPS8l0kbDE

    Edit: 

    for V8, follow like this. 


    _columns = {

    'binary_field':fields.binary('File'),

    'file_name':fields.char('Filename'),

    }

    And in the form view in your xml:

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

    <field name="binary_field" filename="file_name"/>



    Thanks & Regards

    Avinash N K

    อวตาร
    ละทิ้ง
    ผู้เขียน

    it works but when i try to download the file , its download with file extension, without .pdf or .xls

    I update the answer for v8.

    คำตอบที่ดีที่สุด
    class mrp(models.Model):
    _inherit = 'mrp.production'
    upload_file = fields.Binary(string='Upload file')


    record id="mrp_production_form_view_upload_file_view" model="ir.ui.view">
    name="name">mrp.production.form
    name="model">mrp.production
    name="inherit_id" ref="mrp_extension.mrp_production_form_view_inherited"/>
    name="arch" type="xml">
    expr="//field[@name='name']" position="after">
    name="upload_file"/>


    อวตาร
    ละทิ้ง
    Related Posts ตอบกลับ มุมมอง กิจกรรม
    5
    ต.ค. 23
    7406
    1
    ส.ค. 19
    4131
    0
    ต.ค. 19
    2683
    0
    มิ.ย. 16
    2630
    1
    มี.ค. 15
    4823