Remove migrations file. Fix controller and portal view breadcrumbs.

This commit is contained in:
Marc Durepos 2023-11-21 06:27:18 -05:00
parent 26603aeea9
commit 814841943f
4 changed files with 43 additions and 50 deletions

View file

@ -47,14 +47,15 @@ class TeamStaffPortal(CustomerPortal):
'page_name': 'my_teams', 'page_name': 'my_teams',
}) })
@http.route(route=['/my/team/<int:team_id>', '/my/team/<int:team_id>/page/<int:page>'], type='http', auth='user', website=True) @http.route(route=['/my/team', '/my/team/page/<int:page>'], type='http', auth='user', website=True)
def view_team(self, team_id, page=0, **kw): def view_team(self, team_id, page=0, **kw):
""" Display the information for a team including its list of players """ """ Display the information for a team including its list of players """
team_id = int(team_id)
team = http.request.env['sports.team'].browse(team_id) team = http.request.env['sports.team'].browse(team_id)
if not team: if not team:
raise UserError(_('This team could not be found.')) raise UserError(_('This team could not be found.'))
players_count = team.player_count players_count = team.player_count
pgr = pager(url=f'/my/team/{team_id}', total=players_count, page=page, step=10, pgr = pager(url=f'/my/team?team_id={team_id}', total=players_count, page=page, step=10,
scope=5) scope=5)
players = http.request.env['sports.patient'].search([ players = http.request.env['sports.patient'].search([
('team_ids', 'in', team_id), ('team_ids', 'in', team_id),
@ -88,12 +89,14 @@ class TeamStaffPortal(CustomerPortal):
'page_name': 'my_players', 'page_name': 'my_players',
}) })
@http.route(route=['/my/players/<int:player_id>', '/my/players/<int:player_id>/<int:team_id>'], type='http', @http.route(route=['/my/player'], type='http',
auth='user', website=True) auth='user', website=True)
def view_player(self, player_id, team_id=None,**kw): def view_player(self, player_id, team_id=None,**kw):
""" Display the active injuries for a given player. """ """ Display the active injuries for a given player. """
player_id = int(player_id)
team_id = team_id and int(team_id)
player = http.request.env['sports.patient'].browse(player_id) player = http.request.env['sports.patient'].browse(player_id)
team = team_id and http.request.env['sports.team'].browse(player_id) team = team_id and http.request.env['sports.team'].browse(team_id)
if not player: if not player:
raise UserError(_('This player could not be found.')) raise UserError(_('This player could not be found.'))
injuries = player.injury_ids.filtered(lambda r: r.stage == 'active') injuries = player.injury_ids.filtered(lambda r: r.stage == 'active')
@ -102,6 +105,7 @@ class TeamStaffPortal(CustomerPortal):
qcontext={ qcontext={
'player': player, 'player': player,
'injuries': injuries, 'injuries': injuries,
'team': team 'team': team,
'page_name': 'my_player',
} }
) )

View file

@ -1,11 +0,0 @@
from odoo import api, SUPERUSER_ID
def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
patients = env['sports.patient'].search([('partner_id', '=', False)])
for patient in patients:
partner = env['res.partner'].create({
'name': patient._get_name_from_first_and_last(patient.first_name, patient.last_name),
'patient_ids': [(4, patient.id)]
})

View file

@ -232,7 +232,7 @@ class PatientInjury(models.Model):
required=True) required=True)
patient_name = fields.Char(related="patient_id.name") patient_name = fields.Char(related="patient_id.name")
diagnosis = fields.Char(tracking=True) diagnosis = fields.Char(tracking=True)
injury_date = fields.Date(string='Date and Time of Injury', injury_date = fields.Date(string='Date of Injury',
default=date.today()) default=date.today())
injury_date_na = fields.Boolean(string="N/A", default=False) injury_date_na = fields.Boolean(string="N/A", default=False)
internal_notes = fields.Html(tracking=True) internal_notes = fields.Html(tracking=True)

View file

