- 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.
39 lines
1.9 KiB
Python
39 lines
1.9 KiB
Python
from odoo import models, fields, api, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class TreatmentNote(models.Model):
|
|
_name = 'sports.treatment.note'
|
|
_description = 'Treatment Note'
|
|
_order = 'date desc, id desc'
|
|
_inherit = ['mail.thread', 'mail.activity.mixin']
|
|
|
|
patient_id = fields.Many2one('sports.patient', string='Patient', required=True, ondelete='cascade', index=True, tracking=True)
|
|
injury_id = fields.Many2one('sports.patient.injury', string='Injury', required=False, ondelete='cascade', index=True, tracking=True)
|
|
note = fields.Text(string='Note', required=True, tracking=True)
|
|
date = fields.Date(string='Date', default=fields.Date.context_today, required=True, tracking=True)
|
|
user_id = fields.Many2one('res.users', string='Added By', default=lambda self: self.env.user, required=True, tracking=True)
|
|
note_type = fields.Selection([
|
|
('general', 'General Note'),
|
|
('injury', 'Injury-specific')
|
|
], string='Note Type', compute='_compute_note_type', store=True)
|
|
|
|
@api.depends('injury_id')
|
|
def _compute_note_type(self):
|
|
"""Determine whether this is a general note or injury-specific"""
|
|
for record in self:
|
|
record.note_type = 'injury' if record.injury_id else 'general'
|
|
|
|
@api.constrains('note')
|
|
def _check_note_content(self):
|
|
"""Ensure treatment notes have content"""
|
|
for record in self:
|
|
if not record.note or not record.note.strip():
|
|
raise ValidationError(_('Treatment note cannot be empty.'))
|
|
|
|
@api.constrains('injury_id', 'patient_id')
|
|
def _check_injury_patient_match(self):
|
|
"""Ensure the injury belongs to the selected patient"""
|
|
for record in self:
|
|
if record.injury_id and record.injury_id.patient_id != record.patient_id:
|
|
raise ValidationError(_('The injury must belong to the selected patient.'))
|