from odoo import models, fields class EncoachResource(models.Model): _name = 'encoach.resource' _description = 'Learning Resource' name = fields.Char(required=True) type = fields.Selection([ ('video', 'Video'), ('pdf', 'PDF'), ('document', 'Document'), ('link', 'Link'), ('interactive', 'Interactive'), # Audio + image are surfaced in the Resource Manager table # (icons / filters) so we accept them as first-class types # rather than coercing them into ``document`` and losing the # MIME-correct preview (audio player, , etc.). ('audio', 'Audio'), ('image', 'Image'), ('article', 'Article'), ]) review_status = fields.Selection([ ('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected'), ], default='approved') subject_id = fields.Many2one('encoach.subject', ondelete='set null') domain_id = fields.Many2one('encoach.domain', ondelete='set null', string='Domain') topic_ids = fields.Many2many('encoach.topic') learning_objective_ids = fields.Many2many( 'encoach.learning.objective', 'encoach_resource_obj_rel', 'resource_id', 'objective_id', string='Learning Objectives', ) tag_ids = fields.Many2many( 'encoach.resource.tag', 'encoach_resource_tag_rel', 'resource_id', 'tag_id', string='Tags', ) file = fields.Binary(attachment=True) # Preserve the original upload filename (with extension) so the # download endpoint can serve "report.pdf" even when the human- # readable ``name`` field is set to "Q3 Sales Report" without an # extension. We also keep the resolved MIME type to avoid sniffing # by extension on every download — sniffing fails on resources # named "test" with no dot, and was the root cause of admins # downloading files with no extension and ``application/octet-stream`` # ending up unviewable on macOS / Windows. original_filename = fields.Char( string='Original filename', help='Filename as uploaded, including extension. Used by the ' 'download endpoint to produce a sensible Content-Disposition.', ) mimetype = fields.Char( string='MIME type', help='Cached MIME type from the uploaded file or URL. Drives ' 'preview decisions (PDF in iframe vs vs