HOW TO CREATE A MODULE IN ODOO. INTRODUCTION For those who are in starting stage of Odoo development, it is a tough task for creating.

Slides:



Advertisements
Similar presentations
How to Create a Local Collection
Advertisements

10 February Doors TM for Windows TM Software Installation.
Kanban Task Manager Single‒ Introduction
software for easy managing of medical shop
1 of 6 Parts of Your Notebook Below is a graphic overview of the different parts of a OneNote 2007 notebook. Microsoft ® OneNote ® 2007 notebooks are digital.
PayDox applications All features can be used independently.
1 Shared Financial Systems WISDM2 Difference Training October 2006.
Wordpress Tutorial 22 – 24 April Table of Contents Introduction Designing blog Writing and Publishing blog Pages Posts Categories Tags Links Comments.
Website Tutorial. Administration  Log on by clicking Login on the footer of almost any page  Your Username is.
PRIOS ARA Limited Agent User Instructions PRIOS ARA Limited Agent User Instructions Professional Repossessors Interactive Operating System.
Tools Menu and Other Concepts Alerts Event Log SLA Management Search Address Space Search Syslog Download NetIIS Standalone Application.
0 eCPIC User Training: Resource Library These training materials are owned by the Federal Government. They can be used or modified only by FESCOM member.
Lesson 01: Introduction to Database Software. At the end of this lesson, students should be able to: State the usage of database software. Start a database.
1 EndNote X2 Your Bibliographic Management Tool 29 September 2009 Humanities and Social Sciences Resource Teams.
Table of Contents TopicSlide Administrator Login 2 Administrator Navigations 3 Managing AlternativeDr.com Blogs 4 Managing Dr. Lloyd May Blogs 5 Managing.
Web Site Development - Process of planning and creating a website.
Joomla Awdhesh Kumar Singsys Pte Ltd. What is Joomla? Joomla is an award-winning content management system (CMS), which enables you to build Web sites.
Literary Reference Center Tutorial support.ebsco.com.
History Reference Center
History Reference Center
Development Environment
Welcome! To the ETS – Create Client Account & Maintenance
Science Reference Center
Creating a MODULE Tarun Behal
Building a User Interface with Forms
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Reordering in odoo. INTRODUCTION Some products have large scope in market, and we have to make sure that the product never run out stock.
Reordering in odoo. INTRODUCTION Some products have large scope in market, and we have to make sure that the product never run out stock.
HOW TO CONFIGURE PYCHARM FOR ODOO DEVELOPMENT IN WINDOWS?
Steps to create login notification in odoo.
Odoo 10 Attendance Kiosk Mode. INTRODUCTION A beautiful and relevant feature which describes how Odoo is more ease to use and how they.
How to Setup Product Expiry Dates in Odoo?
Product Tracking With Barcode [Enterprise]
Odoo Database Management. INTRODUCTION How to reliably take a full backup of the database, such that in one operation (or multiple, scriptable.
Start promoting in Manage the marketing process
Single Sample Registration
Small Engine Repair Reference Center
Science Reference Center
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Kanban Task Manager for Outlook ‒ Introduction
Visual programming Chapter 1: Introduction
Kanban Task Manager Single‒ Introduction
Introduction With TimeCard users can tag SharePoint events with information that converts them into time sheets. This way they can report.
BOLD 2.0 Navigation Help Guide.
Tutorial Introduction to support.ebsco.com.
Title: Unified Communication Application Suite Keycode Retrieval System (KRS) User Guide Issue: 0.2 Date: July 2011 Hi and welcome to the.
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Hi and welcome to the Order Centre – Ordering training.
Hi and welcome to the Order Centre – Ordering training.
MODULE 7 Microsoft Access 2010
Literary reference center
Finding Magazine and Journal Articles in
Managing Rosters Screener Training Module Module 5
Title: Agile Communication Environment Keycode Retrieval System (KRS) User Guide Issue: 0.4 Date: July 2011 Hi and welcome to the Order.
MAX Warranty Tracking Vince Stefanetti, Exact MAX Americas Trainer.
History Reference Center
Science Reference Center
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Download from Zotero Home Page
Understand basic HTML and CSS terminology, concepts, and basic operations. Objective 3.01.
Overview of Contract Association Batch Upload
Tutorial 7 – Integrating Access With the Web and With Other Programs
Guidelines for Microsoft® Office 2013
Cases Admin Training.
Introduction to MS ACCESS
Drupal user guide Evashni Jansen Web Office.
All Right Reserved © JiJi Technologies Pvt Ltd
Complete exercise 8-11 in the workbook.
MTPD Technology Overview
Presentation transcript:

HOW TO CREATE A MODULE IN ODOO

INTRODUCTION For those who are in starting stage of Odoo development, it is a tough task for creating a new module. In this section let us look how to create a new module in the Odoo.

There are mainly four files required for creating a new module (.py or.xml can be excluded as per the need). The main four files are :-  __init__.py  __manifest__.py  model.py  view.xml

This is based on v10, in the v9 and v8 we have to use __openerp__.py instead of the __manifest__.py. The above four files should be inside a folder, let the folder name be school __init__.py In the __init__.py file we have to import all the python files that we are going to use. Suppose as described above we have a python file called model.py in our module. The first thing we have to do is, import the model.py in the __init__.py file. So our __init__.py file will be like this, import model

 _ manifest__.py In the __manifest__.py, We have to mention the module name, the author name, version, description, company, category etc. Now let us see what all these things for, Name – Name of the module to be displayed Author – The name of one who created the module Version – version of the released module, is it v10,v9 or v8 company – The company which developer module website – the website address of the company Category – Category of the module, whether it is sales, purchase, point of sale etc. Depends – Suppose if our module depends on any other modules, we have to mention that name in the depends. As we are going to create a new module and as it is not depending on any other modules, just add depends as base Data – In the data section we have to specify all the.xml files here. In our case we have to mention the view.xml here

So our __manifest__.py file will be like this { 'name': 'Student Record', 'summary': """This module will add a record to store student details""", 'version': ' ', 'description': """This module will add a record to store student details""", 'author': 'Niyas Raphy', 'company': 'Cybrosys Techno Solutions', 'website': '

'category': 'Tools', 'depends': ['base'], 'license': 'AGPL-3', 'data': [ 'view.xml', ], 'demo': [], 'installable': True, 'auto_install': False, } If the installable is not as set as True, the module will not have an install button when we see it in the apps list. If we set the the auto_install as True, the module will automatically get installed in the time of creation of the new database.

model.py In this file, we have to design a new model to store the values of the student, let it be student.student. On creating a new model, a table will get generated in the database. Inside the model, we have to declare all the fields that we are going to use in this table. The different types of fields are, * char * float * Int * Boolean * many2one * many2many etc, * selection

The model.py in our case is, from odoo import models, fields class StudentRecord(models.Model): _name = "student.student" name = fields.Char(string='Name', required=True) middle_name = fields.Char(string='Middle Name', required=True) last_name = fields.Char(string='Last Name', required=True) photo = fields.Binary(string='Photo') student_age = fields.Integer(string='Age') student_dob = fields.Date(string="Date of Birth") student_gender = fields.Selection([('m', 'Male'), ('f', 'Female'), ('o', 'Other')], string='Gender') student_blood_group = fields.Selection( [('A+', 'A+ve'), ('B+', 'B+ve'), ('O+', 'O+ve'), ('AB+', 'AB+ve'), ('A-', 'A-ve'), ('B-', 'B-ve'), ('O-', 'O-ve'), ('AB-', 'AB-ve')], string='Blood Group') nationality = fields.Many2one('res.country', string='Nationality')

First of all we have to import the models and fields from the odoo. (After importing the required packages give two line space before class ). Then we have to define a new class StudentRecord with the name as the student.student. Now a table will get generated, next we have to define the fields inside this table,(leave one line space between model name and fields) in the above we can see that the fields are name, student_photo, student_age etc.

Now let us look what is the type of the each field, * name – name is defined as a char field. * middle_name – middle name is also char field * last_name – char field * student_photo – This a binary field where we can store the image of the student. * student_age – Integer field to store the age of student * student_dob – Date field to record the date of birth of the student * student_gender – It is selection field from which the gender of the student can be selected * student_blood_group- This is also a selection field, from this the blood group o f can be selected *student_nationality – This is a many2one field of the res.country, all the * nations list will be displayed and we can select the required one name = fields.Char(string='Name', required=True)

IMP :- While giving the name for the fields, give it properly so that one can easily understand why this field is for on seeing its name. student_age = fields.Integer(string='Age'), The word that we have given inside the string attribute will displayed in the form, tree views. We can define the above fields like this also, student_age = fields.Integer('Age'), without string=”Age”, we can directly give 'Age' inside the bracket. But giving with string is recommended.

view.xml As we have defined all the needed fields in the model.py file now we have to create view for this. How should user see this, where must be the name field ? Such thing can be defined in the view.xml file. Right now we have created a table in the database, here we have to define how it should be in the user interface and under which menu it should be etc. In our case, let us create a new menu called school and under the school we can create a sub menu called students and on clicking the students menu we can display the student record.

Let us first look, how to create a new menus, <menuitem id="school_student" name="Students" parent="menu_school" action="action_view_students"/> This is how we can create new menus, In the first menu we can see only the id and name, where as we can see two extra attributes in second menu, ie, action and parent.

As first menu does not have a parent the menu will get created a new menu in top bar. For the second menu parent is set as the first menu, you can see that in the parent of the second the id of the first menu is given. So the second menu will be the submenu of the first menu. The string that we have given in the name attribute will be displayed as the name of the menu. IMP : The menu that is created without having any action will not get displayed in the UI

Now let us look what does the action in the student menu is for, Creating the action record, The action which takes place on clicking the menu is based on what we have defined in the action record. Let us look how our action record “ action_view_students” will be, Students student.student form tree,form [] Create new student

Here, we have to give which all views should be there, in the above i have given two views ie, tree and form view. In the res_model we have to specify the model, our model name is student.student, the name that we have given while creation of the class in the model.py. The domain is for, suppose if we have to filter the records on clicking the menu we can give the filter condition here. [('student_age', '>', 23)], if we give such a domain then student those who have age greater than 23 will ve displayed. Create new student. This will get displayed if no record in the corresponding model is created. If there is no students created then it will display like this, create new student.

Now we have to create form view and tree view for model, Tree view :- student.student.tree student.student In the id we have to give id for tree view, in the model we have to give our model ie, student.student. The attribute tree will identify this as tree view

Form view :- student.student.form student.student

<page name="personal_information" string="Personal Information"> <group col="4" colspan="4" name="personal_detail">

On giving sheet tag inside the form, a sheet will appear inside the form, it will make the form more beautiful. IMP: If the fields are not given inside the group tag, the string for the field given in the model.py will not get displayed in the form view.

To display the fields in two sides of a form, we can use group tag inside group tag,

Now let us look the whole code, that we have written * __init__.py import model * __manifest__.py { 'name': 'Student Record', 'summary': """This module will add a record to store student details""", 'version': ' ', 'description': """This module will add a record to store student details""", 'author': 'Niyas Raphy', 'company': 'Cybrosys Techno Solutions', 'website': ' 'category': 'Tools', 'depends': ['base'], 'license': 'AGPL-3', 'data': [ 'data/view.xml',

], 'demo': [], 'installable': True, 'auto_install': False, } * model.py from odoo import models, fields class StudentRecord(models.Model): _name = "student.student" name = fields.Char(string='Name', required=True) middle_name = fields.Char(string='Middle Name', required=True) last_name = fields.Char(string='Last Name', required=True) photo = fields.Binary(string='Photo') student_age = fields.Integer(string='Age') student_dob = fields.Date(string="Date of Birth")

