diff --git a/bemade_sports_clinic/__manifest__.py b/bemade_sports_clinic/__manifest__.py index 39dd9f2..cbe37c3 100644 --- a/bemade_sports_clinic/__manifest__.py +++ b/bemade_sports_clinic/__manifest__.py @@ -18,7 +18,7 @@ # { 'name': 'Sports Clinic Management', - 'version': '16.0.1.0.0', + 'version': '16.0.1.1.0', 'summary': 'Manage the patients of a sports medicine clinic.', 'description': """ Adds the notion of sports teams, players (patients), coaches and treatment @@ -44,7 +44,7 @@ 'security/sports_clinic_rules.xml', 'views/sports_team_views.xml', 'views/sports_clinic_menus.xml', - 'views/patient_views.xml', + 'views/sports_patient_views.xml', 'views/sports_clinic_portal_views.xml', ], 'demo': ['data/demo/sports_clinic_demo_data.xml'], diff --git a/bemade_sports_clinic/controllers/team_staff_portal.py b/bemade_sports_clinic/controllers/team_staff_portal.py index 566fc0f..ff12259 100644 --- a/bemade_sports_clinic/controllers/team_staff_portal.py +++ b/bemade_sports_clinic/controllers/team_staff_portal.py @@ -8,7 +8,7 @@ class TeamStaffPortal(CustomerPortal): rtn = super()._prepare_home_portal_values(counters) teams_domain = self._prepare_teams_domain() players_domain = self._prepare_players_domain(teams_domain) - rtn['teams_count'] = http.request.env['res.partner'].search_count(teams_domain) + rtn['teams_count'] = http.request.env['sports.team'].search_count(teams_domain) rtn['players_count'] = http.request.env['sports.patient'].search_count( players_domain) return rtn @@ -18,12 +18,12 @@ class TeamStaffPortal(CustomerPortal): user = http.request.env.user partner = http.request.env.user.partner_id return [ - ('staff_partner_ids', 'in', partner.id), + ('staff_ids', 'in', partner.team_staff_rel_ids.ids), ] @classmethod def _prepare_players_domain(cls, teams_domain): - team_ids = http.request.env['res.partner'].search(teams_domain).ids + team_ids = http.request.env['sports.team'].search(teams_domain).ids return [ ('team_ids', 'in', team_ids), ] @@ -31,12 +31,12 @@ class TeamStaffPortal(CustomerPortal): @http.route(route=['/my/teams'], type='http', auth='user', website=True) def view_teams(self, page=0, **kw): """ Display the list of teams that a portal user has access to """ - Teams = http.request.env['res.partner'] + Teams = http.request.env['sports.team'] domain = self._prepare_teams_domain() teams_count = Teams.search_count(domain) pgr = pager(url='/my/teams', total=teams_count, page=page, step=10, scope=10) - teams = http.request.env['res.partner'].search(self._prepare_teams_domain(), + teams = http.request.env['sports.team'].search(self._prepare_teams_domain(), offset=pgr['offset'], limit=teams_count) return http.request.render(template='bemade_sports_clinic.portal_my_teams', @@ -50,7 +50,7 @@ class TeamStaffPortal(CustomerPortal): @http.route(route=['/my/team/'], type='http', auth='user', website=True) def view_team(self, team_id, page=0, **kw): """ Display the information for a team including its list of players """ - team = http.request.env['res.partner'].browse(team_id) + team = http.request.env['sports.team'].browse(team_id) if not team: raise UserError(_('This team could not be found.')) players_count = team.player_count diff --git a/bemade_sports_clinic/data/demo/sports_clinic_demo_data.xml b/bemade_sports_clinic/data/demo/sports_clinic_demo_data.xml index c65e93d..75e4d78 100644 --- a/bemade_sports_clinic/data/demo/sports_clinic_demo_data.xml +++ b/bemade_sports_clinic/data/demo/sports_clinic_demo_data.xml @@ -133,7 +133,7 @@ 2024-02-01 + eval="[Command.set([ref('base.user_admin')])]"/> 2022-03-17 19:13:00 @@ -141,7 +141,7 @@ 2022-03-23 + eval="[Command.set([ref('base.user_admin')])]"/> 2023-10-15 19:55:00 @@ -149,7 +149,7 @@ 2023-11-01 + eval="[Command.set([ref('base.user_admin')])]"/> @@ -177,5 +177,8 @@ + + + \ No newline at end of file diff --git a/bemade_sports_clinic/models/__init__.py b/bemade_sports_clinic/models/__init__.py index 150c09b..bd829d6 100644 --- a/bemade_sports_clinic/models/__init__.py +++ b/bemade_sports_clinic/models/__init__.py @@ -1,3 +1,4 @@ from . import patient from . import res_partner from . import sports_team +from . import res_users diff --git a/bemade_sports_clinic/models/patient.py b/bemade_sports_clinic/models/patient.py index 1eec551..0da8916 100644 --- a/bemade_sports_clinic/models/patient.py +++ b/bemade_sports_clinic/models/patient.py @@ -23,12 +23,10 @@ class Patient(models.Model): tracking=True) email = fields.Char(groups="bemade_sports_clinic.group_sports_clinic_user", tracking=True) - contact_ids = fields.Many2many(comodel_name='sports.patient.contact', - relation="patient_contact_rel", - column1="patient_id", - column2="contact_id", - string='Patient Contacts', - groups="bemade_sports_clinic.group_sports_clinic_user") + contact_ids = fields.One2many(comodel_name='sports.patient.contact', + inverse_name='patient_id', + string='Patient Contacts', + groups="bemade_sports_clinic.group_sports_clinic_user") team_ids = fields.Many2many(comodel_name='sports.team', relation='sports_team_patient_rel', column1='patient_id', @@ -64,10 +62,26 @@ class Patient(models.Model): rec.name = ((rec.first_name or "") + " " + (rec.last_name or "")).strip() - @api.depends('practice_status', 'match_status') + @api.depends('practice_status', 'match_status', 'injury_ids.injury_date_time') def _compute_is_injured(self): for rec in self: rec.is_injured = rec.practice_status != 'yes' or rec.match_status != 'yes' + if rec.is_injured: + rec.injured_since = \ + rec.injury_ids.filtered(lambda r: not r.is_resolved).sorted( + 'injury_date_time')[0].injury_date_time + else: + rec.injured_since = False + + def action_view_patient_form(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'sports.patient', + 'res_id': self.id, + 'context': self._context, + } class PatientContact(models.Model): @@ -77,22 +91,19 @@ class PatientContact(models.Model): sequence = fields.Integer(required=True, default=0) name = fields.Char(unaccent=False) contact_type = fields.Selection(selection=[ - ('Mother', 'mother'), - ('Father', 'father'), + ('mother', 'Mother'), + ('father', 'Father'), ('other', 'Other'), ], required=True) phone = fields.Char(unaccent=False, required=True) - patient_id = fields.Many2many(comodel_name='sports.patient', string="Patient", - relation="patient_contact_rel", - column1="contact_id", column2="patient_id", - groups="bemade_sports_clinic.group_sports_clinic_user", - required=True) + patient_id = fields.Many2one(comodel_name='sports.patient', string='Patient') class PatientInjury(models.Model): _name = 'sports.patient.injury' _description = "A patient's injury." _inherit = ['mail.thread', 'mail.activity.mixin'] + _rec_name = 'diagnosis' patient_id = fields.Many2one(comodel_name='sports.patient', string="Patient", @@ -103,7 +114,7 @@ class PatientInjury(models.Model): injury_date_time = fields.Datetime(string='Date and Time of Injury', required=True, default=datetime.now()) internal_notes = fields.Html(tracking=True) - treatment_professional_ids = fields.Many2many(comodel_name='res.partner', + treatment_professional_ids = fields.Many2many(comodel_name='res.users', relation='patient_injury_treatment_pro_rel', column1='patient_injury_id', column2='treatment_pro_id', @@ -117,7 +128,7 @@ class PatientInjury(models.Model): def write(self, vals): super().write(vals) if 'treatment_professional_ids' in vals: - to_subscribe = (self.treatment_professional_ids + to_subscribe = (self.treatment_professional_ids.mapped('partner_id') - self.message_follower_ids.mapped('partner_id')) self.message_subscribe(to_subscribe.ids) @@ -125,7 +136,17 @@ class PatientInjury(models.Model): def create(self, vals_list): res = super().create(vals_list) for rec in res: - to_subscribe = (rec.treatment_professional_ids + to_subscribe = (rec.treatment_professional_ids.mapped('partner_id') - rec.message_follower_ids.mapped('partner_id')) rec.message_subscribe(to_subscribe.ids) return res + + def action_view_injury_form(self): + self.ensure_one() + return { + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'sports.patient.injury', + 'res_id': self.id, + 'context': self._context, + } diff --git a/bemade_sports_clinic/models/res_partner.py b/bemade_sports_clinic/models/res_partner.py index 1481b4a..83ebc5d 100644 --- a/bemade_sports_clinic/models/res_partner.py +++ b/bemade_sports_clinic/models/res_partner.py @@ -5,8 +5,6 @@ from odoo.exceptions import UserError class Partner(models.Model): _inherit = 'res.partner' - is_treatment_professional = fields.Boolean( - compute="_compute_is_treatment_professional", ) owned_team_ids = fields.One2many(comodel_name='sports.team', inverse_name='parent_id') staff_ids = fields.One2many(comodel_name='sports.team.staff', @@ -16,12 +14,3 @@ class Partner(models.Model): string='Teams Served', help='The teams this person works for.') - @api.depends('user_ids.groups_id') - def _compute_is_treatment_professional(self): - user_partners = self.filtered(lambda r: r.user_ids) - non_user_partners = self - user_partners - non_user_partners.is_treatment_professional = False - group = self.env.ref( - 'bemade_sports_clinic.group_sports_clinic_treatment_professional') - for rec in user_partners: - rec.is_treatment_professional = group in rec.user_ids.groups_id diff --git a/bemade_sports_clinic/models/res_users.py b/bemade_sports_clinic/models/res_users.py new file mode 100644 index 0000000..1dcd258 --- /dev/null +++ b/bemade_sports_clinic/models/res_users.py @@ -0,0 +1,14 @@ +from odoo import models, fields, api, _ + + +class User(models.Model): + _inherit = 'res.users' + + is_treatment_professional = fields.Boolean( + compute="_compute_is_treatment_professional", store=True) + + @api.depends('groups_id') + def _compute_is_treatment_professional(self): + for rec in self: + rec.is_treatment_professional = rec.has_group( + 'bemade_sports_clinic.group_sports_clinic_treatment_professional') diff --git a/bemade_sports_clinic/models/sports_team.py b/bemade_sports_clinic/models/sports_team.py index a929006..f2c7b4f 100644 --- a/bemade_sports_clinic/models/sports_team.py +++ b/bemade_sports_clinic/models/sports_team.py @@ -20,10 +20,12 @@ class SportsTeam(models.Model): staff_ids = fields.One2many(comodel_name='sports.team.staff', inverse_name='team_id') head_coach_id = fields.Many2one(comodel_name='res.partner', - compute='_compute_head_coach') + compute='_compute_head_coach', + store=True) head_coach_name = fields.Char(related='head_coach_id.name') head_trainer_id = fields.Many2one(comodel_name='res.partner', - compute='_compute_head_trainer') + compute='_compute_head_trainer', + store=True) head_trainer_name = fields.Char(related='head_trainer_id.name') website = fields.Char() diff --git a/bemade_sports_clinic/security/sports_clinic_rules.xml b/bemade_sports_clinic/security/sports_clinic_rules.xml index 7920433..5e28e76 100644 --- a/bemade_sports_clinic/security/sports_clinic_rules.xml +++ b/bemade_sports_clinic/security/sports_clinic_rules.xml @@ -7,18 +7,10 @@ - [('id', 'in', user.partner_id.staff_team_ids.mapped('patient_ids').ids)] + [('id', 'in', + user.partner_id.team_staff_rel_ids.mapped('team_id').mapped( + 'patient_ids').ids)] - - - Access patient injury records on invitation only - - - - [('message_partner_ids', 'in', user.partner_id.ids)] - - - diff --git a/bemade_sports_clinic/views/sports_clinic_menus.xml b/bemade_sports_clinic/views/sports_clinic_menus.xml index e369bdc..2f1c8b8 100644 --- a/bemade_sports_clinic/views/sports_clinic_menus.xml +++ b/bemade_sports_clinic/views/sports_clinic_menus.xml @@ -29,7 +29,7 @@ Organizations res.partner tree,kanban,form - [('is_company','=', True)] + [('is_company', '=', True)] Patients @@ -41,22 +41,18 @@ name="Sports Clinic" groups="bemade_sports_clinic.group_sports_clinic_user" action="action_view_team"> - - - - - + + + diff --git a/bemade_sports_clinic/views/sports_clinic_portal_views.xml b/bemade_sports_clinic/views/sports_clinic_portal_views.xml index a5627b8..e1b490d 100644 --- a/bemade_sports_clinic/views/sports_clinic_portal_views.xml +++ b/bemade_sports_clinic/views/sports_clinic_portal_views.xml @@ -52,9 +52,10 @@ Name - Play Status Injured Injured Since + Match Status + Practice Status Estimated Return Date @@ -66,12 +67,13 @@ - + + @@ -90,9 +92,10 @@ Name Teams - Play Status Injured Injured Since + Match Status + Practice Status Estimated Return Date @@ -114,12 +117,13 @@ - + + diff --git a/bemade_sports_clinic/views/patient_views.xml b/bemade_sports_clinic/views/sports_patient_views.xml similarity index 78% rename from bemade_sports_clinic/views/patient_views.xml rename to bemade_sports_clinic/views/sports_patient_views.xml index 763cf25..67ab072 100644 --- a/bemade_sports_clinic/views/patient_views.xml +++ b/bemade_sports_clinic/views/sports_patient_views.xml @@ -28,6 +28,27 @@ + + + + + + + sports.patient.view.list + sports.patient + + + + + + + + + + + +