[ADD] subscription_oca_portal: expose subscriptions in the portal
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m34s
tests / test (pull_request) Successful in 2m39s

Add the missing portal layer for subscription_oca, modelled on the
portal of the OCA contract module:

- sale.subscription inherits portal.mixin; access_url resolves to
  /my/subscriptions/<id>
- read-only ACLs (base.group_portal) on subscription, line, stage and
  template models, with record rules restricting both subscription and
  lines to the user's own commercial partner
- CustomerPortal extension: home counter, paginated and sortable list,
  detail page with lines, totals and a portal chatter
- related invoices are listed only when posted and actually readable by
  the visitor, since subscription_oca creates them in sudo
- /my home entry with a recurring-cycle icon (circular arrows around a
  calendar, matching the portal icon palette)
- 13 tests, fr.po translation catalog

Chatter headings carry mb-4: the frontend portal chatter paints an
opaque sticky bar 15px above its container, which would otherwise clip
the heading (same overlap exists on core portal pages, hidden behind
their taller h3).

Portal body loop variables avoid the names `invoice` and `subscription`:
qweb renders a t-call body before the layout it calls in the same values
dict, so top-level loop variables leak into the breadcrumb context where
account's portal_breadcrumbs template tests t-if="invoice".
This commit is contained in:
Stéphan Sainléger
2026-10-20 23:18:43 +02:00
parent 252fee9c99
commit 18e7ae8925
18 changed files with 1437 additions and 0 deletions

View File

