如何解决 odoo 12 模块创建中的 raise Validation Error(_('Invalid model name in action definition.')
How to solve raise Validation Error(_('Invalid model name in action definition.') in odoo 12 module creation
我想在 windows 10 中的 odoo 12 中创建 "School" 模块。我已经创建了所有需要的文件,例如
init.py, manifest.py, model/_init__.py, model/_init__.py, model/student. py, views/student_view.xml"
下面给出了我的代码示例
init.py
import model
清单.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>
当我安装到 odoo 12 中然后遇到类似的问题
提高 ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
这是错误
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>
请帮我解决这个问题。
谢谢。
您将模型 res_model 设为 "student",但您的模型名称是 student.student,这就是为什么它会提示您模型定义无效的错误。
我想在 windows 10 中的 odoo 12 中创建 "School" 模块。我已经创建了所有需要的文件,例如 init.py, manifest.py, model/_init__.py, model/_init__.py, model/student. py, views/student_view.xml"
下面给出了我的代码示例
init.py
import model
清单.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>
当我安装到 odoo 12 中然后遇到类似的问题 提高 ValidationError(_('Invalid model name %r in action definition.') % action.res_model) 这是错误
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>
请帮我解决这个问题。 谢谢。
您将模型 res_model 设为 "student",但您的模型名称是 student.student,这就是为什么它会提示您模型定义无效的错误。