Outils pour utilisateurs

Outils du site


erp:odoo12:modeles

Modèles

Implémentation

/mon_module
  __init__.py
  /models
    __init__.py
    book.py
/mon_module/__init__.py
from . import models
/mon_module/models/__init__.py
from . import book
/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...
 

#(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

Modèle PRODUIT
id
category_id fields.Many2one('categorie', …)
Modèle CATEGORIE
id
product_ids fields.One2many('produit', …)

Factures et Lignes

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'
    )
erp/odoo12/modeles.txt · Dernière modification: 2020/11/23 07:56 par marclebrun