@@ -0,0 +1,307 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2026 Stéphan Sainléger (Elabore)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template
id="portal_my_home_menu_subscription"
name="Portal layout: subscription menu entries"
inherit_id="portal.portal_breadcrumbs"
priority="35"
>
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li
t-if="page_name == 'Subscriptions'"
t-attf-class="breadcrumb-item #{'active ' if not subscription else ''}"
>
<a
t-if="subscription"
t-attf-href="/my/subscriptions?{{ keep_query() }}"
>Subscriptions</a>
<t t-else="">Subscriptions</t>
</li>
<!-- page_name is part of the condition for the same reason as the
`portal_invoice` rename below: a leaked `subscription` variable
from another portal page body must not activate this item. -->
<li
t-if="page_name == 'Subscriptions' and subscription"
class="breadcrumb-item active"
>
<t t-out="subscription.name" />
</li>
</xpath>
</template>
<template
id="portal_my_home_subscription"
name="Show Subscriptions"
inherit_id="portal.portal_my_home"
customize_show="True"
priority="30"
>
<div id="portal_common_category" position="inside">
<t t-call="portal.portal_docs_entry">
<t
t-set="icon"
t-value="'/subscription_oca_portal/static/src/img/subscription_icon.svg'"
/>
<t t-set="title">Subscriptions</t>
<t t-set="text">Follow your recurring subscriptions</t>
<t t-set="url" t-value="'/my/subscriptions'" />
<t t-set="placeholder_count" t-value="'subscription_count'" />
</t>
</div>
</template>
<template id="portal_my_subscriptions" name="My Subscriptions">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True" />
<t t-call="portal.portal_searchbar">
<t t-set="title">Subscriptions</t>
</t>
<t t-if="subscriptions" t-call="portal.portal_table">
<thead>
<tr class="active">
<th>Reference</th>
<th class="d-none d-md-table-cell">Subscription Template</th>
<th class="d-none d-md-table-cell">Start Date</th>
<th class="d-none d-md-table-cell">Next Invoice Date</th>
<th class="text-end">Recurring Price</th>
<th class="text-end">Stage</th>
</tr>
</thead>
<tbody>
<tr t-foreach="subscriptions" t-as="subscription">
<td>
<a
t-att-href="subscription.get_portal_url()"
t-attf-class="tr_subscription_link"
t-att-title="subscription.name"
>
<t t-out="subscription.name" />
</a>
</td>
<td class="d-none d-md-table-cell">
<span t-field="subscription.template_id" />
</td>
<td class="d-none d-md-table-cell">
<span t-field="subscription.date_start" />
</td>
<td class="d-none d-md-table-cell">
<span t-field="subscription.recurring_next_date" />
</td>
<td class="text-end">
<span t-field="subscription.recurring_total" />
</td>
<td class="text-end">
<span t-field="subscription.stage_id" />
</td>
</tr>
</tbody>
</t>
</t>
</template>
<template id="portal_subscription_page" name="My Subscription">
<t t-call="portal.portal_layout">
<h5 class="mb-0">
<span>Subscription - <span t-field="subscription.name" /></span>
</h5>
<div id="general_information">
<div class="row mt-4">
<div
t-if="subscription.partner_id"
class="col-12 col-md-6 mb-4 mb-md-0"
>
<h6><strong>Customer:</strong></h6>
<address
t-field="subscription.partner_id"
t-options='{"widget": "contact", "fields": ["name", "email", "phone"]}'
/>
</div>
</div>
<div class="row mt-4" id="subscription_information">
<div class="col-12 col-md-6 mb-4 mb-md-0">
<div t-if="subscription.code" class="row mb-2 mb-sm-1">
<div class="col-12 col-sm-4"><strong>Reference</strong></div>
<div class="col-12 col-sm-8">
<span t-field="subscription.code" />
</div>
</div>
<div t-if="subscription.template_id" class="row mb-2 mb-sm-1">
<div
class="col-12 col-sm-4"
><strong>Subscription Template</strong></div>
<div class="col-12 col-sm-8">
<span t-field="subscription.template_id" />
</div>
</div>
<div t-if="subscription.stage_id" class="row mb-2 mb-sm-1">
<div class="col-12 col-sm-4"><strong>Stage</strong></div>
<div class="col-12 col-sm-8">
<span t-field="subscription.stage_id" />
</div>
</div>
</div>
<div class="col-12 col-md-6">
<div t-if="subscription.date_start" class="row mb-2 mb-sm-1">
<div
class="col-12 col-sm-4"
><strong>Start Date</strong></div>
<div class="col-12 col-sm-8">
<span
t-field="subscription.date_start"
t-options='{"widget": "date"}'
/>
</div>
</div>
<div
t-if="subscription.recurring_next_date"
class="row mb-2 mb-sm-1"
>
<div
class="col-12 col-sm-4"
><strong>Next Invoice Date</strong></div>
<div class="col-12 col-sm-8">
<span
t-field="subscription.recurring_next_date"
t-options='{"widget": "date"}'
/>
</div>
</div>
<div t-if="subscription.date" class="row mb-2 mb-sm-1">
<div
class="col-12 col-sm-4"
><strong>Finish Date</strong></div>
<div class="col-12 col-sm-8">
<span
t-field="subscription.date"
t-options='{"widget": "date"}'
/>
</div>
</div>
</div>
</div>
<div id="subscription_lines">
<table class="table table-sm" id="subscription_line_table">
<thead class="bg-100">
<tr>
<th name="th_name" class="text-start">Description</th>
<th name="th_quantity" class="text-end">Quantity</th>
<th name="th_price_unit" class="text-end">Unit Price</th>
<th
name="th_discount"
class="text-end"
>Discount (%)</th>
<th
name="th_price_subtotal"
class="text-end"
>Subtotal</th>
</tr>
</thead>
<tbody class="subscription_tbody">
<tr
t-foreach="subscription.sale_subscription_line_ids"
t-as="line"
>
<td name="td_name"><span t-field="line.name" /></td>
<td name="td_quantity" class="text-end">
<span t-field="line.product_uom_qty" />
</td>
<td name="td_price_unit" class="text-end">
<span
t-field="line.price_unit"
t-options='{"widget": "monetary", "display_currency": subscription.currency_id}'
/>
</td>
<td name="td_discount" class="text-end">
<span t-field="line.discount" />
</td>
<td name="td_price_subtotal" class="text-end">
<span
t-field="line.price_subtotal"
t-options='{"widget": "monetary", "display_currency": subscription.currency_id}'
/>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4" class="text-end">
<strong>Recurring Price</strong>
</td>
<td class="text-end">
<span t-field="subscription.recurring_total" />
</td>
</tr>
<tr>
<td colspan="4" class="text-end">Taxes</td>
<td class="text-end">
<span t-field="subscription.amount_tax" />
</td>
</tr>
<tr>
<td colspan="4" class="text-end">
<strong>Total</strong>
</td>
<td class="text-end">
<strong><span
t-field="subscription.amount_total"
/></strong>
</td>
</tr>
</tfoot>
</table>
</div>
<div t-if="invoices" id="subscription_invoices" class="mt-4">
<h6><strong>Invoices</strong></h6>
<table class="table table-sm" id="subscription_invoice_table">
<thead class="bg-100">
<tr>
<th class="text-start">Invoice</th>
<th class="text-end">Invoice Date</th>
<th class="text-end">Total</th>
<th class="text-end">Amount Due</th>
</tr>
</thead>
<tbody>
<!-- The loop variable must not be named `invoice`:
the body of a t-call is rendered before the
layout it calls (ir_qweb _compile_directive_call),
so a top-level `invoice` variable would leak
into the breadcrumb context, where account's
portal_breadcrumbs template tests
t-if="invoice". -->
<tr t-foreach="invoices" t-as="portal_invoice">
<td>
<a
t-attf-href="/my/invoices/#{portal_invoice.id}"
t-attf-class="tr_subscription_invoice_link"
>
<t t-out="portal_invoice.name" />
</a>
</td>
<td class="text-end">
<span
t-field="portal_invoice.invoice_date"
t-options='{"widget": "date"}'
/>
</td>
<td class="text-end">
<span t-field="portal_invoice.amount_total" />
</td>
<td class="text-end">
<span t-field="portal_invoice.amount_residual" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="subscription_communication" class="mt-4">
<!-- mb-4 is required: the frontend portal chatter paints an
opaque sticky bar 15px above its own container
(portal/static/src/chatter/core/portal_chatter.xml), which
would otherwise cover the bottom of this heading. -->
<h6 class="mb-4"><strong>Communication</strong></h6>
<t t-call="portal.message_thread" />
</div>
</t>
</template>
</odoo>