IWSD-03 ODOO

Table of Contents

    IWSD-03 ODOO

    Introduction

    • Odoo is an open-source ERP (Enterprise Resource Planning) system that provides a suite of business applications, including CRM, eCommerce, accounting, inventory, HR, and more.
    • It is highly modular, allowing businesses to install only the apps they need and extend functionality as required.
    • Key Features
      • Modular System: Install only the required apps.
      • Integrated Suite: All applications work together seamlessly.
      • Customizable: Supports drag-and-drop customization and developer-based modifications.
      • Open-source & Enterprise Versions: Open-source (free) with community support, Enterprise (paid) with advanced features.

    ODOO Studio

    • Odoo Studio is a low-code/no-code environment that allows users to customize applications without writing code.
    • Key Features:
      • Form and Report Editor: Modify form views, reports, and layouts using drag-and-drop.
      • Workflow Automation: Automate processes like sending emails when an order is confirmed.
      • Custom Fields: Add new fields to forms and models without coding.
      • Menu Customization: Adjust navigation and interface elements easily.
      • User Role Management: Control who sees what data using role-based access control.
    • Limitations of Odoo Studio:
      • Cannot handle complex logic or advanced automation.
      • Limited in modifying backend database structures.
      • Cannot create deep integrations with external systems.
      • Limited ability to modify existing module code.
      • For advanced customizations, developers need to work with code.

    History of ODOO

    • Odoo was founded by Fabien Pinckaers in 2005 under the name TinyERP. Over the years, it evolved into OpenERP and eventually Odoo.
    • 2005: Released as TinyERP 1.0, focusing on small businesses.
    • 2009: Renamed OpenERP, expanding to larger enterprises.
    • 2014: Became Odoo, introducing modular app-based architecture.
    • 2015: Present Continuous growth, with Odoo Enterprise for premium features.

    Code-Based Customization in Odoo

    • Odoo uses Python (backend logic) and XML (UI views and data structure). To create advanced functionalities, developers need to work with these core components.

    Add-on Module Structure

    • Odoo uses modules to extend its functionality. A module is a self contained package that adds new features, models, or views.

    Module Directory Structure

    • πŸ“‚customβ€”addons/
    • πŸ“‚myβ€”module/: Your module folder
      • πŸ“„__init__.py:: Python file to import models
      • πŸ“„__manifest__.py: Manifest file (metadata)
      • πŸ“‚models/: Python models (database tables & business logic)
      • πŸ“‚views/: XML files (Ul structure)
      • πŸ“‚security/: Access rights & record rules

    Manifest File

    • The __manifest__.py file is a Python dictionary that acts as the module's configuration file and contains metadata about the module.
    • Key Attributes:
      • depends: Other Odoo modules required (e.g., ['base', 'sale']).
      • data: Files to be loaded (e.g., views, security, demo data).
      • installable: Whether the module can be installed (True/False).
      • application: Defines whether the module should appear as a main app in Odoo.
    {
    'name': 'My Custom Module',
    'version': '1.0',
    'depends': ['base'],
    'data': [
    	'views/my_model_view.xml',
    	'security/ir.model.access.csv',
    	],
    'installable': True,
    'application': True,
    }

    Steps to Write Module in Odoo

    1. Download and install Odoo
    2. Create a new module:
      1. Navigate to odoo/addons/ or custom_addons/.
      2. Create a folder my_module.
      3. dd __init__.py and __manifest__.py files
    3. Define a Model (Database Table)
      • Create models/my_model.py:
    from odoo import models, fields
     
    class MyModeI(modeIs.ModeI):
    	_name = 'my.model'
    	_description = 'My First Custom Model'
     
    	name = fields.Char(string="Name', required=True)
    	description = fields.Text(string = "Description")
    	is_active = flase.Boolean(string = "Active", default = "True")
    1. Define Views (User Interface)
      • Create views/my_model_view.xml
    <odoo>
    	<record id="view_my_model_form" model="ir.ui.view">
    		<field name="name">my.model.form</field>
    		<field name="model">my.model</field>
    		<field name="arch" type="xml">
    			<form string="My Model">
    				<group>
    					<field name="name"/>
    					<field name="description"/>
    					<field name="is_active"/>
    				</group>
    			</form>
    		</field>
    	</record>
    </odoo>

    Relation Field

    • Relation fields are used to create relationships between different models (database tables).
    • These fields help link records across models, enabling data consistency and easy access.

    Many2One (Foreign Key)

    • A record belongs to another model
    class Order(models.Model):
    	_name = 'sales.order'
     
    	customer_id = fields.Many2One('res.partner', string="Customer")

    One2Many (Reverse Relation)

    • A record has multiple related records.
    class Customer(models.Model):
    	_name = 'res.partner'
     
    	order_ids = fields.One2Many('sales.order', 'customer_id', string="Orders")

    Many2Many (Multiple Relationships)

    class Course(models.Model):
    	_name = 'academy.course'
     
    	student_ids = fields.Many2Many('academy.student', string="Students")

    Widgets & Controls in UI

    • Odoo provides various Ul widgets to improve the user experience.
    • Common Widgets:
      • char: Simple text field
      • text: Multi-line text
      • boolean: Checkbox
      • selection: Dropdown
      • binary: File upload
      • many20ne: Dropdown with search
      • html: Rich text editor

    Domain Filter in Odoo

    • A domain filter dynamically filters records in a view.
    • Example: Show only active customer
    <field name="customer_id" domain="[('is_active', '=', True)]"/>
    • Example: Only show products from a specific category
    <field name="product_id" domain="[('category_id', '=', 'Electronics')]"/>

    Significance of Odoo’s Modular Structure

    • Allows businesses to install only the necessary applications.
    • Enables easy customization and scalability.
    • Provides seamless integration between different modules.
    • Supports both no-code (Odoo Studio) and code-based customization (Python & XML).

    Modules in Odoo

    • A module in Odoo is a self-contained package that adds functionality to the system. It includes models, views, security rules, and business logic.
    • Key Features:
      • A modular structure allows easy customisation.
      • Defined using a manifest file (__manifest__.py).
      • Can introduce new features or extend existing ones.

    ATTRS in Odoo

    • In Odoo, ATTRS stands for Attributes. It is used in XML views to control the behavior of fields dynamically based on conditions. Such as hiding/showing fields or making them read-only based on conditions.
    • Key Features:
      • Applied in XML views
      • Supports conditions like invisible, required, read-only
    • ATTRS is used to dynamically control field visibility, required fields, and read-only conditions in views.
    • Common Attributes:
      • { 'readonly': [('state', '=' 'done')] }: Makes the field read-only based on a condition.
      • { 'required': [('type', '=' 'mandatory')] }: Marks the field as required dynamically.
      • { 'invisible': [('field_name', '=' 'value')] }: Hides the field when a condition is met.

    On-Change Events

    • An on-change event triggers an action when a field value changes. It is used to update dependent fields automatically.
    • Key Features:
      • Implemented in Python using @api.onchange.
      • Helps to update field values dynamically
    @api.onchange('price'):
     
    def _onchange_price(self):
    	if self.price:
    		self.price_with_tax = self.price * 1.18

    Views in Odoo

    • Odoo provides multiple views to display data in various formats.
    • Common Views:
      • Form View – For editing individual records.
      • Tree View – Displays multiple records in a tabular format.
      • Kanban View – Graphical card-based representation.
      • Graph View – Used for analytical data visualization.
      • Calendar View – Represents records with date and time attributes.

    View Attributes

    AttributeDescription
    editableEnables/disables editing in list views.
    colspanDefines how many columns a field spans.
    nolabelHides the field label.
    widgetCustomizes how a field is displayed.
    stringSets a custom label for a field.
    domainFilters records based on conditions.
    contextPasses additional parameters to views.

    Diagram View

    • The Diagram View is used to visually represent workflows, processes, or relationships.
    • Key Features:
      • Commonly used in CRM, project management, and automation modules.
      • Allows visual linking of different process stages.
    <diagram>
    	<node model="project.task" name="start"/>
    	<node model="project.task" name="end"/>
    	<transition from="start" to="end"/>
    </diagram>

    Graph View

    • Graph View is used for charts and reports
    • Key Features:
      • Supports bar, line, and pie charts.
      • Used in Sales, Inventory, HR analytics.
    <graph>
    	<field name="date" type="row" />
    	<field name="sales_amount" type="measure" />
    </graph>

    Calendar View

    • Displays date-based records (like tasks, meetings).
    • Key Features:
      • Shows events in a calendar format.
      • Commonly used in HR, Project, and Appointment modules.
    <calendar date_start="start_date" date_stop="end_date" />

    Kanban View

    • Kanban views show cards instead of lists.
    • Key Features:
      • Visual representation.
      • Used in task management, CRM, inventory.
    <kanban>
    	<templates>
    		<t t-name="kanban-box">
    			<div class="oe_kanban_card">
    				<strong><field name="name" /></strong>
    			</div>
    		</t>
    	</templates>
    </kanban>

    Field Parameters

    • Define how fields behave in models.
    ParametersDescription
    required=TrueField is mandatory
    readonly=TrueField is read-only
    default=lambda self:self.env.user.idSets a default value

    Complex Field

    • Complex fields store multiple values in one field. It includes relation fields but also cover other advanced data types that store structured data.

    • Selection Fields β€” Dropdown field with redefined choices.

    state=fields.Selection([('draft', 'Draft'), ('done', 'Done')], string="State")
    • Computed Fields β€” Fields calculated dynamically based on other fields.
    total_price = fields.Float(compute="_compute_total_price")
    • HTML Fields β€” Stores rich text content.
    description = fields.Html(string="Description")

    Model & Class Level Attributes

    • Defines metadata for a model.
    AttributeDescription
    _nameInternal model name
    _descriptionShort description of a model
    _orderDefault string order
    _rec_nameField used as record

    Constraints

    • Constraints enforce data validation at the database level.

    Python Constraints

    Constraint TypeDescription
    @api.constrainsValidates fields based on conditions.
    Required Field CheckEnsures a field is not empty.
    Unique Field CheckPrevents duplicate values in a field.
    Relational CheckEnforces logic between related fields

    SQL Constraints

    Constraint TypeDescription
    CHECKEnsures values meet a condition (e.g., price > 0).
    NOT NULLPrevents NULL values in a column.
    UNIQUEEnsures all values are distinct.
    FOREIGN KEYLinks a column to another table's primary key.

    Automatic Reserve Fields

    • Odoo automatically creates technical fields like:
      • create_date (Record creation time).
      • write_date (Last modification time).
      • create_uid (User who created the record).
    create_date = fields.Datetime(string="Created On", readonly=True)
     
    write_date = fields.Datetime(string="Last Update On", readonly=True)
     
    create_uid = fields.Many2One('res.users', string="Created By", readonly=True)

    Resources

    1. Odoo Official Tutorial

    Made By SOU Student for SOU Students