使用odoo创建many2one字段时出错

时间:2022-07-14 20:23:38

I am new to odoo ERP and i'm trying to create a new module for learning i need to create a drop down list that gets values from postgres database but i get the following error in the log file: 'module' object has no attribute 'many2one'

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

here is my xml code:

这是我的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 code:

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

Regards,

问候,

2 个解决方案

#1


1  

You just need to define:

你只需要定义:

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

#2


0  

You need edit many2one to Many2one

您需要编辑many2one到Many2one

#1


1  

You just need to define:

你只需要定义:

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

#2


0  

You need edit many2one to Many2one

您需要编辑many2one到Many2one