====== Modèles ======
Doc: [[https://www.odoo.com/documentation/13.0/reference/orm.html|ORM API]]
* [[erp:odoo12:modeles:champs_speciaux]]
* [[erp:odoo12:modeles:decorateurs]]
* [[erp:odoo12:modeles:methodes]]
* [[erp:odoo12:modeles:droits_access]]
* [[erp:odoo12:modeles:mapped]]
===== Implémentation =====
/mon_module
__init__.py
/models
__init__.py
book.py
from . import models
from . import book
from odoo import api, models, fields
class Book(models.Model): #(1)
_name = 'mon_module.book' #(2)
_description = 'Book'
# champs...
# méthodes...
**#(1)** Le nom de la classe n'a aucune importance pour Odoo.
**#(2)** Le nom du modèle identifie le modèle partout dans Odoo.
* En général sa structure est **POINT**
===== Types de Champs =====
^ fields.Char | [size=...] |
^ fields.Text | |
^ fields.Html | |
^ fields.Integer | |
^ fields.Float | [digits=...] |
^ fields.Boolean | |
^ fields.Date | |
^ fields.Datetime | |
^ fields.Selection | [selection=...] |
^ fields.Many2one | [comodel_name=...] |
^ fields.One2many | [comodel_name=...] [inverse_name=...] |
===== Relations =====
==== Produits et Catégories ====
{{:erp:odoo12:modeles:screenshot_20201122_083943.png?nolink|}}
^ Modèle PRODUIT ^^
| id | |
| category_id | fields.Many2one('categorie', ...) |
| ||
^ Modèle CATEGORIE ^^
| id | |
| product_ids | fields.One2many('produit', ...) |
==== Factures et Lignes ====
{{:erp:odoo12:modeles:screenshot_20201122_084004.png?nolink|}}
class Facture(models.Model):
_name = 'mymodule.invoice'
line_ids = fields.One2many(
string = 'Invoice Lines',
comodel_name = 'mymodule.invoice_line',
inverse_name = 'invoice_id'
)
class LigneFacture(models.Model):
_name = 'mymodule.invoice_line'
invoice_id = fields.Many2one(
string = 'Invoice',
comodel_name = 'mymodule.invoice'
)