/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.
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=…] |
Modèle PRODUIT | |
---|---|
id | |
category_id | fields.Many2one('categorie', …) |
Modèle CATEGORIE | |
id | |
product_ids | fields.One2many('produit', …) |
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' )