Milon Sarker
Milon Sarker

Reputation: 478

XML Parsing Error while Upgrading Custom Module

I'm new in Odoo. Created a simple custom module. It was working fine till when I've splitted xml file into two. Its giving below error while trying to upgrade my custom module:

The above exception was the direct cause of the following exception:

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"/>

Here are codes:

manifest.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
}

model : patient.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")

menu.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>

patient_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>

Upvotes: 0

Views: 889

Answers (2)

Thanh Kieu Cong
Thanh Kieu Cong

Reputation: 1

Actually, I don't know the root cause of the issue but here is my workaround below:

  1. In the manifest.py, rearrange the data sequence:

'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. Go to Settings -> Technical -> Actions (not Windows Actions). Find "Patients" and then Delete it.
  2. Go to Apps. Find your module (in this case Hospital Management) and then Upgrade. Done. It's working as expected. Hope this works for you!

P/s: Maybe we are facing this issue because we already created the Action "action_hospital_patient" following the tutorial video "5. How To Create Window Action In Odoo || Actions In Odoo - https://www.youtube.com/watch?v=XcVMcJYHuzc&list=PLqRRLx0cl0homY1elJbSoWfeQbRKJ-oPO&index=5"

Upvotes: 0

Kenly
Kenly

Reputation: 26688

From menuitem documentation:

action
if specified, the action attribute should be the external id of an action to execute when the menu is open.

Use the external id in the last menu item for the action:

om_hospital.action_hospital_patient

When loading the menu item, odoo will try to get the action database id if the action is set and valid.

You should load the menu.xml after the patient_view.xml, update the data entry in the manifest file to the following:

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

Upvotes: 2

Related Questions