Odoo中的许多关系(开放式)

时间:2014-09-25 15:39:19

标签: python openerp openerp-7 openerp-8

我正在从兽医诊所的例子中学习odoo编程。

python代码如下。

class vetclinic_animal(osv.Model):
    _name = "vetclinic.animal"
    _columns = {
        'name': fields.char('Name', size=64),
        'birthdate': fields.date('Birth Date'),
        'breed_id':fields.many2one('vetclinic.breed','Breed'),
        'classification_id': fields.many2one('vetclinic.classification','Classification'),
        'labels_ids':fields.many2many('vetclinic.labels','rel_animal_labels','animal_id','labels_id',string='Labels'),      

 }

问题看起来像是'labels_ids',当我在我的Odoo上安装此模块时,'labels_ids'('标签)的字段没有显示在表单中。但是,如果我将代码的这一部分更改为:

    'labels_ids': fields.many2one('vetclinic.labels','Labels'),

它在很多2字段中显示出预期效果。

那么,我的代码出了什么问题?

由于

XML视图如下

    

    <record id="vetclinic_animal_action" model="ir.actions.act_window">
        <field name="name">Animals</field>
        <field name="res_model">vetclinic.animal</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html"> 
            <p class="oe_view_nocontent_create">Click Create to add a new animal record.</p>
        </field>    
    </record>

    <record id="vetclinic_classification_action" model="ir.actions.act_window">
        <field name="name">Classification</field>
        <field name="res_model">vetclinic.classification</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html"> 
            <p class="oe_view_nocontent_create">Click Create to add a new classification record.</p>
        </field>    
    </record>

    <record id="vetclinic_breed_action" model="ir.actions.act_window">
        <field name="name">Breed</field>
        <field name="res_model">vetclinic.breed</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html"> 
            <p class="oe_view_nocontent_create">Click Create to add a new breed record.</p>
        </field>    
    </record>       


    <record id="vetclinic_animal_form_view" model="ir.ui.view">
        <field name="name">vetclinic.animal.form.view</field>
        <field name="view_type">form</field>
        <field name="model">vetclinic.animal</field>
        <field name="arch" type="xml">
            <form string="Animal">
                <field name="name"/>
                <field name="birthdate"/>
                <field name="breed_id"/>
                <field name="classification_id"/>
                <field name="labels_ids"/>
            </form>
        </field>    
    </record>

    <menuitem id="vetclinic" name="Vet Clinic"/>    
    <menuitem id="vetclinic_menu" name="Vet Clinic" parent= "vetclinic" />
    <menuitem id="vetclinic_animal_menu" 
        name="Animals" 
        parent="vetclinic_menu" 
        action="vetclinic_animal_action"
     />
    <menuitem id="vetclinic_classification_menu" 
        name="Classification" 
        parent="vetclinic_menu" 
        action="vetclinic_classification_action"
     />
    <menuitem id="vetclinic_breed_menu" 
        name="Breed" 
        parent="vetclinic_menu" 
        action="vetclinic_breed_action"
     />         

</data>

完整的python文件如下

from openerp.osv import osv, fields

class vetclinic_animal(osv.Model):
    _name = "vetclinic.animal"
    _columns = {
        'name': fields.char('Name', size=64),
        'birthdate': fields.date('Birth Date'),
        'breed_id':fields.many2one('vetclinic.breed','Breed'),
        'classification_id': fields.many2one('vetclinic.classification','Classification'),
        'labels_ids':fields.many2many('vetclinic.labels','rel_animal_labels','animal_id','labels_id',string='Label')      
    }

class vetclinic_classification(osv.Model):
    _name = "vetclinic.classification"
    _columns = {
        'name': fields.char('Name', size=32),  
        }

class vetclinic_breed(osv.Model):
    _name = "vetclinic.breed"
    _columns = {
        'name': fields.char('Name', size=32),  
        }

class vetclinic_labels(osv.Model):
    _name = "vetclinic.labels"
    _columns = {
        'name': fields.char('Name', size=32),  
        }            

1 个答案:

答案 0 :(得分:0)

使vetclinic取决于 openerp .py

'depends': ['vetclinic']