Odoo ParseError: "Invalid view definition Error detail : Model not found

人走茶凉 提交于 2020-01-03 05:27:13

问题


Please since yesterday I'm trying to install a module on Odoo 9 but I got this error:

Odoo ParseError: "Invalid view definition 
Error detail : 
Model not found: employee.register

Context of error :
View `employee.form`
[view_id: 547, xml_id: n/a, model: employee.register, parent_id: n/a]
None" while parsing /opt/odoo/addons/lci_gestpaie_tic/views/employee.xml:7, near

<record model="ir.ui.view" id="employee_form">
    <field name="name">employee.form</field>  
    <field name="model">employee.register</field>
    <field name="arch" type="xml">
        <form string="Employee">

            <label string="Nom"/>
            <field name="nom"/>

            <label string="Prenom"/>
            <field name="prenom"/>

            <label string="Date de Naissance"/>
            <field name="date_naissance"/>

            <label string="Lieu de naissance"/>
            <field name="lieu_naissance"/>

            <label string="CNI"/>
            <field name="cni"/>

            <label string="Salaire de Base"/>
            <field name="salaire_base"/>

            <label string="Date embauche"/>
            <field name="date_embauche"/>

            <label string="Sexe"/>
            <field name="sexe"/>

            <label string="Situation matrimoniale"/>
            <field name="situation_matrimoniale"/>

            <label string="Nombre enfants"/>
            <field name="nombre_enfant"/>

            <label string="Telephone"/>
            <field name="telephone"/>

            <label string="Email"/>
            <field name="email"/>
        </form>
    </field>
</record>

Here's the structure of my modules and my source code

my_module
    |models
        | __init__.py
        | emlpoyee.py
    |views
        | employee.xml
    __init__.py
    __openerp__.py

my_modules.init.py

import models

../models.init.py

import employee

../models.openerp.py

{
    'name': 'LCI',
    'version': '0.1',
    'category': 'LCI',
    'summary': """
        Summary of the module
    """,
    'author': 'LCI Sarl',
    'website': 'http://lcicm.com',
    'depends': ['base'],
    'data': ['views/employee.xml'],
    'installable': True,
    'auto_install': False,
}

../views.employee.xml

<?xml version="1.0" ?>
<openerp>
<data>

    <!--formulaire enregistrement-->
    <record model="ir.ui.view" id="employee_form">
        <field name="name">employee.form</field>  
        <field name="model">employee.register</field>
        <field name="arch" type="xml">
            <form string="Employee">

                <label string="Nom"/>
                <field name="nom"/>

                <label string="Prenom"/>
                <field name="prenom"/>

                <label string="Date de Naissance"/>
                <field name="date_naissance"/>

                <label string="Lieu de naissance"/>
                <field name="lieu_naissance"/>

                <label string="CNI"/>
                <field name="cni"/>

                <label string="Salaire de Base"/>
                <field name="salaire_base"/>

                <label string="Date embauche"/>
                <field name="date_embauche"/>

                <label string="Sexe"/>
                <field name="sexe"/>

                <label string="Situation matrimoniale"/>
                <field name="situation_matrimoniale"/>

                <label string="Nombre enfants"/>
                <field name="nombre_enfant"/>

                <label string="Telephone"/>
                <field name="telephone"/>

                <label string="Email"/>
                <field name="email"/>
            </form>
        </field>
    </record>

    <!--affichage de la liste des employes-->
    <record model="ir.ui.view" id="employee_tree">
        <field name="name">employee.tree</field>
        <field name="model">employee.register</field>
        <field name="type">tree</field>

        <field name="arch" type="xml">
            <tree string="Employee List">

                <field name="nom"/>
                <field name="prenom"/>
                <field name="date_naissance"/>
                <field name="lieu_naissance"/>
                <field name="cni"/>                  
                <field name="salaire_base"/>
                <field name="date_embauche"/>
                <field name="sexe"/>
                <field name="situation_matrimoniale"/>
                <field name="nombre_enfant"/>
                <field name="telephone"/>
                <field name="email"/>

            </tree>
        </field>
    </record>

    <!--actions qui seront executees-->
    <record model="ir.actions.act_window" id="action_employee">
        <field name="name">Employee</field>
        <field name="res_model">employee.register</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <!--nos differents menus-->
    <menuitem name="GestPaie" id="lci_gestpaie_tic"/>
    <menuitem name="Employee" id="employee_gestpaie_section" parent="lci_gestpaie_tic"/>
    <menuitem name="Create Employee" id="employee_register" parent="employee_gestpaie_section" action="action_employee"/>

</data>
</openerp>

../models/employee.py

from openerp import fields, models

class EmployeeRegister(models.Model):
    _name = 'employee.register'

    # attributs de Employee
    nom = fields.Char(required=True)
    prenom = fields.Char(required=True)
    date_naissance = fields.Date(required=True)
    lieu_naissance = fields.Char(required=True)
    cni = fields.Char(required=True)
    salaire_base = fields.Integer(required=True)
    date_embauche = fields.Date(required=True)
    sexe = fields.Char(required=True) # M pour Masculin, F pour Feminin
    situation_matrimoniale = fields.String()
    nbre_enfant = fields.Integer()
    telephone = fields.Char(required=True)
    email = fields.Char(required=True)

回答1:


i've resolved the problem it was a cache problem so i did

./openerp_server stop

then

./openerp_server stop



回答2:


In my_module/models/__init__.py should be a line that imports employee:

import employee



回答3:


Do this and it will work okay.

In my_module/models/init.py should be a line that imports employee:

from . import employee


来源:https://stackoverflow.com/questions/35650161/odoo-parseerror-invalid-view-definition-error-detail-model-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!