student_gender = fields.Selection([('m', 'Male'), ('f', 'Female'), ('o', 'Other')], string='Gender') student_blood_group = fields.Selection( [('A+', 'A+ve'), ('B+', 'B+ve'), ('O+', 'O+ve'), ('AB+', 'AB+ve'), ('A-', 'A-ve'), ('B-', 'B-ve'), ('O-', 'O-ve'), ('AB-', 'AB-ve')], string='Blood Group') *view.xml student.student.tree student.student

student.student.form student.student

<page name="personal_information" string="Personal Information"> <group col="4" colspan="4" name="personal_detail">

Students student.student form tree,form [] Create new student

The module is now completed, make sure that the newly created module is inside the proper addons path. Then Go to Odoo, activate developer mode. Then Apps -> update apps list -> click on update. The technical name of our module is the folder name (ie, school in our case) and the name is Student Record which is given in the manifest file. Now after updating the apps list, you can search for the module based on either of those name. This is now the structure of the module, school -- __init__.py -- __manifest__.py -- model.py -- view.xml -- static --- description --icon.png ** Bold ones is folders

Extra tips * For giving icon image for the newly created module, create a folder named static inside the school, then inside the static folder create a description folder and inside that add a image in name icon and it is format should be png. * We can use MVC concept in creation of the module. So that the all.py file should be added inside the models folder and all the.xml file should be added in views folder. If we are using the above concept we have to change the module structure like this, school -- __init__.py -- __manifest__.py -- models -- __init__.py -- model.py -- views -- view.xml

-- static --- description --icon.png In the main __init__.py file we have to import the models folder, main __init__.py import models In the __init__.py file inside the models folder, import model As the view.xml is moved to the views folder, the manifest file also has to be changed.

__manifest__.py { 'name': 'Student Record', 'summary': """This module will add a record to store student details""", 'version': ' ', 'description': """This module will add a record to store student details""", 'author': 'Niyas Raphy', 'company': 'Cybrosys Techno Solutions', 'website': ' 'category': 'Tools', 'depends': ['base'], 'license': 'AGPL-3', 'data': [ 'views/view.xml', ], 'demo': [], 'installable': True, 'auto_install': False, }

This is how we can create a module in Odoo …..

Refer this link for more:

Thank You ! Cybrosys Technologies Pvt. Ltd. Neospace, Kinfra Techno Park, Kakkancherry, Calicut University P.O. Calicut Kerala, India Cybrosys Ltd 15, ST Antonys Road, Forest Gate, London England, E79QA. Cybrosys Technologies Pvt. Ltd. 1st Floor, Thapasya Building, Infopark, Kakkanad, Kochi, Kerala, India