简体   繁体   中英

menu item and its action didn't work in odoo13

I started to learn odoo13 latterly and I am trying to add an appointment menu item to my app in the same steps I did with the patient menu item & didn't work so these are the steps that I did

  1. inside the model folder that I have created I put my appointment.py file

    from odoo import fields, models, api, _ class HospitalAppointment(models.Model): _name = "hospital.appointment" _inherit = ['mail.thread', 'mail.activity.mixin'] _description = "Appointment For Patients" @api.model def create(self, vals): if vals.get('name', _('New')) == _('New'): vals['name'] = self.env['ir.sequence'].next_by_code('hospital.appointment') or _('New') result = super(HospitalAppointment, self).create(vals) return result name = fields.Char(string='Appointment ID', required=True, copy=False, readonly=True, index=True, default=lambda self: _('New')) # patient_id = fields.Integer('ID Number') patient_id = fields.Many2one('hospital.patient', string='Patient', required=True) patient_age = fields.Integer('Age') notes = fields.Text(string='Registration Notes') appointment_date = fields.Date(string='Date', required=True)```
  2. code inside init .py file that is inside models folder

from . import patient
from . import appointment
  1. code inside appointment.xml file that is inside view folder
<?xml version="1.0" encoding="utf-8"?>

<odoo>

     <!--defining tree view for appointment model-->
     <record id="appointment_tree" model="ir.ui.view">
            <field name="name">hospital.appointment.tree</field>
            <field name="model">hospital.appointment</field>
            <field name="arch" type="xml">
               <tree string="Appointments">
                   <field name="name"/>
                   <field name="patient_id"/>
                   <field name="patient_age"/>
                   <field name="appointment_date"/>
               </tree>
            </field>
     </record>

      <!--defining form view for appointment model-->
     <record id="appointment_form" model="ir.ui.view">
            <field name="name">hospital.appointment.form</field>
            <field name="model">hospital.appointment</field>
            <field name="arch" type="xml">
                <form string="Appointments">
                    <sheet>
                         <div class="oe_title">
                        <h1>
                            <field name="name" />
                        </h1>
                        </div>
                   <group>
                        <group>
                                <field name="patient_age"/>
                                <field name="patient_id"/>
                        </group>
                        <group>
                                <field name="appointment_date"/>
                        </group>
                    </group>
                        <group>

                            <field name="notes"/>
                        </group>
                    </sheet>
                     <div class="oe_chatter">
                        <field name="message_follower_ids" widget="mail_followers"/>
                        <field name="activity_ids" widget="mail_activity"/>
                        <field name="message_ids" widget="mail_thread" options="{'post_refresh': 'recipients'}"/>
                     </div>
                </form>
            </field>
        </record>

        <!--    action of the appointment menu-->
     <record id="action_appointment" model="ir.actions.act_window">
            <field name="name">Appointments</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">hospital.appointment</field>
            <field name="view_type">form</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 Appointment!
              </p>
            </field>
     </record>

    <menuitem id="hospital_appointment"
              name="Appointment"
              parent="hospital_root"
              action="action_appointment"
               sequence="1"/>

</odoo>
  1. included the XML file in the data too in manifest .py file
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

{
    'name': 'Hospital Management',
    'version': '1.0',
    'summary': 'Hospital Management Software',
    'category': 'Productivity',
    'depends': [
        'mail',
        'sale'
    ],
    'data': [
        'security/ir.model.access.csv',
        'data/sequence.xml',
        'views/patient.xml',
        'views/appointment.xml'
    ],
    'application': True,
    'installable': True,
    'auto_install': False,
}

please help me find why odoo doesn't create my menu item? I tried to restart the server many times too

Make sure the root menu id is the same as you declared in parent="hospital_root"

for exemple:

<menuitem id="menu_hospital_root"
          name="Hospital"/>

Child menu:

 <menuitem id="menu_appointment"
           name="Appointments"
           parent="menu_hospital_root""/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM