Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5010 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

Thanks Jasad.

Autore

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 correlati Risposte Visualizzazioni Attività
5
apr 19
5719
1
apr 16
3941
1
mar 15
8534
10
mag 20
4488
6
lug 18
11616