How to Create a Custom Module in Odoo 15

Custom_addons

Add this path on odoo.conf file
addons_path = C:\public\Ravi Gupta\odoo15.0\addons,custom_addons

Restaurant_Project

__init__.py
from . import model
__manifest__.py
# -*- coding: utf-8 -*-
{
'name': "Restaurant Project",
'version' : "15.0.1",

'summary': """Restaurant Project will help in the management of Restaurant""",
'sequence' : -101,

'description': """Manage All Data In your Description""",
# Categories can be used to filter modules in modules listing
'category': 'Learn',
'website' : "https://www.odoo.com/",

'author': "My Company",
'website': "http://www.yourcompany.com",
# any module necessary for this one to work correctly
'depends': ['base'],

'data': [

'security/ir.model.access.csv',
'views/staff_views.xml',
'views/menu_views.xml',
],
# only loaded in demonstration mode
'demo': [
],
'installable': True,
'application': True,
'auto_install': False,
'license' : 'LGPL-3',
}

models

__init__.py
from . import res_staff
res_staff.py
from odoo import models, fields,api

class RestStaff(models.Model):
_name = 'res.staff' # (This is object of Model) This name write in security file res_staff
_description = 'this model store the data of staff'

name = fields.Char(string="Name",size=50)
age = fields.Integer(string="Age")
dob = fields.Date(string="Dob")
mobile = fields.Char(string="Mobile")
email = fields.Char(string="Email")

Security

ir_security_access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_rest_staff,res.staff,model_res_staff,base.group_user,1,1,1,1

views

menu_views.xml
<odoo>
<menuitem id="rest_main_menu" name="Restaurant"/>
<menuitem id="rest_staff_submenu" name="Our Team" parent="restaurant_project.rest_main_menu" action="restaurant_project.res_staff_action_id"/>
</odoo>
staff_views.xml
<odoo>
<!-- This is form View-->
<record model="ir.ui.view" id="res_staff_form_view_id">
<field name="name">res.staff.form.view.id</field>
<field name="model">res.staff</field>
<field name="arch" type="xml">
<form string="Staff Form">
<sheet>
<!-- For show label of form we create a group-->
<group>
<group>
<field name="name"/>
<field name="age"/>
<field name="dob"/>
</group>
<group>
<field name="mobile"/>
<field name="email"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<!-- This is Tree View (List View)-->
<record model="ir.ui.view" id="res_staff_tree_view_id">
<field name="name">res.staff.tree.view.id</field>
<field name="model">res.staff</field>
<field name="arch" type="xml">
<tree string="Staff Tree">
<field name="name"/>
<field name="age"/>
<field name="dob"/>
<field name="mobile"/>
<field name="email"/>
</tree>
</field>
</record>

<!-- This is Kanban View -->
<record id="res_staff_kanban_view_id" model="ir.ui.view">
<field name="name">res.staff.kanban.view.id</field>
<field name="model">res.staff</field>
<field name="arch" type="xml">
<kanban class="o_res_restaurant_kanban">
<field name="name"/> <!-- Include field entry which u call in kanban box -->
<field name="mobile"/>
<field name="email"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_global_click">
<div class="oe_kanban_details">
<strong class="o_kanban_record_title">
<field name="name"/>
</strong>
<div t-if="record.mobile.value">
<t t-esc="record.mobile.value"/>
</div>
<div t-if="record.email.value">
<t t-esc="record.email.value"/>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>

<!-- This is Calendra View (List View)-->
<record id="res_staff_calendar_view_id" model="ir.ui.view">
<field name="name">res.staff.calendar.view.id</field>
<field name="model">res.staff</field>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<calendar date_start="dob" string="Tasks" mode="month" color="name" event_limit="5"
hide_time="true" js_class="project_calendar" event_open_popup="true" quick_add="false">
<field name="name"/>
<field name="age"/>
<field name="dob"/>
<field name="mobile"/>
<field name="email"/>
</calendar>
</field>
</record>

<!-- This is for search-->
<record id="res_staff_search_view_id" model="ir.ui.view">
<field name="name">res.staff.search.view.id</field>
<field name="model">res.staff</field>
<field name="arch" type="xml">
<search string="Search destination">
<field name="name"/>
<field name="age"/>
</search>
</field>
</record>

<!-- This is For Action (Here you can add all type of view)-->
<record model="ir.actions.act_window" id="res_staff_action_id">
<field name="name">Staff (Our Team)</field>
<field name="res_model">res.staff</field>
<field name="view_mode">kanban,tree,form,calendar</field>
<field name="help" type="html">
<p class="o_view_nocontent_empty_folder">
There is no Record added Yet
</p>
</field>

</record>
</odoo>

Leave a Comment

Your email address will not be published. Required fields are marked *