bemade-addons/bemade_sports_clinic/models/injury_document.py
Denis Durepos ca57ec8f16 [IMP] bemade_sports_clinic: Refactor portal views and enhance treatment notes
- Refactor portal templates to eliminate intra-module template inheritance
- Integrate emergency contacts section into player injuries template
- Add full internal admin views for treatment notes with chatter support
- Fix ORM warning in test_rights by using proper ORM commands
- Update manifest to reflect new functionality (v18.0.1.9.0)

This refactoring improves template stability by removing XPath errors and
provides treatment professionals with better access to emergency contacts
and treatment notes both in portal and backend interfaces.
2025-07-11 21:47:50 -04:00

46 lines
2 KiB
Python

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
import base64
class InjuryDocument(models.Model):
_name = 'sports.injury.document'
_description = 'Injury Document'
_order = 'create_date desc, id desc'
name = fields.Char(string='Name', required=True)
injury_id = fields.Many2one('sports.patient.injury', string='Injury', required=True, ondelete='cascade')
patient_id = fields.Many2one('sports.patient', string='Patient', related='injury_id.patient_id', store=True)
description = fields.Text(string='Description')
file_content = fields.Binary(string='File Content', required=True, attachment=False)
file_name = fields.Char(string='File Name')
file_size = fields.Integer(string='File Size', compute='_compute_file_size', store=True)
category = fields.Selection([
('medical', 'Medical Report'),
('xray', 'X-Ray'),
('mri', 'MRI'),
('prescription', 'Prescription'),
('other', 'Other'),
], string='Category', default='other', required=True)
created_by_id = fields.Many2one('res.users', string='Uploaded By', default=lambda self: self.env.user, required=True)
create_date = fields.Datetime(string='Upload Date')
@api.depends('file_content')
def _compute_file_size(self):
"""Compute the file size in bytes"""
for record in self:
if record.file_content:
try:
record.file_size = len(base64.b64decode(record.file_content))
except Exception:
record.file_size = 0
else:
record.file_size = 0
@api.constrains('file_content')
def _check_file_size(self):
"""Ensure document file size is within limits"""
max_size = 10 * 1024 * 1024 # 10 MB
for record in self:
if record.file_size > max_size:
raise ValidationError(_('Document file size cannot exceed 10 MB.'))