简体   繁体   中英

Odoo does not find model

I'm writing as custom odoo module, with some configuration that can be set by the user. Therefore, I created a res_config.py containing:

# -*- 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',
  )

As a view, I created 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>

[..]

When I install the module, the server resonds with a 500. In the logfile, I find:

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

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

Message in english: Could not find model: mymodule.config.settings . So in the view, my config model is not accessible.

Any idea?

Remove _name = 'mymodule.config.settings' from your model, because you are inherit the existing model so no need to define new name other wise it will create new model.

And then fields you have defined in new model will not be accessible in the inherited model.

Update this line in xml.

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

Add one more line to the xml view after model

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

Also remove default_model='mymodule.config.settings',

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

You missed to inherit main view of res.config.settings

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

I got the same issue but i followed STEPS and resolved my issue. You can use the step on the given link and i hope you will resolve your issue.

make sure you import the mymodule.config.settings in your __init__.py file and also run this command to save your files

./odoo-bin -u your module name

That shoud help you solve the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM