模型"res.config.settings"中不存在字段

Field does not exist in model quot;res.config.settingsquot;(模型quot;res.config.settingsquot;中不存在字段)

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

问题描述

我要添加自定义Odoo模块的配置。但是,每当我尝试安装该模块时,都会收到以下错误。Odoo似乎看不到我创建的自定义模型。

odoo.exceptions.ValidationError: Error while validating view near:

                            <div class="o_setting_search">
                                <input type="text" class="searchInput pull-right p-0 pb-1" placeholder="Search..."/>
                                <span class="searchIcon"><i class="fa fa-search" role="img" aria-label="Search" title="Search"/></span>
                            </div>
                        </div>

Field "test_field" does not exist in model "res.config.settings"

./models/__init__.py

from . import res_config_settings

./models/res_config_settings.py

from odoo import api, fields, models


class ResConfigSettings(models.TransientModel):
    _inherit = "res.config.settings"
    _name = "test.settings"

    test_field = fields.Char(string="Test Field")

    @api.model
    def get_values(self):
        res = super(ResConfigSettings, self).get_values()
        test_config = self.env.ref('test_config', False)
        test_config and res.update(
            test_field=test_config.test_field,
        )
        return res

    def set_values(self):
        super(ResConfigSettings, self).set_values()
        test_config = self.env.ref('test_config', False)
        test_config and test_config.write({
            'test_field': self.test_field,
        })

views/settings.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <record id="res_config_settings_view_form" model="ir.ui.view">
    <field name="name">res.config.settings.view.form.inherit.test</field>
    <field name="model">res.config.settings</field>
    <field name="inherit_id" ref="base.res_config_settings_view_form" />
    <field name="arch" type="xml">
      <xpath expr="//div[hasclass('settings')]" position="inside">
        <div
          class="app_settings_block"
          data-string="Abcdefg Test Configuration"
          string="Abcdefg Test Configuration"
          data-key="odoo-abcdefg-test-module"
        >
          <h2>Test Configuration</h2>
          <group>
            <div class="row mt16 o_settings_container">
              <div class="o_setting_left_pane">
                <label for="test_field" string="Test Field"/>
                <field name="test_field"/>
              </div>
            </div>
          </group>
        </div>
      </xpath>
    </field>
  </record>
</odoo>

__init__.py

from . import models

__manifest__.py

{
    "name": "ABCDEFG Test Module",
    "version": "0.1.0",
    "category": "Testing",
    "application": False,
    "installable": True,
    "depends": ["base"],
    "data": [
        "views/settings.xml",
    ],
}

我做错了什么?

推荐答案

您将_nameinherit属性组合在一起,将生成名为test.settings的新模型。名为Classical inheritance。

若要将test_field添加到res.config.settings,只需删除_name属性。

这篇关于模型&quot;res.config.settings&quot;中不存在字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:模型&quot;res.config.settings&quot;中不存在字段

基础教程推荐