Skip to Content
Menu
This question has been flagged
3 Replies
16161 Views


I want to create "School" module in odoo 12 in windows 10. I have created all require file like init.py, manifest.py, model/_init__.py, model/_init__.py, model/student.py, views/student_view.xml"

My code sample given bellow

init.py

import model

manifest.py

# -*- coding: utf-8 -*-
{
    'name': 'School',
    'version': '12.0.1.0.0',
    'summary': 'Record Student Information',
    'category': 'Tools',
    'author': 'Niyas Raphy',
    'maintainer': 'Cybrosys Techno Solutions',
    'company': 'Cybrosys Techno Solutions',
    'website': 'https://www.cybrosys.com',
    'depends': ['base'],
    'data': [
        'views/student_view.xml'
    ],
    'images': [],
    'license': 'AGPL-3',
    'installable': True,
    'application': False,
    'auto_install': False,
}

model/_init__.py

from. import student

model/student.py

from odoo import models, fields

 class StudentStudent(models.Model):
    _name = 'student.student'

    name = fields.Char(string='Name', required=True)

views/student_view.xml

<?xml version="1.0" encoding="UTF-8"?>
 <odoo>
    <data>
        <record id="student_menu_action" model="ir.actions.act_window">
            <field name="name">Students</field>
            <field name="res_model">student.student</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Student
                </p>
            </field>
</record>
        <menuitem id="school_menu"
                name="School"/>
        <menuitem id="school_student_menu" parent="school_menu" name="Student"/>
    </data>
</odoo>

When i install into odoo 12 then facing issue like raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model) Here is the error

