Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
5000 Tampilan

I'm so confused about the creation of new modules in openerp. I need to know what actually creates the tables in the database, and how to modify them. Is it the classes of the new model where we define the "_columns" dictionary? Is it the view (.xml) file where we define ?

Or can I build the tables by myself in the pgAdmin?

It took me so much time yet I couldn't figure out the mechanism of creating the structure of the tables.

I downloaded a sample openerp module and installed it which ran successfully, but whenever I tried to add a new field in the xml file I kept getting the message "Invalid XML for View Architecture".

Avatar
Buang
Jawaban Terbai

Hi Ehab Mosilhy,

Tables are get created in database from class we written in python code. And fields in the tables are the one we write in _columns in that class.

eg:

class sale_order(osv.osv):
    _name = "sale.order"
    _columns = {
        'name': fields.char('Order Reference', size=64, required=True,
            readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, select=True), 
      ...........
    } 
sale_order()

Fields write in xml file is only for view purpose.

To add or modify the table or view, inherit the class and add new fields. If you want to show the fields in view, then inherit the view(xml) and add the new field in view too.

eg:

class sale_order(osv.osv):
    _inherit = 'sale.order'
    _columns = {
        'section_id': fields.many2one('crm.case.section', 'Sales Team'),
        'categ_ids': fields.many2many('crm.case.categ', 'sale_order_category_rel', 'order_id', 'category_id', 'Categories', \
        domain="['|',('section_id','=',section_id),('section_id','=',False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}")
}

Its added in view.

<record model="ir.ui.view" id="sale_view_inherit123">
            <field name="name">sale.order.inherit</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <field name="user_id" position="after">
                    <field name="section_id" widget="selection"/>
                    <field name="categ_ids" widget="many2many_tags"/>
                </field>
            </field>
        </record>
Avatar
Buang
Penulis

Thanks Jasad.

Penulis

It's mentioned in the documentation that if I want to create a table automatically from the class, I should use _auto. See "_auto Determines whether a corresponding PostgreSQL table must be generated automatically from the object." But as you say, _auto is not required, is this true?

Post Terkait Replies Tampilan Aktivitas
5
Apr 19
5712
1
Apr 16
3910
1
Mar 15
8525
new module? Diselesaikan
10
Mei 20
4478
6
Jul 18
11588