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

Hi!

I created a custom module to add a field to the Event Registration Form, I need a text field where we can input more details for each registered user to an X event.

So far I have develop the following module:

  • add_fields_events (folder)
  • __init__.py
  • __openerp__.py
  • code.py
  • view.xml

Each one with the following simple code:

__init__.py

import code

__openerp__.py

    {
    'name' : 'Custom Extra Event Fields',
    'version' : '1.0',
    'description' : """Custom Extra Fields for Event Module""",
    'depends' : ['event'],
    'init_xml' : [], 
    'update_xml' : ['view.xml'],
    'demo_xml' : [],
    'active' : False, 
    'installable' : True,
}

code.py

from osv import osv, fields

class res_partner_add_text_field(osv.osv):
    _inherit = 'event.registration'

    _columns = {
        'textual_field' : fields.text('Details'),
    }

view.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>            
        <record model="ir.ui.view" id="view_event_form_add_text_field">
            <field name="name">view.event.form.add.text.field</field>
            <field name="model">event.registration</field>
            <field name="inherit_id" ref="view_event_registration_form"/>
            <field name="arch" type="xml">
                <field name="email" position="after">
                    <field name="textual_field" />
                </field>
            </field>
        </record>
    </data>
</openerp>

Everything seems to be alright, but i get the following error when trying to install:

ValueError: No such external ID currently defined in the system: add_event_fields.view_event_registration_form

Any ideas? The "view_event_registration_form" is the id inside of event_view.xml - View which i would like to change.

Thanks in advance!

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

Seems i got the solution.

Reading and watching from other examples I realize that in OpenERP, you have to inherit from the same (folder - file) "structure" that is in the addons folder, so based on that the right parameter in code.py is:

class res_partner_add_text_field(osv.osv):
    _inherit = 'event.event'

In the other hand in the view.xml the "event." property must be included as part of the refence, so the right code would be:

<field name="inherit_id" ref="event.view_event_registration_form"/>

So there you go, my initial experience with custom modules.

Do you have any other advice? Thanks!

Ảnh đại diện
Huỷ bỏ

No advice for you but your post was instructive to me as I am also a newbie with custom modules. Thanks for the helpful examples!

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 10 20
8681
1
thg 3 15
4260
0
thg 3 15
4781
0
thg 3 15
3611
3
thg 2 24
10152