本文介绍了odoo 9-字段不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照文档Odoo 9.0的要求,我创建了一个新模块,并按如下所示创建了一个新模型:

follow the documentation Odoo 9.0, I created a new module which I created a new model as follows:

models.py

models.py

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class payModel(models.Model):
    _name = 'payModel.payModel'
    _inherit = 'hr.employee'

    num_CN = fields.Char("CN°")

和我的表单视图:

<record model="ir.ui.view" id="payModel_form_view">
    <field name="name">payModel.num_CN</field>
    <field name="model">hr.employee</field>
    <field name="inherit_id" ref="hr.view_employee_form"/>
    <field name="arch" type="xml">
        <data>
            <xpath expr="//field[@name='bank_account_id']" position="after">
                <field name="num_CN"/>
            </xpath>
        </data>
    </field>
</record>

我在设置->技术->数据库结构->成功添加模型和字段的模型中发现问题,但我遇到了这个错误:

I verirfy in Settings -> Technical -> Database Structure -> Models that the model and the field were added by success But I get this error :

我尝试通过开发人员模式在员工表单视图中添加此字段,但出现相同的错误!

I try to add this field in employee form view by developer mode but I get the same error!

可以帮助我所缺少的吗?

Can sameone help me what's missing?

推荐答案

首先-关于您的模型.

_name = 'payModel.payModel'表示当您安装模块时,Odoo将创建名称为 payModel_payModel 的新表.在系统中之后,将是您的自定义对象- payModel.payModel .

_name = 'payModel.payModel' means that when you install module Odoo will create new table with name payModel_payModel. After this in the system will be your custom object - payModel.payModel.

_inherit = 'hr.employee'表示您扩展表 hr_employee (Odoo对象- hr.employee ).

_inherit = 'hr.employee' means that you expand table hr_employee(Odoo object - hr.employee).

如果要创建新表并使用新对象,则需要删除_inherit = 'hr.employee'.如果您需要扩展 hr.employee (例如添加新字段或为模型添加一些逻辑等),则需要删除_name = 'payModel.payModel'

If you want to create new table and use your new object you need to remove _inherit = 'hr.employee'. If you need to extend the hr.employee(for example add new fields or add some logic to model etc.) you need to remove _name = 'payModel.payModel'

第二个问题可能是依赖项.如果您的模块取决于 hr 模块,则需要在模块的 __ openerp __.py 中进行标记:

Second problem which can be it is dependencies. If your module depends from hr module you need to mark this in __openerp__.py of your module:

'depends': ['hr'],

还有一件事.确保将 models.py 导入到模块的 __ init __.py 中.在 .py 文件中进行更改后,请先重新启动openerp-server,然后再更新模块.如果不重新启动,Odoo不会在 .py 文件中看到更改.

And one more thing. Make sure that models.py is imported in __init__.py of your module. Restart openerp-server before updating your module after changes in .py files. Odoo does not see changes in .py files without restart.

希望这对您有所帮助.

这篇关于odoo 9-字段不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 23:14