bemade-addons/bemade_sports_clinic/tests/test_injury_assignment.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

116 lines
4.3 KiB
Python

from odoo.tests import TransactionCase, tagged
@tagged("-at_install", "post_install")
class TestInjuryAssignment(TransactionCase):
"""Test injury assignment when reported by coaches or therapists."""
@classmethod
def setUpClass(cls):
super().setUpClass()
# Get security groups
cls.treatment_prof_group = cls.env.ref('bemade_sports_clinic.group_sports_clinic_treatment_professional')
cls.user_group = cls.env.ref('bemade_sports_clinic.group_sports_clinic_user')
# Create a test organization
cls.organization = cls.env['sports.organization'].create({
'name': 'Test Organization',
})
# Create a test team
cls.team = cls.env['sports.team'].create({
'name': 'Test Team',
'organization_id': cls.organization.id,
})
# Create test partners for different roles
cls.partner_therapist = cls.env['res.partner'].create({
'name': 'Therapist Partner',
'email': 'test.therapist@example.com',
})
cls.partner_coach = cls.env['res.partner'].create({
'name': 'Coach Partner',
'email': 'test.coach@example.com',
})
cls.partner_athlete = cls.env['res.partner'].create({
'name': 'Athlete Partner',
'email': 'test.athlete@example.com',
})
# Create users for each partner with appropriate roles
cls.user_therapist = cls.env['res.users'].create({
'name': 'Test Therapist',
'login': 'test.therapist@example.com',
'partner_id': cls.partner_therapist.id,
'groups_id': [
(4, cls.env.ref('base.group_user').id),
(4, cls.treatment_prof_group.id)
],
})
cls.user_coach = cls.env['res.users'].create({
'name': 'Test Coach',
'login': 'test.coach@example.com',
'partner_id': cls.partner_coach.id,
'groups_id': [
(4, cls.env.ref('base.group_user').id),
(4, cls.user_group.id)
],
})
# Create a patient
cls.patient = cls.env['sports.patient'].create({
'first_name': 'Test',
'last_name': 'Athlete',
'team_ids': [(4, cls.team.id)],
})
# Create team staff
cls.env['sports.team.staff'].create({
'team_id': cls.team.id,
'partner_id': cls.partner_therapist.id,
'is_treatment_professional': True,
'user_id': cls.user_therapist.id,
})
cls.env['sports.team.staff'].create({
'team_id': cls.team.id,
'partner_id': cls.partner_coach.id,
'is_treatment_professional': False,
'user_id': cls.user_coach.id,
})
def test_injury_reported_by_therapist(self):
"""Test that when an injury is reported by a therapist, they are automatically assigned to it."""
# Switch to therapist user
self.env = self.env(user=self.user_therapist)
# Create an injury as the therapist
injury = self.env['sports.patient.injury'].create({
'patient_id': self.patient.id,
'team_id': self.team.id,
'diagnosis': 'Sprained ankle',
})
# Check that the therapist is automatically assigned
self.assertIn(self.user_therapist.id, injury.treatment_professional_ids.ids,
"Therapist should be automatically assigned when reporting an injury")
def test_injury_reported_by_coach_with_team_therapist(self):
"""Test that when an injury is reported by a coach, the team therapist is assigned."""
# Switch to coach user
self.env = self.env(user=self.user_coach)
# Create an injury as the coach
injury = self.env['sports.patient.injury'].create({
'patient_id': self.patient.id,
'team_id': self.team.id,
'diagnosis': 'Knee pain',
})
# Check that the team therapist is automatically assigned
self.assertIn(self.user_therapist.id, injury.treatment_professional_ids.ids,
"Team therapist should be automatically assigned when a coach reports an injury")