升级自定义模块时出现 XML 解析错误

问题描述 投票:0回答:2

我是 Odoo 的新手。创建了一个简单的自定义模块。它工作正常,直到我将 xml 文件分成两部分。尝试升级我的自定义模块时出现以下错误:

上述异常是导致以下异常的直接原因:

Traceback (most recent call last):
  File "D:\Odoo\Odoo_15\odoo\odoo\http.py", line 643, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "D:\Odoo\Odoo_15\odoo\odoo\http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
odoo.tools.convert.ParseError: while parsing file:/d:/odoo/odoo_15/custom_addons/om_hospital/views/menu.xml:17, somewhere inside
<menuitem id="menu_patient" name="Patient" action="action_hospital_patient" parent="menu_patient_master" sequence="0"/>

以下是代码:

清单.py:

{
    'name': 'Custom Hospital Management by Milon',
    'version': '1.0.0',
    'category': 'Hospital Maanagement',
    'author': 'Milon Sarker',
    'summary': 'Its a custom system',
    'description': 'Its a custom system bro',
    'depends': [],
    'data': [
        'views/menu.xml',
        'views/patient_view.xml',
    ],
    'installable': True,
    'auto_install': False,
    'application': True,
    'sequence': -100
}

模型:患者.py:

from odoo import api, fields, models

class hospitalPatient(models.Model):
    _name = 'hospital.patient'
    _description = 'Hospital Patient'
    name = fields.Char(string = 'Name')
    age = fields.Integer(string = "Age")
    gender = fields.Selection([('male','Male'), ('female', 'Female')], string = "Gender")

菜单.xml:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <menuitem id = "menu_hospital_root"
              name = "Hospital"
              sequence = "0"
    />
    <menuitem id = "menu_patient_master"
              name = "Patient Details"
              parent = "menu_hospital_root"
              sequence = "0"
    />
    <menuitem id="menu_patient"
              name="Patient"
              action="action_hospital_patient"
              parent="menu_patient_master"
              sequence="0"
    />
</odoo>

患者_view.xml:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id = "action_hospital_patient" model = "ir.actions.act_window">
        <field name="name">Patients</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">hospital.patient</field>
        <field name="view_mode">tree,form,</field>
        <field name="context">{}</field>
        <field name="help" type = "html">
            <p class = "o_view_nocontent_smiling_face">
                Create your first patient!
            </p>
        </field>
    </record>
</odoo>
odoo odoo-15
2个回答
1
投票

来自 menuitem 文档:

action
如果指定,action 属性应该是菜单打开时要执行的操作的外部 id。

使用最后一个菜单项中的外部 id 来表示

action
:

om_hospital.action_hospital_patient

加载菜单项时,如果操作已设置且有效,odoo 将尝试获取操作数据库 ID

您应该在

menu.xml
之后加载
patient_view.xml
,将清单文件中的
data
条目更新为以下内容:

'data': [
    'views/patient_view.xml',
    'views/menu.xml',
],

0
投票

实际上,我不知道问题的根本原因,但以下是我的解决方法:

  1. manifest.py中,重新排列数据顺序:

'data':[
        'security/ir.model.access.csv',
         # Define action in patient views before their references
        'views/patient_view.xml',
        'views/menu.xml', # Last because referencing actions defined in previous files
    ],

  1. 转到“设置”->“技术”->“操作”(不是 Windows 操作)。找到“患者”,然后将其删除。
  2. 转到应用程序。找到您的模块(在本例中为医院管理),然后升级。 完毕。它按预期工作。希望这对你有用!

P/s:也许我们面临这个问题是因为我们已经按照教程视频“5.如何在 Odoo 中创建窗口操作 || Odoo 中的操作 - https://www.youtube.com”创建了操作“action_hospital_ Patient” /watch?v=XcVMcJYHuzc&list=PLqRRLx0cl0homY1elJbSoWfeQbRKJ-oPO&index=5"

© www.soinside.com 2019 - 2024. All rights reserved.