我正在使用 Odoo 14 并在安装用于自动休假分配的自定义模块时出现以下错误。这是一个在 Odoo 12 中工作的模块。我不知道我哪里出错了。想要在设置 > 员工 > 工作组织下创建一个新的两个字段。
Field "holiday_status_id" does not exist in model "res.config.settings"
View name: res.config.settings.view.form.inherit.hr.auto.leaves
Error context:
view: ir.ui.view(565,)
xmlid: res_config_settings_view_form
view.model: res.config.settings
view.parent: ir.ui.view(477,)
file: c:\users\training\desktop\odoo14\venv\scripts\odoo\addons\hr_auto_leaves\views\res_config_settings_views.xml
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\base\models\ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 359, in _call_function
return checked_call(self.db, *args, **kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\service\model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 347, in checked_call
result = self.endpoint(*a, **kw)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 912, in __call__
return self.method(*args, **kw)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 531, in response_wrap
response = f(*args, **kw)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\web\controllers\main.py", line 1381, in call_button
action = self._call_kw(model, method, args, kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\web\controllers\main.py", line 1369, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\api.py", line 396, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\api.py", line 383, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-71>", line 2, in button_immediate_install
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\base\models\ir_module.py", line 73, in check_and_log
return method(self, *args, **kwargs)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\base\models\ir_module.py", line 474, in button_immediate_install
return self._button_immediate_function(type(self).button_install)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\addons\base\models\ir_module.py", line 592, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\modules\registry.py", line 89, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\modules\loading.py", line 455, in load_modules
loaded_modules, update_module, models_to_check)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\modules\loading.py", line 348, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\modules\loading.py", line 221, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\modules\loading.py", line 69, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\tools\convert.py", line 733, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\tools\convert.py", line 799, in convert_xml_import
obj.parse(doc.getroot())
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\tools\convert.py", line 719, in parse
self._tag_root(de)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\tools\convert.py", line 685, in _tag_root
)) from e
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:\Users\Training\Desktop\odoo14\venv\Scripts\odoo\http.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing file:/c:/users/training/desktop/odoo14/venv/scripts/odoo/addons/hr_auto_leaves/views/res_config_settings_views.xml:3, near
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.hr.auto.leaves</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="70"/>
<field name="inherit_id" ref="hr.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='work_organization_setting_container']" position="inside">
<div class="o_setting_right_pane">
<field name="auto_leave_allocation"/>
</div>
<div class="o_setting_right_pane">
<label for="auto_leave_allocation"/>
<div class="text-muted">
Automatic allocation of leave to the new employees.
</div>
</div>
</xpath>
<xpath expr="//div[@id='default_company_schedule_setting']" position="inside">
<div class="o_setting_left_pane">
<label for="holiday_status_id"/>
<div class="content-group">
<div class="mt16">
<field name="holiday_status_id" widget="many2many_tags" placeholder="Select Leave Type"/>
</div>
</div>
</div>
</xpath>
</field>
</record>
这是我的 res_config_settings.py 文件。在这里,我继承了表'res.config.settings'。我想创建两个新字段,即 holiday_status_id 和 auto_leave_allocation。请帮帮我。
# -*- coding: utf-8 -*-
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
holiday_status_id = fields.Many2many('hr.leave.type', string="Leave Types")
auto_leave_allocation = fields.Boolean(string="Automatic Leave Allocation")
这是视图文件。在视图文件中,我相信我已经正确编写了 xpath。我真的不知道我哪里出错了。
<?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.hr.auto.leaves</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="70"/>
<field name="inherit_id" ref="hr.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='work_organization_setting_container']" position="inside">
<div class="o_setting_right_pane">
<field name="auto_leave_allocation"/>
</div>
<div class="o_setting_right_pane">
<label for="auto_leave_allocation"/>
<div class="text-muted">
Automatic allocation of leave to the new employees.
</div>
</div>
</xpath>
<xpath expr="//div[@id='default_company_schedule_setting']" position="inside">
<div class="o_setting_left_pane">
<label for="holiday_status_id"/>
<div class="content-group">
<div class="mt16">
<field name="holiday_status_id" widget="many2many_tags" placeholder="Select Leave Type"/>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>