Odoo Server Error
Traceback (most recent call last):
  File "F:\Odoo\server\odoo\tools\convert.py", line 758, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "F:\Odoo\server\odoo\tools\convert.py", line 663, in _tag_record
    record = model.with_context(rec_context)._load_records([data], self.mode == 'update')
  File "F:\Odoo\server\odoo\models.py", line 3865, in _load_records
    records = self._load_records_create([data['values'] for data in to_create])
  File "F:\Odoo\server\odoo\models.py", line 3779, in _load_records_create
    return self.create(values)
  File "<decorator-gen-37>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 238, in create
    return super(IrActionsActWindow, self).create(vals_list)
  File "<decorator-gen-35>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 59, in create
    res = super(IrActions, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "F:\Odoo\server\odoo\models.py", line 3560, in create
    records = self._create(data_list)
  File "F:\Odoo\server\odoo\models.py", line 3692, in _create
    records._validate_fields(name for data in data_list for name in data['stored'])
  File "F:\Odoo\server\odoo\models.py", line 1108, in _validate_fields
    check(self)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 141, in _check_model
    raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
odoo.exceptions.ValidationError: ("Invalid model name 'student' in action definition.", None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\Odoo\server\odoo\http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "F:\Odoo\server\odoo\http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "F:\Odoo\server\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "F:\Odoo\server\odoo\http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "F:\Odoo\server\odoo\http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "F:\Odoo\server\odoo\service\model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "F:\Odoo\server\odoo\http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "F:\Odoo\server\odoo\http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "F:\Odoo\server\odoo\http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "f:\odoo\server\odoo\addons\web\controllers\main.py", line 966, in call_button
    action = self._call_kw(model, method, args, {})
  File "f:\odoo\server\odoo\addons\web\controllers\main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "F:\Odoo\server\odoo\api.py", line 749, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "F:\Odoo\server\odoo\api.py", line 736, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-61>", line 2, in button_immediate_install
  File "f:\odoo\server\odoo\addons\base\models\ir_module.py", line 74, in check_and_log
    return method(self, *args, **kwargs)
  File "f:\odoo\server\odoo\addons\base\models\ir_module.py", line 445, in button_immediate_install
    return self._button_immediate_function(type(self).button_install)
  File "f:\odoo\server\odoo\addons\base\models\ir_module.py", line 561, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "F:\Odoo\server\odoo\modules\registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "F:\Odoo\server\odoo\modules\loading.py", line 421, in load_modules
    loaded_modules, update_module, models_to_check)
  File "F:\Odoo\server\odoo\modules\loading.py", line 313, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "F:\Odoo\server\odoo\modules\loading.py", line 222, in load_module_graph
    load_data(cr, idref, mode, kind='data', package=package, report=report)
  File "F:\Odoo\server\odoo\modules\loading.py", line 68, in load_data
    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
  File "F:\Odoo\server\odoo\tools\convert.py", line 802, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "F:\Odoo\server\odoo\tools\convert.py", line 865, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "F:\Odoo\server\odoo\tools\convert.py", line 755, in parse
    self.parse(rec, mode)
  File "F:\Odoo\server\odoo\tools\convert.py", line 764, in parse
    exc_info[2]
  File "F:\Odoo\server\odoo\tools\pycompat.py", line 86, in reraise
    raise value.with_traceback(tb)
  File "F:\Odoo\server\odoo\tools\convert.py", line 758, in parse
    self._tags[rec.tag](rec, de, mode=mode)
  File "F:\Odoo\server\odoo\tools\convert.py", line 663, in _tag_record
    record = model.with_context(rec_context)._load_records([data], self.mode == 'update')
  File "F:\Odoo\server\odoo\models.py", line 3865, in _load_records
    records = self._load_records_create([data['values'] for data in to_create])
  File "F:\Odoo\server\odoo\models.py", line 3779, in _load_records_create
    return self.create(values)
  File "<decorator-gen-37>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 238, in create
    return super(IrActionsActWindow, self).create(vals_list)
  File "<decorator-gen-35>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 59, in create
    res = super(IrActions, self).create(vals_list)
  File "<decorator-gen-3>", line 2, in create
  File "F:\Odoo\server\odoo\api.py", line 452, in _model_create_multi
    return create(self, arg)
  File "F:\Odoo\server\odoo\models.py", line 3560, in create
    records = self._create(data_list)
  File "F:\Odoo\server\odoo\models.py", line 3692, in _create
    records._validate_fields(name for data in data_list for name in data['stored'])
  File "F:\Odoo\server\odoo\models.py", line 1108, in _validate_fields
    check(self)
  File "f:\odoo\server\odoo\addons\base\models\ir_actions.py", line 141, in _check_model
    raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
odoo.tools.convert.ParseError: "Invalid model name 'student' in action definition.
None" while parsing file:/f:/odoo/server/odoo/addons/school/views/student_view.xml:4, near
<record id="student_menu_action" model="ir.actions.act_window">
            <field name="name">Students</field>
            <field name="res_model">student</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Student
                </p>
            </field>
</record>

Please help me how to solve this issue. Thanks.


Avatar
Discard
Best Answer

You need to just put correct model name in action 

<field name="res_model">student</field> 
should be 
<field name="res_model">student.student</field>
Avatar
Discard
Best Answer

his document

<record id="student_menu_action" model="ir.actions.act_window">
            <field name="name">Students</field>
            <field name="res_model">student.student</field>
            <field name="view_type">form</field>
you see he put student.student yet,
 <field name="res_model">student.student</field>

and his is right here
_name = 'student.student'
The solution is very simple: you need to reboot (sudo reboot), after you make same names ( student.student ) in above two places. if you not, you will not install the self made module.
Avatar
Discard
Best Answer

Hi,

You have given the model name wrongly in the XML file, in the Python File you have defined the model with the name student.student and in the Xml you specified the model name as Student. 

What you have to do is that update the model name as below:-

<record id="student_menu_action" model="ir.actions.act_window">
<field name="name">Students</field>
<field name="res_model">student.student</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create The First Student
</p>
</field>
</record>

Hope you referred this Blog:  How to Create a Module in Odoo 12

If you are in the starting stage of the odoo development, I will suggest you to have a look at this Videos

1. How To Create Custom Module in Odoo12 - Manifest File

2. Create New Model

3. Define New Menu and Actions in Odoo

4. How To Define Tree and Form View In Odoo


Thanks

Avatar
Discard
Related Posts Replies Views Activity
6
Jan 23
11270
0
Aug 19
3090
3
Aug 19
3726
2
Jun 20
5603
0
Apr 19
2142