跳至内容
菜单
此问题已终结
1 回复
5004 查看

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

形象
丢弃
最佳答案

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>
形象
丢弃
编写者

Thanks Jasad.

编写者

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?

相关帖文 回复 查看 活动
5
4月 19
5712
1
4月 16
3912
1
3月 15
8526
new module? 已解决
10
5月 20
4480
6
7月 18
11590