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

Is there a way to load data into a models binary field on module install?

I want to have a howtos model where there would be a tree view of binary fields where the howtos would be stored. This fields would be filled with data on module install.

I know how to fill data into models with xml files. 

<record model="hr.code.tags" id="tag_my_tag">
	<field name="name">MyTag</field>
	<field name="usage">To be used for my values.</field>
	<field name="locked">True</field>
</record>
How would do that with pdf files from the /static folder in a binary field? 
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Yes, there is a way:

Assuming that your module names "demo", your model has the identifier "demo.howto" and the binary field is "file":

1. Put in the folder demo/static/src/binary your pdf files (howto.pdf).

2. Create a file with data records to register in the folder demo/data (howto_data.xml):

<odoo noupdate="1">

    <data>

        <record id="howto_1" model="demo.howto">

            <field file="demo/static/src/binary/howto.pdf" name="file" type="base64" />

        </record>

    </data>

</odoo>

3. Register the data file in the data section of the __manifest__.py

    # always loaded

    'data': [

        'security/ir.model.access.csv',

        'data/howto_data.xml',

        'views/views.xml',

        'views/templates.xml',

    ],

4. Install module and the data will be loaded.

 

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

Thanks! Needed only the 2. point, but a nice explanation how to load data on module install/upgrade.

You are welcome. I'm glad I could help you.

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
เม.ย. 22
16875
1
พ.ย. 18
4192
4
พ.ย. 16
10064
2
ก.ค. 25
4502
2
ธ.ค. 24
7674