Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Mechanism of database and new modules in Openerp

Ehab Mosilhy
on 12/18/13, 2:03 AM 897 views

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".

On 12/18/13, 3:29 AM

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.


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), 

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.


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"/>

Thanks Jasad.

Ehab Mosilhy
on 12/18/13, 4:24 AM

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?

Ehab Mosilhy
on 12/18/13, 4:25 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 12/18/13, 2:03 AM
Seen: 897 times
Last updated: 3/16/15, 8:10 AM