from odoo import models, fields class EncoachEntity(models.Model): _name = "encoach.entity" _description = "EnCoach Entity (Organization)" _inherit = ["mail.thread"] name = fields.Char(required=True, tracking=True) label = fields.Char() licenses = fields.Integer(default=0) expiry_date = fields.Datetime() payment_currency = fields.Char() payment_price = fields.Float(digits=(12, 2)) role_ids = fields.One2many("encoach.role", "entity_id", string="Roles") user_rel_ids = fields.One2many( "encoach.user.entity.rel", "entity_id", string="Members", ) legacy_id = fields.Char(index=True) def to_encoach_dict(self): self.ensure_one() payment = None if self.payment_currency and self.payment_price: payment = { "currency": self.payment_currency, "price": self.payment_price, } return { "id": self.id, "label": self.label or self.name, "licenses": self.licenses, "expiryDate": ( self.expiry_date.isoformat() if self.expiry_date else None ), "payment": payment, }