@ -32,7 +32,7 @@
<tr> <tr>
<td> <td>
<strong> <strong>
<a t-attf-href="/my/team/{{ team.id }}" <a t-attf-href="/my/team?team_id={{ team.id }}"
t-field="team.name"/> t-field="team.name"/>
</strong> </strong>
</td> </td>
@ -63,7 +63,8 @@
<tbody> <tbody>
<t t-foreach="players" t-as="player"> <t t-foreach="players" t-as="player">
<t t-set="stage" t-value="player.stage"/> <t t-set="stage" t-value="player.stage"/>
<t t-set="url" t-value="'/my/players/' + str(player.id) + '/' + str(team.id)"/> <t t-set="url"
t-value="'/my/player?player_id=' + str(player.id) + '&amp;team_id=' + str(team.id)"/>
<tr t-attf-class="{{ ('text-danger' if stage == 'no_play' <tr t-attf-class="{{ ('text-danger' if stage == 'no_play'
else 'text-warning') if stage != 'healthy' else 'text-warning') if stage != 'healthy'
else '' }}"> else '' }}">
@ -115,7 +116,7 @@
<tbody> <tbody>
<t t-foreach="players" t-as="player"> <t t-foreach="players" t-as="player">
<t t-set="stage" t-value="player.stage"/> <t t-set="stage" t-value="player.stage"/>
<t t-set="url" t-value="'/my/players/' + str(player.id)"/> <t t-set="url" t-value="'/my/player?player_id=' + str(player.id)"/>
<tr t-attf-class="{{ ('text-danger' if stage == 'no_play' <tr t-attf-class="{{ ('text-danger' if stage == 'no_play'
else 'text-warning') if stage != 'healthy' else 'text-warning') if stage != 'healthy'
else '' }}"> else '' }}">
@ -129,7 +130,7 @@
<ul class="list-unstyled"> <ul class="list-unstyled">
<t t-foreach="player.team_ids" t-as="team"> <t t-foreach="player.team_ids" t-as="team">
<li> <li>
<a t-attf-href="/my/team/{{ team.id }}" <a t-attf-href="/my/team?team_id={{ team.id }}"
t-field="team.name"/> t-field="team.name"/>
</li> </li>
</t> </t>
@ -185,35 +186,34 @@
</template> </template>
<template id="portal_breadcrumbs" inherit_id="portal.portal_breadcrumbs"> <template id="portal_breadcrumbs" inherit_id="portal.portal_breadcrumbs">
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside"> <xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li t-if="page_name == 'my_teams'" <!-- Show link back to teams if team is set, otherwise just title the Teams-->
t-attf-class="breadcrumb-item #{'active ' if not team else ''}"> <t t-if="page_name == 'my_teams'">
<a t-if="team" <li t-attf-class="breadcrumb-item #{'active ' if not team else ''}">
t-attf-href="/my/teams?{{ keep_query() }}">Teams</a> <a t-if="team" t-attf-href="/my/teams">Teams</a>
<t t-else="">Teams</t> <t t-else="">Teams</t>
</li> </li>
<li t-if="page_name == 'my_teams' and team" class="breadcrumb-item active" t-esc="team.name"/> <!-- Show the team name as the title if we're looking at a specific team -->
<li t-if="page_name == 'my_players'" <li t-if="team" class="breadcrumb-item active" t-esc="team.name"/>
t-attf-class="breadcrumb-item #{'active ' if not player else ''}"> </t>
<a t-if="player" <!-- If just listing players, show the "Players" title -->
t-attf-href="/my/players?{{ keep_query() }}">Players</a> <li t-if="page_name == 'my_players'" class="breadcrumb-item active">Players</li>
<t t-else="">Players</t> <t t-if="page_name == 'my_player'">
</li> <!-- The single player page can be reached from the players list or the teams list.
<li t-if="player and page_name == 'my_player'" class="breadcrumb-item active"> If it was reached from the teams list, the team parameter will be set and should be the first
<a t-attf-href="/my/players?{{ keep_query() }}">Players</a> breadcrumb -->
<span t-field="player.name"/> <t t-if="team">
</li> <li class="breadcrumb-item">
<li t-if="player and team" class="breadcrumb-item"> <a href="/my/teams">Teams</a>
<a href="/my/teams">Teams</a> </li>
</li> <li class="breadcrumb-item">
<li t-if="player" class="breadcrumb-item"> <a t-attf-href="/my/team?team_id={{ team.id }}"><span t-field="team.name"/></a>
<a t-if="team" t-attf-href="/my/team/{{ team.id }}?{{ keep_query() }}"> </li>
<span t-field="team.name"/> </t>
</a> <li t-else="" class="breadcrumb-item">
<a t-else="" t-attf-href="/my/players/{{ keep_query() }}">Players</a> <a t-attf-href="/my/players">Players</a>
</li> </li>
<li t-if="player" class="breadcrumb-item active"> <li class="breadcrumb-item active"><span t-field="player.name"/></li>
<span t-field="player.name"/> </t>
</li>
</xpath> </xpath>
</template> </template>
</data> </data>