Pages - Menu

31 January, 2018

How to config module of odoo from scratch with window os in localhost








There are many ways that we could build a module from scratch and I would like to show all of you by using a method.
Odoo provides a mechanism to help set up a new module, odoo-bin has a subcommand scaffold to create an empty module:


Go to command prompt in window then type
odoo-bin scaffold
eg. odoo-bin scaffold openacademy addons
After we create, it provide us with structures:




Then go to openacademy/__manifest__.py copy or type:

# -*- coding: utf-8 -*-
{
'name': "Open Academy",

'summary': """Manage trainings""",

'description': """
Open Academy module for managing trainings:
- training courses
- training sessions
- attendees registration
""",
'author': "My Company",
'website': "http://www.yourcompany.com",

# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Test',
'version': '0.1',

# any module necessary for this one to work correctly
'depends': ['base'],

# always loaded
'data': [
# 'security/ir.model.access.csv',
'templates.xml',
'views/openacademy.xml',

],
# only loaded in demonstration mode
'demo': [
'demo.xml',
],
}
Then go to openacademy/__init__.py copy and type:
# -*- coding: utf-8 -*-
from . import controllers
from . import models
Then go to openacademy/controllers.py
# -*- coding: utf-8 -*-
from odoo import http
Then go to openacademy/models.py

from odoo import models, fields, api
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string="Title", required=True)
description = fields.Text()
Then go to openacademy/views/openacademy.xml


<?xml version="1.0" encoding="UTF-8"?>
<odoo>
        <!-- window action -->
        <!--
            The following tag is an action definition for a "window action",
            that is an action opening a view or a set of views
        -->
        <record model="ir.actions.act_window" id="course_list_action">
            <field name="name">Courses</field>
            <field name="res_model">openacademy.course</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create the first course
                </p>
            </field>
        </record> 
        <!-- top level menu: no parent -->
        <menuitem id="main_openacademy_menu" name="Open Academy"/>
        <!-- A first level in the left side menu is needed
             before using action= attribute -->
        <menuitem id="openacademy_menu" name="Open Academy"
                  parent="main_openacademy_menu"/>
        <!-- the following menuitem should appear *after*
             its parent openacademy_menu and *after* its
             action course_list_action -->
        <menuitem id="courses_menu" name="Courses" parent="openacademy_menu"
                  action="course_list_action"/>
        <!-- Full id location:
             action="openacademy.course_list_action"
             It is not required when it is the same module -->
</odoo>

After we copy and past code follow this structure ready. You could to (http://localhost:8069/web) then login by username and password that you config then go to setting menu -> click Activate the developer mode then click on App -> click Update App List then search Open Academy after you will see Open Academy module display and you could install it.

No comments:

Post a Comment