bemade_sports_clinic: second iteration complete.
This commit is contained in:
parent
d92c124f50
commit
93a82074df
13 changed files with 127 additions and 77 deletions
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -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/<int:team_id>'], 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
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@
|
|||
<field name="predicted_resolution_date">2024-02-01</field>
|
||||
<field name="patient_id" ref="patient_1"/>
|
||||
<field name="treatment_professional_ids"
|
||||
eval="[Command.set([ref('base.partner_admin')])]"/>
|
||||
eval="[Command.set([ref('base.user_admin')])]"/>
|
||||
</record>
|
||||
<record id="injury_2" model="sports.patient.injury">
|
||||
<field name="injury_date_time">2022-03-17 19:13:00</field>
|
||||
|
|
@ -141,7 +141,7 @@
|
|||
<field name="predicted_resolution_date">2022-03-23</field>
|
||||
<field name="patient_id" ref="patient_1"/>
|
||||
<field name="treatment_professional_ids"
|
||||
eval="[Command.set([ref('base.partner_admin')])]"/>
|
||||
eval="[Command.set([ref('base.user_admin')])]"/>
|
||||
</record>
|
||||
<record id="injury_3" model="sports.patient.injury">
|
||||
<field name="injury_date_time">2023-10-15 19:55:00</field>
|
||||
|
|
@ -149,7 +149,7 @@
|
|||
<field name="predicted_resolution_date">2023-11-01</field>
|
||||
<field name="patient_id" ref="patient_3"/>
|
||||
<field name="treatment_professional_ids"
|
||||
eval="[Command.set([ref('base.partner_admin')])]"/>
|
||||
eval="[Command.set([ref('base.user_admin')])]"/>
|
||||
</record>
|
||||
<record id="stingers_coach_rel" model="sports.team.staff">
|
||||
<field name="partner_id" ref="base.partner_demo_portal"/>
|
||||
|
|
@ -177,5 +177,8 @@
|
|||
<record id="group_sports_clinic_admin" model="res.groups">
|
||||
<field name="users" eval="[Command.link(ref('base.user_admin'))]"/>
|
||||
</record>
|
||||
<record id="group_sports_clinic_treatment_professional" model="res.groups">
|
||||
<field name="users" eval="[Command.link(ref('base.user_demo'))]"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from . import patient
|
||||
from . import res_partner
|
||||
from . import sports_team
|
||||
from . import res_users
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
14
bemade_sports_clinic/models/res_users.py
Normal file
14
bemade_sports_clinic/models/res_users.py
Normal file
|
|
@ -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')
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -7,18 +7,10 @@
|
|||
<field name="model_id" ref="model_sports_patient"/>
|
||||
<field name="groups" eval="[(6, 0, [ref('base.group_portal')])]"/>
|
||||
<field name="domain_force">
|
||||
[('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)]
|
||||
</field>
|
||||
</record>
|
||||
<!-- Patient injury records should be on invitation only for non-admins -->
|
||||
<record id="restrict_patient_access_to_treatment_professionals" model="ir.rule">
|
||||
<field name="name">Access patient injury records on invitation only</field>
|
||||
<field name="model_id" ref="model_sports_patient_injury"/>
|
||||
<field name="groups" eval="[(6, 0, [ref('group_sports_clinic_user'), ref('group_sports_clinic_treatment_professional')])]"/>
|
||||
<field name="domain_force">
|
||||
[('message_partner_ids', 'in', user.partner_id.ids)]
|
||||
</field>
|
||||
<field name="perm_create" eval="False"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
<field name="name">Organizations</field>
|
||||
<field name="res_model">res.partner</field>
|
||||
<field name="view_mode">tree,kanban,form</field>
|
||||
<field name="domain">[('is_company','=', True)]</field>
|
||||
<field name="domain">[('is_company', '=', True)]</field>
|
||||
</record>
|
||||
<record id="action_view_patient" model="ir.actions.act_window">
|
||||
<field name="name">Patients</field>
|
||||
|
|
@ -41,22 +41,18 @@
|
|||
name="Sports Clinic"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_team">
|
||||
<menuitem id="sports_clinic_clients"
|
||||
name="Contacts"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user">
|
||||
<menuitem id="sports_clinic_organizations"
|
||||
name="Organizations"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_organization"/>
|
||||
<menuitem id="sports_clinic_teams"
|
||||
name="Teams"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_team"/>
|
||||
<menuitem id="sports_clinic_patients"
|
||||
name="Patients"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_patient"/>
|
||||
</menuitem>
|
||||
<menuitem id="sports_clinic_organizations"
|
||||
name="Organizations"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_organization"/>
|
||||
<menuitem id="sports_clinic_teams"
|
||||
name="Teams"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_team"/>
|
||||
<menuitem id="sports_clinic_patients"
|
||||
name="Patients"
|
||||
groups="bemade_sports_clinic.group_sports_clinic_user"
|
||||
action="action_view_patient"/>
|
||||
</menuitem>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -52,9 +52,10 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Play Status</th>
|
||||
<th>Injured</th>
|
||||
<th>Injured Since</th>
|
||||
<th>Match Status</th>
|
||||
<th>Practice Status</th>
|
||||
<th>Estimated Return Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -66,12 +67,13 @@
|
|||
<td>
|
||||
<strong><span t-field="player.name"/></strong>
|
||||
</td>
|
||||
<td><span t-field="player.player_status"/></td>
|
||||
<td><span t-out="injured"/></td>
|
||||
<td>
|
||||
<span t-field="player.injured_since"
|
||||
t-options="{'widget': 'date'}"/>
|
||||
</td>
|
||||
<td><span t-field="player.match_status"/></td>
|
||||
<td><span t-field="player.practice_status"/></td>
|
||||
<td>
|
||||
<span t-field="player.predicted_return_date"
|
||||
t-options="{'widget': 'date'}"/>
|
||||
|
|
@ -90,9 +92,10 @@
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Teams</th>
|
||||
<th>Play Status</th>
|
||||
<th>Injured</th>
|
||||
<th>Injured Since</th>
|
||||
<th>Match Status</th>
|
||||
<th>Practice Status</th>
|
||||
<th>Estimated Return Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -114,12 +117,13 @@
|
|||
</t>
|
||||
</ul>
|
||||
</td>
|
||||
<td><span t-field="player.player_status"/></td>
|
||||
<td><span t-out="injured"/></td>
|
||||
<td>
|
||||
<span t-field="player.injured_since"
|
||||
t-options="{'widget': 'date'}"/>
|
||||
</td>
|
||||
<td><span t-field="player.match_status"/></td>
|
||||
<td><span t-field="player.practice_status"/></td>
|
||||
<td>
|
||||
<span t-field="player.predicted_return_date"
|
||||
t-options="{'widget': 'date'}"/>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,27 @@
|
|||
<field name="team_ids" widget="many2many_tags"/>
|
||||
<field name="match_status"/>
|
||||
<field name="practice_status"/>
|
||||
<field name="predicted_return_date" widget="date"/>
|
||||
<field name="activity_ids" widget="list_activity"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="sports_patient_view_list_embedded" model="ir.ui.view">
|
||||
<field name="name">sports.patient.view.list</field>
|
||||
<field name="model">sports.patient</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Patients" multi_edit="True" editable="bottom">
|
||||
<field name="first_name"/>
|
||||
<field name="last_name"/>
|
||||
<field name="date_of_birth"/>
|
||||
<field name="age"/>
|
||||
<field name="team_ids" widget="many2many_tags"/>
|
||||
<field name="match_status"/>
|
||||
<field name="practice_status"/>
|
||||
<field name="predicted_return_date" widget="date"/>
|
||||
<field name="activity_ids" widget="list_activity"/>
|
||||
<button name="action_view_patient_form" type="object"
|
||||
class="fa fa-arrow-right"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
|
@ -97,8 +118,9 @@
|
|||
<group>
|
||||
<field name="injury_date_time"/>
|
||||
<field name="diagnosis"/>
|
||||
<field name="treatment_professional_ids"/>
|
||||
<field name="internal_notes"/>
|
||||
<field name="treatment_professional_ids"
|
||||
widget="many2many_tags_avatar"/>
|
||||
<field name="predicted_resolution_date"/>
|
||||
</group>
|
||||
</sheet>
|
||||
|
|
@ -114,11 +136,16 @@
|
|||
<field name="name">sports.patient.injury.view.tree</field>
|
||||
<field name="model">sports.patient.injury</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Patient Injury History">
|
||||
<tree string="Patient Injury History" editable="bottom"
|
||||
multi_edit="True">
|
||||
<field name="injury_date_time" widget="datetime"/>
|
||||
<field name="diagnosis"/>
|
||||
<field name="predicted_resolution_date" widget="date"/>
|
||||
<field name="treatment_professional_ids"/>
|
||||
<field name="treatment_professional_ids"
|
||||
widget="many2many_avatar_user"/>
|
||||
<field name="activity_ids" widget="list_activity"/>
|
||||
<button name="action_view_injury_form" type="object"
|
||||
class="fa fa-arrow-right"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
|
@ -111,7 +111,8 @@
|
|||
</group>
|
||||
</group>
|
||||
<separator string="Players"/>
|
||||
<field name="patient_ids" editable="bottom" nolabel="1"/>
|
||||
<field name="patient_ids" nolabel="1"
|
||||
context="{'tree_view_ref': 'bemade_sports_clinic.sports_patient_view_list_embedded'}"/>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
|
|
|
|||
Loading…
Reference in a new issue