Skip to content
oxpace.

Lesson 2/2 · 14 min

Models and security

python
from odoo import api, fields, models

class DemoTask(models.Model):
    _name = "oxpace.demo.task"
    _description = "Demo task"
    _inherit = ["mail.thread"]

    name = fields.Char(required=True, tracking=True)
    hours = fields.Float()
    state = fields.Selection([("draft", "Draft"), ("done", "Done")], default="draft")

    @api.constrains("hours")
    def _check_hours(self):
        for rec in self:
            if rec.hours < 0:
                raise ValueError("Hours must be positive")

Every new model needs access rules in ir.model.access.csv; without them only the superuser can see it.