Mastering Odoo 11.0 Development: Mohamed Magdy

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Odoo

Mastering Odoo 11.0 Development

Mohamed Magdy
OpenObject Concepts
● OOP Class is Object.
● OOP Instance is Resource.
● There is an object for every type of resource,
and not an object per resource.
● MVC:
○ Model: PostgreSQL tables.
○ View: Defined in XML files.
○ Controller: Odoo Objects.
Module Structure
module_name
● __init__.py
● __manifest__.py
● module_name.py
● views/
● security/
● demo/
● wizard/
● report/
● i18n/
● static/
Objects
● In Odoo, Objects are Classes define new
types.
● Models
○ Add new Tables, Fields in Database.
○ Add SQL Constraints.
● Controllers
○ Methods to compute Values.
○ Onchange Methods.
○ Methods (Logic) behind Buttons.
Fields Types (MorePython.com)
● Boolean: is_new_field = fields.Boolean(string="", )
● Char: new_field = fields.Char(string="", required=False, )
● Text: new_field = fields.Text(string="", required=False, )
● Integer: new_field = fields.Integer(string="", required=False, )
● Float: new_field = fields.Float(string="", required=False, )
● Date: new_field = fields.Date(string="", required=False, )
● Datetime: new_field = fields.Datetime(string="", required=False, )
● Selection: new_field = fields.Selection(string="", selection=[('', ''), ('', ''), ], required=False, )
● Many2many: new_field_ids = fields.Many2many(comodel_name="", relation="", column1="", column2="", string="", )
● One2many: new_field_ids = fields.One2many(comodel_name="", inverse_name="", string="", required=False, )
● Many2one: new_field_id = fields.Many2one(comodel_name="", string="", required=False, )
● Binary: new_field = fields.Binary(string="", )
Common Attributes (MorePython.com)
Some attributes are common:
● string: The label of the field seen by users.
● help: The tooltip of the field seen by users.
● readonly: Determines if the field is read-only or editable (boolean).
● required: Determines if the field is required or optional (boolean).
● index: Determines if the field is indexed inDB (boolean).
● default: The default value of the field, it can be static or computed value.
● states: A dictionary mapping state values to lists of UI attribute-value.
● groups: Comma-separated lists of group XML ids.
● copy: Whether to copy the field value when the record is duplicated or not.
● old_name: The old name of this field, so that ORM rename at migration.
● compute: The name of the method that computes the field’s value.
Common Attributes (MorePython.com)
Some attributes are common:
● inverse: The name of a method that inverses the field.
● search: The name of a method that implement search on the field.
● store: Determines if the field is stored in DB (boolean).
● compute_sudo: Determines if the field should be recomputed as superuser
to bypass access rights (boolean).
● related: To get the field’s value automatically from the source field.
● company_dependant: If the field is company-dependant (boolean).
Specific Attributes (MorePython.com)
Some attributes are for specific fields:
Char:
● size: The maximum size of the values stored for that field.
● translate: Enables the translation of the field’s value.
Text:
● translate: Enables the translation of the field’s value.
Float:
● digits: A pair (total, decimal), or a function taking a database cursor and
returning a pair (total, decimal)
Specific Attributes (MorePython.com)
Some attributes are for specific fields:
Selection:
● selection: Specifies the possible values for this field.
● add_selection: Provides an extension of the selection in the case of an
overridden field.
Monetary:
● currency_field: Name of the field holding the currency this monetary field
is expressed in.
Specific Attributes (MorePython.com)
Some attributes are for specific fields:
Many2one:
● comodel_name: Name of the target model (string).
● domain: An optional domain to set on candidate values on the client side.
● context: An optional context to use on the client side when handling that
field (dictionary).
● ondelete: Determines what to do when the referred record is deleted.
Possible values: set null, restrict or cascade.
● auto_join: Determines if JOINS are generated upon search through that
field (boolean).
● delegate: Set it to ‘True’ to make fields of the target model accessible from
the current model.
Specific Attributes (MorePython.com)
Some attributes are for specific fields:
One2many:
● comodel_name: Name of the target model (string).
● domain: An optional domain to set on candidate values on the client side.
● context: An optional context to use on the client side when handling that
field (dictionary).
● inverse_name: Name of the inverse ‘Many2one’ field in ‘comodel_name’.
● auto_join: Determines if JOINS are generated upon search through that
field (boolean).
● limit: Optional limit to use upon read (integer).
Specific Attributes (MorePython.com)
Some attributes are for specific fields:
Many2many:
● comodel_name: Name of the target model (string).
● relation: Optional limit to use upon read (integer).
● domain: An optional domain to set on candidate values on the client side.
● context: An optional context to use on the client side when handling that
field (dictionary).
● column1: An optional name of the column referring to ‘these’ records in
the table ‘relation’.
● column2: An optional name of the column referring to ‘those’ records in
the table ‘relation’.
● limit: Optional limit to use upon read (integer).
Odoo
Mastering Odoo 11.0 Development

Mohamed Magdy

You might also like