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',
})
@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):
""" 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)
if not team:
raise UserError(_('This team could not be found.'))
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)
players = http.request.env['sports.patient'].search([
('team_ids', 'in', team_id),
@ -88,12 +89,14 @@ class TeamStaffPortal(CustomerPortal):
'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)
def view_player(self, player_id, team_id=None,**kw):
""" 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)
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:
raise UserError(_('This player could not be found.'))
injuries = player.injury_ids.filtered(lambda r: r.stage == 'active')
@ -102,6 +105,7 @@ class TeamStaffPortal(CustomerPortal):
qcontext={
'player': player,
'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)
patient_name = fields.Char(related="patient_id.name")
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())
injury_date_na = fields.Boolean(string="N/A", default=False)
internal_notes = fields.Html(tracking=True)

View file

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