Files
Stéphan Sainléger 18e7ae8925
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m34s
tests / test (pull_request) Successful in 2m39s
[ADD] subscription_oca_portal: expose subscriptions in the portal
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".
2026-10-20 23:28:32 +02:00

153 lines
6.6 KiB
Markdown

# Subscription OCA Portal
![Beta](https://img.shields.io/badge/maturity-Beta-yellow.png)
![License: AGPL-3](https://img.shields.io/badge/licence-AGPL--3-blue.png)
![Gitea](https://img.shields.io/badge/gitea-elabore%2Fsale--tools-lightgray.png)
This module lets portal users consult the subscriptions (`subscription_oca`) that are
billed to them, from the Odoo customer portal.
`subscription_oca` ships no portal at all: `sale.subscription` is not a portal document,
its access rights are limited to the salesman group and it has no record rule. This
module adds the missing portal layer, read-only, modelled on the portal of the OCA
`contract` module.
## Table of Contents
- [Description](#description)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Security Model](#security-model)
- [Known Issues / Roadmap](#known-issues--roadmap)
- [Bug Tracker](#bug-tracker)
- [Credits](#credits)
## Description
### Portal document
`sale.subscription` inherits `portal.mixin`, which brings the `access_token` and
`access_url` fields. `access_url` resolves to `/my/subscriptions/<id>`, so
`get_portal_url()` and the share links built by `_get_share_url()` point at the portal
page instead of the backend.
### Routes
| Route | Auth | Purpose |
| ------------------------------- | ------ | ------------------------------------------- |
| `/my/subscriptions` | user | Paginated list of the user's subscriptions |
| `/my/subscriptions/page/<page>` | user | Page N of that list |
| `/my/subscriptions/<id>` | public | Detail page, by ownership or by share token |
The list is sortable by start date (default), next invoice date, and reference. An entry
is added to the portal home page (`/my`), with a counter that reflects the record rule.
### Detail page
The detail page shows the customer, the reference, the subscription template, the stage,
the start / next invoice / finish dates, the subscription lines (description, quantity,
unit price, discount, subtotal), the recurring price, the taxes, the total, the related
invoices, and a portal chatter.
Only **posted** invoices that the visitor is actually allowed to read are listed.
`subscription_oca` creates its invoices in `sudo`, so nothing guarantees the customer
may read them: the portal rule of `account.move` requires a posted move whose followers
include the customer's commercial partner. Invoices are therefore re-browsed with the
visitor's own environment and filtered on the effective read access, which keeps the
page free of dead links. A visitor arriving with a share token sees no invoice at all.
### Out of scope
The portal is strictly read-only. Cancelling, renewing or modifying a subscription, and
online or recurring payment, are not covered.
## Installation
This module depends on:
- `subscription_oca` (OCA, [contract](https://github.com/OCA/contract) repository)
- `portal` (Odoo core)
Use the standard Odoo module installation procedure to install
`subscription_oca_portal`.
## Configuration
No specific configuration is required. The portal entry appears as soon as a portal user
owns at least one subscription.
The customer's contacts see the subscriptions of their company, because the record rule
matches the commercial partner and its children. No action is needed to share a
subscription with the contacts of a company.
## Usage
1. Create a subscription for a customer that has a portal user.
2. Log in to the portal with that user: the **Subscriptions** card appears on `/my`.
3. Open the card to list the subscriptions, then click a reference to see its detail.
4. To share a subscription with someone who has no account, use the `access_token` of
the record as a query string parameter:
`/my/subscriptions/<id>?access_token=<token>`.
## Security Model
| Model | Portal access | Record rule |
| ---------------------------- | ------------- | --------------------------------------------------------------------- |
| `sale.subscription` | read | `partner_id` is the user's commercial partner, or one of its children |
| `sale.subscription.line` | read | the parent subscription matches the same condition |
| `sale.subscription.stage` | read | none: stage names are configuration data |
| `sale.subscription.template` | read | none: template names are configuration data |
The rule on the line model is not optional: without it, the read access granted on
`sale.subscription.line` would expose every subscription line to every portal user.
Granting read access on the stage and template models exposes their names to all portal
users. These two models are only read to display the stage and the template of a
subscription.
The portal chatter is a write surface: a portal user who can see a subscription can post
messages on it.
## Known Issues / Roadmap
- `subscription_oca` declares no multi-company record rule on `sale.subscription`. This
module does not add one, since that belongs upstream; the portal rule is based on the
partner, so a portal user never sees the subscriptions of another customer, whatever
the company.
- The JS tour (`subscription_oca_portal_tour`) is skipped when the test image ships no
Chrome binary, which is the case of the Elabore CI image. It is kept for parity with
the OCA `contract` portal and runs as soon as a browser is available.
- The heading of the chatter block carries `mb-4` on purpose. The frontend portal
chatter pulls its own sticky bar 15 px above its container and paints it opaque
(`portal/static/src/chatter/core/portal_chatter.xml` and
`portal/static/src/chatter/scss/shadow.scss`), so a heading with less than 15 px of
bottom margin gets its lower half covered. Core portal pages hide the same overlap
behind a much taller `<h3>`.
- The product of a subscription line is deliberately not displayed: `product.product`
grants no read access to the portal group in Odoo 18. The line description is shown
instead.
## Bug Tracker
Bugs are tracked on
[our issue tracker](https://git.elabore.coop/Elabore/sale-tools/issues). In case of
trouble, please check there if your issue has already been reported. If you spotted it
first, help us smash it by providing a detailed and welcomed feedback.
## Credits
### Contributors
- Stéphan Sainléger \<stephan@sainleger.fr\>
### Funders
The development of this module has been financially supported by:
- [Elabore](https://elabore.coop)
### Maintainer
This module is maintained by [Elabore](https://elabore.coop).