【问题标题】:Odoo does not find modelOdoo 找不到模型
【发布时间】:2018-07-18 23:45:30
【问题描述】:

我正在编写自定义 odoo 模块,其中包含一些可由用户设置的配置。 因此,我创建了一个res_config.py,其中包含:

# -*- coding: utf-8 -*-
from openerp import models, fields, api


class mymodule_configuration(models.TransientModel):
  _name = 'mymodule.config.settings'
  _inherit = 'res.config.settings'

  default_myfield = fields.Char(
    string='my description',
    required=True,
    help="mydescription",
    default_model='mymodule.config.settings',
  )

作为一个视图,我创建了views/resconfigview.xml

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
        <record id="view_mymodule_configuration" model="ir.ui.view">
          <field name="name">mymodule configuration</field>
          <field name="model">mymodule.config.settings</field>
          <field name="arch" type="xml">
            <form string="mymodule configuration"
                  class="oe_form_configuration">
                <sheet>
                    <div>
                        <button string="Apply"
                                type="object"
                                name="execute"
                                class="oe_highlight" />
                        or
                        <button string="Cancel"
                                type="object"
                                name="cancel"
                                class="oe_link" />
                    </div>

                    <group string="My Settings">
                        <field name="default_myfield" />
                    </group>

[..]

当我安装模块时,服务器响应 500。在日志文件中,我发现:

Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Konnte Modell nicht finden: mymodule.config.settings

英文留言:Could not find model: mymodule.config.settings。 所以在视图中,我的配置模型是不可访问的。

有什么想法吗?

【问题讨论】:

  • 您是否将import res_config 添加到您的__init__.py 中?

标签: odoo odoo-8


【解决方案1】:

从您的模型中删除 _name = 'mymodule.config.settings',因为您继承了现有模型,因此无需定义新名称,否则它将创建新模型。

然后您在新模型中定义的字段将无法在继承模型中访问。

在 xml 中更新这一行。

 <field name="model">res.config.settings</field>

在模型之后的 xml 视图中再添加一行

<field name="priority" eval="50" />

同时删除default_model='mymodule.config.settings',

default_myfield = fields.Char(string='my description',required=True,help="mydescription",)

你错过了继承res.config.settings的主视图

<field name="inherit_id" ref="set view id here"/>

【讨论】:

  • 感谢您的回答 - 这导致另一个异常:找不到“default_myfield”。在模型中,我将“default_model”参数更改为“res.config.settings”。
  • 我已经更新了答案。您需要重新启动 odoo 服务并更新您的模块。
  • 好的,我根据你的更新更新了视图中的字段名,重启了Odoo,但是异常还是一样。
  • 可能存在顺序问题,请查看更新后的答案并再次更新您的模块。
  • 我在您的代码中发现的字段声明的另一个问题,请参阅我有更新的答案。列结构的变化需要更新模块。
【解决方案2】:

确保您将mymodule.config.settings 导入您的__init__.py 文件并运行此命令来保存您的文件

./odoo-bin -u your module name

应该能帮你解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多