Search code examples
odooodoo-viewodoo-13

Odoo 13 - multiple model and menus in same module


I'm new to odoo and learning developing custom module. Trying to develop an contact management app for company and person. Following are the files and code structure:

#models.py
from odoo import models, fields, api


class company(models.Model):
    _name = 'cs_contact.company'
    _description = 'Model for create company profile.'

    name = fields.Char('Company name', required=True)
    country_id = fields.Many2one('res.country', string='Country', help='Select Country', ondelete='restrict', required=True)
    ho_address = fields.Text('HO address')
    website = fields.Char('Website')
    courier_account = fields.Char('Courier Account')
    email = fields.Char('Email')
    

class person(models.Model):
    _name = 'cs_contact.person'
    _description = 'Model for create person contact.'

    name = fields.Char('Full Name', required=True)
    country_id = fields.Many2one('res.country', string='Country', help='Select Country', ondelete='restrict', required=True)
    email = fields.Char('Email')
    im_id = name = fields.Char('Instant messaging ID (Skype/line)')
    worked_before = fields.Selection([
        ('Yes', 'Yes'),
        ('No', 'No'),
        ], string="Worked Before?")
    how_we_meet = fields.Selection([
        ('Fair', 'Fair'),
        ('Email', 'Email'),
        ('Agent', 'Agent'),
        ], string="How we meet?")
    quantity = fields.Integer(string='Quantity')
    note = fields.Text('Note')

Views looke like:

#views.xml
<odoo>
  <data>
    <!-- explicit list view definition -->

    <record model="ir.ui.view" id="cs_contact.list">
      <field name="name">cs_contact list</field>
      <field name="model">cs_contact.person</field>
      <field name="arch" type="xml">
        <tree>
            <field name="name"/>
            <field name="country_id" />
            <field name="email"/>
        </tree>
    </field>      
    </record>

    <record id="view_cs_contactsearch" model="ir.ui.view">                                
      <field name="name">cs_contact list</field>
      <field name="model">cs_contact.person</field>                            
      <field name="arch" type="xml">                                    
        <search string="Search contacts">                                        
          <field name="name"></field>                                        
          <field name="country_id"></field>                                        
          <field name="email"></field>
        </search>

      </field>   

    </record>

  </data>
</odoo>

Menu looks like:

#menu.xml
<odoo>
  <act_window  id="action_company" name=" Company Contacts" res_model="cs_contact.company" view_mode="tree,form"  />  

  <menuitem  id="contact_root" name="Contacts" sequence='-1' />
  <menuitem  id="contact_company" name="Company" parent="contact_root" action="action_company" sequence="-1" />

</odoo>

It's working fine for company contact. Now I'm not getting how to create top menu for person and define view. This is the the design I want. I tried various method from blogs but didn't work. Please help me out.


Solution

  • You have added country_id in cs_contact.person view definition but the field does not exist. Remove it from the view definition or declare it in the corresponding model.

    To add the Person menu item next to the Company menu item, you just need to use the same parent and higher sequence number then connect it to the corresponding action.

    Example:

    <act_window id="action_person" name="Persons" res_model="cs_contact.person" view_mode="tree,form"/>
    <menuitem id="contact_person" name="Person" parent="contact_root" action="action_person" sequence="2"/>