Last active
May 26, 2021 14:48
-
-
Save exaucae/295978dcfaa6025ea307aa5414d2e2c8 to your computer and use it in GitHub Desktop.
notes about Odoo structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
======================== | |
ODOO building blocs | |
============== | |
I expose Odoo 14 models structure here. Have a look to reference for further informations. | |
1. Models: represents a business object | |
They are built around three main base ORM classes BaseModel, AbstractModel and Model | |
Models are not directly accessible; one should use recordsets to do so. | |
1.1 RecordSets (mix between class and sets) | |
They are all instances of a model at the same time. | |
In a given model, "self" is a recordSet. Recordsets can be: filtered, mapped, sorted, searched, copied, added and so on. | |
1.2 Environnement variable ( self.env) | |
Due to it, we can access any given recordset in a model. | |
In fact, the self element contains a given model recordsets. | |
Those recordsets can have duplicate values, although their name suggest the contrary. With the env, one can change user or context with ease | |
Example: self.env("res.partner"): gets the recordset of the res.partner model. It implicitly passes 3 params: | |
- cr: db cursor | |
- uid: current user id | |
- context: the current context dictionnary ( used to pass data between views and models or models and models) | |
With the env, one can also have access to ref and current user like so: | |
- self.env.ref(model.external_id_in_view_or_data_file, False) | |
- self.env.user | |
- and much more: see https://www.odoo.com/documentation/14.0/developer/reference/orm.html#environment | |
1.3 Inheritance | |
Odoo has composition based inheritance, (direct and polymorphic) apart from classical python inheritance. | |
It is mainly used in model definition. | |
1.4. Decorators: | |
They are simple python decorators | |
== | |
Ref: | |
- prerequisites: | |
- python rehearsal: https://www.pythoncheatsheet.org/ | |
- odoo custom modules: https://www.youtube.com/watch?v=I8FNdellz3Y | |
- official odoo documentation: | |
- Oddo 14 ORM ref: https://www.odoo.com/documentation/14.0/developer/reference/orm.html | |
- Odoo v8+ new api: https://odoo-new-api-guide-line.readthedocs.io/en/latest/environment.html | |
- Odoo v8+ online reference: https://www.odoo.com/documentation/online/reference/ | |
- Odoo v8+ new ORM API: https://www.odoo.com/documentation/online/reference/orm.html | |
- misc: | |
- Odoo ORM advanced concepts: https://docs.huihoo.com/odoo/training/reference-material/advanced-features-of-the-api.pdf | |
- Odoo context and domain: https://www.globalteckz.com/how-to-use-context-and-domain-in-odoo/ | |
- Odoo self.env.ref: https://www.instant-erp.com/services/odoo-erp-openerp/how-can-we-retrieve-a-record-with-its-external-id-for-an-odoo-model | |
- Odoo Action to return to Tree or Form View, dynamically: https://www.excelroot.com/post/odoo-action-to-return-to-tree-view | |
=========== | |
Side note: | |
- Domain: list of criteria, each criterion being a triple (either a list or a tuple) of (field_name, operator, value). | |
It can be used in: | |
- in views as a filter to display data | |
- as a directive with the eval keyword | |
- in fields definition | |
The syntax goes like this: domain= "[("field_name", "operator", "value"), ("field_name", "operator", "value") ]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment