使用odoo创建many2one字段时出错

时间:2016-10-26 11:56:35

标签: python postgresql odoo-8

我是odoo ERP的新手,我正在努力创建一个新的学习模块 我需要创建一个从postgres数据库获取值的下拉列表 但我在日志文件中收到以下错误: '模块'对象没有属性' many2one'

这是我的xml代码:

<!--COSTCENTER-->
<!--Cost Center Form-->
<record model="ir.ui.view" id="cc_form">
    <field name="name">cc.form</field>
    <field name="model">cc.cc</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Cost Center" version="1.0">

        <group colspan="2" col="2">
            <field name="cc_code" required="1"  widget="selection"/>
            <field name="cc_name"/>
             <field name="notes"/>

        </group>
    </form>
  </field>
</record>

<!--Cost Center Tree-->
<record model="ir.ui.view" id="cc_tree_view">
 <field name="name">cc.tree</field>
 <field name="model">cc.cc</field>
 <field name="type">tree</field>
 <field name="arch" type="xml">
     <tree string="Cost Center">
        <field name="cc_code"/>
        <field name="cc_name"/>
            <field name="notes"/>
          </tree>
   </field>
</record>

<!--Cost Center Action-->
<record id="action_cc" model="ir.actions.act_window">   
<field name="name">Cost Center</field>
<field name="res_model">cc.cc</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

<!--EQUIPMENTS-->
<!--Equipments Form-->
<record model="ir.ui.view" id="eqp_form">
<field name="name">eqp.form</field>
<field name="model">eqp.eqp</field>
<field name="type">form</field>
<field name="arch" type="xml">
    <form string="Equipments" version="1.0">

        <group colspan="4" col="4">
            <field name="asset_no" required="1"/>
            <field name="used_by"/>
            <field name="cc_code"/>

        </group>
    </form>
</field>
</record>

<!--Equipments Tree-->
<record model="ir.ui.view" id="eqp_tree_view">
 <field name="name">eqp.tree</field>
 <field name="model">eqp.eqp</field>
 <field name="type">tree</field>
 <field name="arch" type="xml">
     <tree string="Equipments">
        <field name="asset_no" required="1"/>
        <field name="used_by"/>
        <field name="cc_code"/>
          </tree>
 </field>
</record>

python代码:

from openerp  import models, fields, api, _

class cc(models.Model):

    _name = "cc.cc"
    _description = "Testing cc "

    cc_code = fields.Char(string='Cost Center Code', required=True, index=True, translate=True, help='Requierd to enter cost center code')
    cc_name = fields.Char(string='Cost Center Name', help='Enter cost center name')
    notes = fields.Text(string='Notes', help='Enter notes')

class eqp(models.Model):

    _name = "eqp.eqp"
    _description = "Testing eqp "

    asset_no = fields.Char(string='Asset No')
    used_by = fields.Char(string='Used By')
    cc_code = fields.many2one('cc.cc_code', string='cc_code')

此致

2 个答案:

答案 0 :(得分:1)

您只需要定义:

cc_code = fields.many2one('cc.cc', string='cc_code')

答案 1 :(得分:0)

您需要将 m any2one编辑为 M any2one