-
In the
custom_addons
directory create your own module ex.real_estate
,km_hospital
etc. known as technical name. In the module minimum two file is mandatory, one is__init__.py
and the other is__manifest__.py
. -
A demo template for
__manifest__.py
:{ 'name': "Real Estate", 'sequence': 10, 'summary': """ A real estate module where one can add properties info for advertising purposes""", 'description': """ A real estate module where one can add properties info for advertising purposes""", 'author': "Kamrul", 'website': "http://www.yourcompany.com", 'category': 'Uncategorized', 'version': '0.1', 'license': 'LGPL-3', 'depends': ['base'], 'data': [], 'demo': [], 'installable' : True, 'application' : True, 'auto_install' : False, }
Look up the code and try to implement:
-
Run the odoo server using this command:
/opt/odoo/odoo14/./odoo-bin --addons-path=/opt/odoo/odoo14/addons,/opt/odoo/odoo14/custom_addons --xmlrpc-port=8014
-
In the odoo app list search module name
km_hospital
and you will find the app. In theModule Info
you will find all the information given in the__manifest__.py
file. You can also install and upgrade the app.
-
Here is the general structure of a module. Ex.
km_hospital
controllers
: contains (.py) files and all the requests are handled from the browsers and pass to server.models
: contains all the python (.py) filesreports
: contains python and xml file to create and design report.security
: holds access rights of the models.views
: contains all the.xml
files for different viewswizard
: contains python and xml file to create a modal window.__init__.py
: contains import statements linking to folders and files in the module.__manifest__.py
: the root of the module that describe essential information about the module.
-
For creating a model first create a folder named
models
and import this from outer__init__.py
.from . import models
-
In the
models
folder create another__init__.py
and a python model file namedpatient.py
and import that file from the__init__.py
. All the python model files have to be imported from the__init__.py
.from . import patient
-
Create a base class in
patient.py
and it inherits the odooModel
as regular database-persisted models. Here_name
is the model name that is required to identify the model and a table will be created in the postgresql database with the namekmhospital_patient
, by replacing.
to_
.from odoo import api, models, fields class HospitalPatient(models.Model): _name = 'kmhospital.patient' _description = 'Hospital Patient' name = fields.Char(string='Patient Name', required=True) address = fields.Char(string='Address') gender = fields.Selection([ ('male','Male'), ('female', 'Female') ], default="male")
-
Fields are used to define what the model can store in the database table. Many types of data can be stored -
Integer, Float, Char, Boolean, Text, Selection, Binary, Datetime
etc. -
Restart the server and upgrade the module and then go to
Settings > Technical > Models
. Search using model name and you will get the model. In this model fields will be created based on thefields
defined in the model and some predefined fields will also be created.