How to create new module in odoo 13

How to create new module in odoo 13

how to create new module in odoo
how to create new module in odoo 13

How to create new module at odoo 13:

Odoo is an opensource business management software (ERP), you can build new module on odoo throw these :

Follow these steps to create new module on odoo, Create new directory inside your addons directory in Odoo files :

  1. Create __init__.py file inside your new module → which is required to make Python treat the directories as containing packages.
  1. Create __manifest__.py inside your new module→ which is to declare a python package as an Odoo module and to specify module metadata,

you can say its the file that have your module information, importing xml files in it which have your views menus … and on what module it depends.

  1. Create models folder: - this folder have your python files code which has classes, functions …
  1. Create security folder: - this folder have your module privilege: read, create, delete, modify for your module data and user.

Inside a file called (ir.model.access.csv) this is static file name which has privileges.

  1. static folder which has static file as css, js, images …

You can add icon (image) for your module inside it by default, following this structure directories:

static → description → your-image. To relate it to your module.

  1. views folder :- this folder used to add xml files which has views types, menus, …
  1. data folder:- this folder is used to add xml file in it to import demo data when installing your module
  1. report, wizard, controllers, i18n folders: these another folder you can import in your odoo module also but we will make it easy first to learn how to create basic new module in odoo,

Kindly note that these folder structure is the best way to handle, modifying, creating any new or exist module in odoo 13, so stay tuned to it

how to create new module on odoo

Here is an example code for creating new module on odoo :-


from . import models # to import the folder that has inside it python files.


# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
'name' : "Census jordan",
'version': '3.0',
'description' : """Census""",
'summary': 'Census',
'website': 'https://www.odoo.com',
'author' : "Hamza-Atieh",
'category' : " People counts",
'depends' : ['base', 'mail'], # this new module depends on what modules
'data' : ['security/census_security.xml',
], # inside data import your security, views, demo data , report .. files
'demo' : [],
'installable' : True,


how to create menu on new odoo module

<?xml version="1.0" encoding="utf-8"?>
<menuitem id="menu_root" name="Census"
sequence="75" groups="base.group_user" /> <!— this is the main menu for the module —>

<menuitem name="Census" parent="menu_root"
id="main_menu_census" sequence="10" />
<!— Sub menu of the main menu —>

Now let’s check the census_view.xml file which have the views : tree form …


<!—tree view example —>

how to create tree view on odoo module
<?xml version="1.0" encoding="utf-8"?>

<record id="view_census_entry_tree" model="ir.ui.view">
<field name="name">census.entry.tree</field> <!—class-name.tree —>
<field name="model">census.entry</field><!— class-name —>
<field name="arch" type="xml"><!—required field —>
<tree string="census"> <!—required field —>
<field name="name"/>
<field name="id_number"/>

<!— form view example—>

how to create form view on odoo module

<!— form view example—>
<record id="view_census_entry_form" model="ir.ui.view">
<field name="name">census.entry.form</field><!—class-name.form —>
<field name="model">census.entry</field> <!—class-name —>
<field name="arch" type="xml"> <!—required field —>
<form string="census"> <!—required field —>

<div class="oe_title">
<label for="name" class="oe_edit_only"/>
<field name="name" placeholder=" Person"/>
<div class="pull-left">
<label for="phone" class="oe_edit_only"/>
<field name="phone"/>
<page string="Citizen Info">
<group string="Information">
<field name="mothers_number_related"


<group string="Citizen Status-Birth">
<field name="birth" on_change="onchange_get_age(birth,context)"/>

<div class="oe_chatter"> <!—for form logging how change on record down of the record —>
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>

<!—search view example —>how to create search view on odoo module
<!—search view example —>
<record id="census_entry_view_search" model="ir.ui.view">
<field name="name">census.entry.search</field>
<field name="model">census.entry</field>
<field name="arch" type="xml">
<search string="Census">
<field name="id_number" string="By Identification Number"/>
<filter name ="Male" icon="terp-document-new" domain="[('gender','=','male')]" string="Mens"/>
<filter name ="Female" icon="terp-dolar" domain="[('gender','=','female')]" string="Girls"/>
<group expand="1" string="Group By">
<filter name= "City" string="City" icon="terp-personal" domain="[]" context="{'group_by':'city'}"/>

<!—action example —>
<!— To connect Tree, form, kanban , search…. , this action id will be reference in the menu —>
<record id="action_census_entry" model="ir.actions.act_window">
<field name="name">Census</field>
<field name="res_model">census.entry</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="census_entry_view_search"/>
<field name="domain">[]</field><!— ('user_id', '=', uid) —>
<field name="view_id" ref="view_census_entry_tree"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to Add population

<menuitem id="menu_census_entry" action="action_census_entry"
parent="main_menu_census" name="Census Entry" sequence="1"/>



from odoo import api, fields, models, _
from datetime import date

class census_entry(models.Model):

_name = "census.entry" # class name which is used in form, tree, search, action … views
_description = "Census population for Jordan"
_inherit = ['mail.thread'] # so you can import log user down of module in the form view
_rec_name = 'id_number' # primary field

name = fields.Char('Name Of Citizen', required=True)
id_number = fields.Char('ID Number', required=True)

_sql_constraints = [('id_number_unique', 'unique(id_number)', 'This ID number is already used!')]

python class

__init__.py file inside models folder :
from . import census


security folder

security privilege in odoo

ir.model.access.csv file for privileges inside security folder :-

  • id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink 

ir.model.access.csv security file in odoo 13

  • These four numbers is for : create, read, write, unlike(delete) which value can be 0 or 1.

Finally you can install the module training example from github to continue learning on odoo from this link, but kindly when you install it take T_census directory only with out T_census-master and but it in your addons directory.

© 2020 PyOdoo.