Outils pour utilisateurs

Outils du site


erp:odoo12:modeles

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
erp:odoo12:modeles [2020/09/19 07:24]
marclebrun créée
erp:odoo12:modeles [2020/11/23 07:56] (Version actuelle)
marclebrun [Types de Champs]
Ligne 3: Ligne 3:
 Doc: [[https://​www.odoo.com/​documentation/​13.0/​reference/​orm.html|ORM API]] Doc: [[https://​www.odoo.com/​documentation/​13.0/​reference/​orm.html|ORM API]]
  
-  * [[erp:​odoo12:​modeles:​implementation]] 
-  * [[erp:​odoo12:​modeles:​relations]] 
   * [[erp:​odoo12:​modeles:​champs_speciaux]]   * [[erp:​odoo12:​modeles:​champs_speciaux]]
   * [[erp:​odoo12:​modeles:​decorateurs]]   * [[erp:​odoo12:​modeles:​decorateurs]]
Ligne 10: Ligne 8:
   * [[erp:​odoo12:​modeles:​droits_access]]   * [[erp:​odoo12:​modeles:​droits_access]]
   * [[erp:​odoo12:​modeles:​mapped]]   * [[erp:​odoo12:​modeles:​mapped]]
 +
 +===== Implémentation =====
 +
 +<​code>​
 +/mon_module
 +  __init__.py
 +  /models
 +    __init__.py
 +    book.py
 +</​code>​
 +
 +<code python /​mon_module/​__init__.py>​
 +from . import models
 +</​code>​
 +
 +<code python /​mon_module/​models/​__init__.py>​
 +from . import book
 +</​code>​
 +
 +<code python /​mon_module/​models/​book.py>​
 +from odoo import api, models, fields
 +
 +class Book(models.Model): ​             #(1)
 +    _name        = '​mon_module.book' ​  #(2)
 +    _description = '​Book'​
 +    ​
 +    # champs...
 +    ​
 +    # méthodes...
 +    ​
 +</​code>​
 +
 +**#(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 **<​nom_du_module>​POINT<​nom_du_modele>​**
 +
 +===== 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|}}
 +
 +<code python>
 +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'​
 +    )
 +</​code>​
  
erp/odoo12/modeles.1600500280.txt.gz · Dernière modification: 2020/09/19 07:24 par marclebrun