[ADD] subscription_oca_portal: expose subscriptions in the portal #5
2
subscription_oca_portal/.gitignore
vendored
Normal file
2
subscription_oca_portal/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.*~
|
||||
*pyc
|
||||
152
subscription_oca_portal/README.md
Normal file
152
subscription_oca_portal/README.md
Normal file
@@ -0,0 +1,152 @@
|
||||
# Subscription OCA Portal
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
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).
|
||||
2
subscription_oca_portal/__init__.py
Normal file
2
subscription_oca_portal/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import controllers
|
||||
from . import models
|
||||
30
subscription_oca_portal/__manifest__.py
Normal file
30
subscription_oca_portal/__manifest__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "subscription_oca_portal",
|
||||
"version": "18.0.1.0.0",
|
||||
"author": "Elabore",
|
||||
"website": "https://git.elabore.coop/elabore/sale-tools",
|
||||
"maintainer": "Stéphan Sainléger",
|
||||
"license": "AGPL-3",
|
||||
"category": "Sales",
|
||||
"summary": "Let portal users consult their own subscriptions.",
|
||||
"depends": [
|
||||
"subscription_oca",
|
||||
"portal",
|
||||
],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"security/subscription_portal_security.xml",
|
||||
"views/subscription_portal_templates.xml",
|
||||
],
|
||||
"assets": {
|
||||
"web.assets_tests": [
|
||||
"subscription_oca_portal/static/src/js/subscription_portal_tour.esm.js",
|
||||
],
|
||||
},
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
||||
1
subscription_oca_portal/controllers/__init__.py
Normal file
1
subscription_oca_portal/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import main
|
||||
168
subscription_oca_portal/controllers/main.py
Normal file
168
subscription_oca_portal/controllers/main.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, http
|
||||
from odoo.exceptions import AccessError, MissingError
|
||||
from odoo.http import request
|
||||
|
||||
from odoo.addons.portal.controllers.portal import CustomerPortal
|
||||
from odoo.addons.portal.controllers.portal import pager as portal_pager
|
||||
|
||||
PAGE_NAME = "Subscriptions"
|
||||
SESSION_HISTORY_KEY = "my_subscriptions_history"
|
||||
|
||||
|
||||
class PortalSubscription(CustomerPortal):
|
||||
"""Expose ``sale.subscription`` records as read-only portal documents."""
|
||||
|
||||
def _prepare_home_portal_values(self, counters):
|
||||
"""Add the subscription counter displayed on the portal home page.
|
||||
|
||||
:param counters: list of counter names requested by the portal home.
|
||||
:return: the portal home values, with ``subscription_count`` added when
|
||||
it was requested. The count is ``0`` for users without read access
|
||||
so that the home entry stays hidden instead of raising.
|
||||
"""
|
||||
values = super()._prepare_home_portal_values(counters)
|
||||
if "subscription_count" in counters:
|
||||
subscription_model = request.env["sale.subscription"]
|
||||
values["subscription_count"] = (
|
||||
subscription_model.search_count([])
|
||||
if subscription_model.has_access("read")
|
||||
else 0
|
||||
)
|
||||
return values
|
||||
|
||||
def _subscription_portal_invoices(self, subscription_sudo):
|
||||
"""Return the subscription invoices the current visitor may read.
|
||||
|
||||
Subscription invoices are created in ``sudo`` by ``subscription_oca``,
|
||||
so nothing guarantees the customer is allowed to read them: the portal
|
||||
rule of ``account.move`` requires a posted move the partner follows.
|
||||
Browsing the moves with the visitor's own environment and filtering on
|
||||
the effective access right keeps the detail page free of dead links.
|
||||
|
||||
:param subscription_sudo: ``sale.subscription`` singleton, in sudo.
|
||||
:return: an ``account.move`` recordset, possibly empty, readable by the
|
||||
current user and restricted to posted moves.
|
||||
"""
|
||||
subscription_sudo.ensure_one()
|
||||
posted_invoices = subscription_sudo.invoice_ids.filtered(
|
||||
lambda move: move.state == "posted"
|
||||
)
|
||||
return (
|
||||
request.env["account.move"]
|
||||
.browse(posted_invoices.ids)
|
||||
._filtered_access("read")
|
||||
)
|
||||
|
||||
def _subscription_get_page_view_values(
|
||||
self, subscription_sudo, access_token, **kwargs
|
||||
):
|
||||
"""Build the rendering values of the subscription detail page.
|
||||
|
||||
:param subscription_sudo: ``sale.subscription`` singleton, in sudo.
|
||||
:param access_token: share token used to reach the page, or ``None``.
|
||||
:param kwargs: extra values forwarded to ``_get_page_view_values``.
|
||||
:return: dict of QWeb values, including the prev/next record browsing
|
||||
keys computed by the portal from the session history.
|
||||
"""
|
||||
values = {
|
||||
"page_name": PAGE_NAME,
|
||||
"subscription": subscription_sudo,
|
||||
"invoices": self._subscription_portal_invoices(subscription_sudo),
|
||||
}
|
||||
return self._get_page_view_values(
|
||||
subscription_sudo,
|
||||
access_token,
|
||||
values,
|
||||
SESSION_HISTORY_KEY,
|
||||
False,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@http.route(
|
||||
["/my/subscriptions", "/my/subscriptions/page/<int:page>"],
|
||||
type="http",
|
||||
auth="user",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_subscriptions(self, page=1, sortby=None, **kw):
|
||||
"""Render the paginated list of the current user's subscriptions.
|
||||
|
||||
Record-level filtering is delegated to the portal ``ir.rule``, so the
|
||||
search domain stays empty on purpose.
|
||||
|
||||
:param page: 1-based page number.
|
||||
:param sortby: key of ``searchbar_sortings``; defaults to the start date.
|
||||
:param kw: extra query string arguments, ignored.
|
||||
:return: the rendered list page, or a redirect to ``/my`` when the user
|
||||
has no read access on subscriptions.
|
||||
:raise KeyError: if ``sortby`` is not a known sorting key.
|
||||
"""
|
||||
subscription_model = request.env["sale.subscription"]
|
||||
if not subscription_model.has_access("read"):
|
||||
return request.redirect("/my")
|
||||
values = self._prepare_portal_layout_values()
|
||||
searchbar_sortings = {
|
||||
"date_start": {"label": _("Start Date"), "order": "date_start desc"},
|
||||
"recurring_next_date": {
|
||||
"label": _("Next Invoice Date"),
|
||||
"order": "recurring_next_date desc",
|
||||
},
|
||||
"code": {"label": _("Reference"), "order": "code desc"},
|
||||
}
|
||||
if not sortby:
|
||||
sortby = "date_start"
|
||||
order = searchbar_sortings[sortby]["order"]
|
||||
subscription_count = subscription_model.search_count([])
|
||||
pager = portal_pager(
|
||||
url="/my/subscriptions",
|
||||
url_args={"sortby": sortby},
|
||||
total=subscription_count,
|
||||
page=page,
|
||||
step=self._items_per_page,
|
||||
)
|
||||
subscriptions = subscription_model.search(
|
||||
[], order=order, limit=self._items_per_page, offset=pager["offset"]
|
||||
)
|
||||
request.session[SESSION_HISTORY_KEY] = subscriptions.ids[:100]
|
||||
values.update(
|
||||
{
|
||||
"subscriptions": subscriptions,
|
||||
"page_name": PAGE_NAME,
|
||||
"pager": pager,
|
||||
"default_url": "/my/subscriptions",
|
||||
"searchbar_sortings": searchbar_sortings,
|
||||
"sortby": sortby,
|
||||
}
|
||||
)
|
||||
return request.render("subscription_oca_portal.portal_my_subscriptions", values)
|
||||
|
||||
@http.route(
|
||||
["/my/subscriptions/<int:subscription_id>"],
|
||||
type="http",
|
||||
auth="public",
|
||||
website=True,
|
||||
)
|
||||
def portal_my_subscription_detail(self, subscription_id, access_token=None, **kw):
|
||||
"""Render one subscription, by ownership or by share token.
|
||||
|
||||
:param subscription_id: database id of the subscription.
|
||||
:param access_token: share token allowing access without ownership.
|
||||
:param kw: extra query string arguments forwarded to the view values.
|
||||
:return: the rendered detail page, or a redirect to ``/my`` when the
|
||||
record is missing or not accessible.
|
||||
"""
|
||||
try:
|
||||
subscription_sudo = self._document_check_access(
|
||||
"sale.subscription", subscription_id, access_token
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
values = self._subscription_get_page_view_values(
|
||||
subscription_sudo, access_token, **kw
|
||||
)
|
||||
return request.render(
|
||||
"subscription_oca_portal.portal_subscription_page", values
|
||||
)
|
||||
200
subscription_oca_portal/i18n/fr.po
Normal file
200
subscription_oca_portal/i18n/fr.po
Normal file
@@ -0,0 +1,200 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * subscription_oca_portal
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 18.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-20 20:17+0000\n"
|
||||
"PO-Revision-Date: 2026-10-20 20:17+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: fr\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: nplurals=2; plural=n > 1;\n"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Communication</strong>"
|
||||
msgstr "<strong>Communication</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Customer:</strong>"
|
||||
msgstr "<strong>Client :</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Finish Date</strong>"
|
||||
msgstr "<strong>Date de fin</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Invoices</strong>"
|
||||
msgstr "<strong>Factures</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Next Invoice Date</strong>"
|
||||
msgstr "<strong>Date de prochaine facture</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Recurring Price</strong>"
|
||||
msgstr "<strong>Prix récurrent</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Reference</strong>"
|
||||
msgstr "<strong>Référence</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Stage</strong>"
|
||||
msgstr "<strong>Étape</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Start Date</strong>"
|
||||
msgstr "<strong>Date de début</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Subscription Template</strong>"
|
||||
msgstr "<strong>Modèle d'abonnement</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Total</strong>"
|
||||
msgstr "<strong>Total</strong>"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_warning
|
||||
msgid "Access warning"
|
||||
msgstr "Avertissement d'accès"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Amount Due"
|
||||
msgstr "Montant dû"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,help:subscription_oca_portal.field_sale_subscription__access_url
|
||||
msgid "Customer Portal URL"
|
||||
msgstr "URL du portail client"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Description"
|
||||
msgstr "Description"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Discount (%)"
|
||||
msgstr "Remise (%)"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_subscription
|
||||
msgid "Follow your recurring subscriptions"
|
||||
msgstr "Suivez vos abonnements récurrents"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Invoice"
|
||||
msgstr "Facture"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Invoice Date"
|
||||
msgstr "Date de facturation"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Next Invoice Date"
|
||||
msgstr "Date de prochaine facture"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_url
|
||||
msgid "Portal Access URL"
|
||||
msgstr "URL d'accès au portail"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Quantity"
|
||||
msgstr "Quantité"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Recurring Price"
|
||||
msgstr "Prix récurrent"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Reference"
|
||||
msgstr "Référence"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_token
|
||||
msgid "Security Token"
|
||||
msgstr "Jeton de sécurité"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Stage"
|
||||
msgstr "Étape"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Start Date"
|
||||
msgstr "Date de début"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model,name:subscription_oca_portal.model_sale_subscription
|
||||
msgid "Subscription"
|
||||
msgstr "Abonnement"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Subscription -"
|
||||
msgstr "Abonnement -"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Subscription Template"
|
||||
msgstr "Modèle d'abonnement"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_menu_subscription
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_subscription
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Subscriptions"
|
||||
msgstr "Abonnements"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Subtotal"
|
||||
msgstr "Sous-total"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Taxes"
|
||||
msgstr "Taxes"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Unit Price"
|
||||
msgstr "Prix unitaire"
|
||||
199
subscription_oca_portal/i18n/subscription_oca_portal.pot
Normal file
199
subscription_oca_portal/i18n/subscription_oca_portal.pot
Normal file
@@ -0,0 +1,199 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * subscription_oca_portal
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 18.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-10-20 20:17+0000\n"
|
||||
"PO-Revision-Date: 2026-10-20 20:17+0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Communication</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Customer:</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Finish Date</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Invoices</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Next Invoice Date</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Recurring Price</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Reference</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Stage</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Start Date</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Subscription Template</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "<strong>Total</strong>"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_warning
|
||||
msgid "Access warning"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Amount Due"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,help:subscription_oca_portal.field_sale_subscription__access_url
|
||||
msgid "Customer Portal URL"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Description"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Discount (%)"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_subscription
|
||||
msgid "Follow your recurring subscriptions"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Invoice"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Invoice Date"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Next Invoice Date"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_url
|
||||
msgid "Portal Access URL"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Quantity"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Recurring Price"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Reference"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model.fields,field_description:subscription_oca_portal.field_sale_subscription__access_token
|
||||
msgid "Security Token"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Stage"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#. odoo-python
|
||||
#: code:addons/subscription_oca_portal/controllers/main.py:0
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Start Date"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model:ir.model,name:subscription_oca_portal.model_sale_subscription
|
||||
msgid "Subscription"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Subscription -"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Subscription Template"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_menu_subscription
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_home_subscription
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_my_subscriptions
|
||||
msgid "Subscriptions"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Subtotal"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Taxes"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Total"
|
||||
msgstr ""
|
||||
|
||||
#. module: subscription_oca_portal
|
||||
#: model_terms:ir.ui.view,arch_db:subscription_oca_portal.portal_subscription_page
|
||||
msgid "Unit Price"
|
||||
msgstr ""
|
||||
1
subscription_oca_portal/models/__init__.py
Normal file
1
subscription_oca_portal/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import sale_subscription
|
||||
31
subscription_oca_portal/models/sale_subscription.py
Normal file
31
subscription_oca_portal/models/sale_subscription.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class SaleSubscription(models.Model):
|
||||
"""Turn subscriptions into shareable portal documents.
|
||||
|
||||
``subscription_oca`` declares ``sale.subscription`` as a mail thread only.
|
||||
Adding ``portal.mixin`` brings in ``access_token`` / ``access_url``, which
|
||||
the portal controllers need for ownership checks and token-based sharing.
|
||||
"""
|
||||
|
||||
_name = "sale.subscription"
|
||||
_inherit = ["sale.subscription", "portal.mixin"]
|
||||
|
||||
def _compute_access_url(self):
|
||||
"""Point each subscription at its portal detail page.
|
||||
|
||||
``portal.mixin`` computes ``access_url`` as ``'#'``; this override makes
|
||||
``get_portal_url()`` and ``_get_share_url()`` resolve to the route
|
||||
served by ``PortalSubscription.portal_my_subscription_detail``.
|
||||
|
||||
:return: whatever ``portal.mixin`` returns, i.e. ``None``. The method
|
||||
assigns ``access_url`` on every record of ``self``.
|
||||
"""
|
||||
result = super()._compute_access_url()
|
||||
for subscription in self:
|
||||
subscription.access_url = f"/my/subscriptions/{subscription.id}"
|
||||
return result
|
||||
3
subscription_oca_portal/pyproject.toml
Normal file
3
subscription_oca_portal/pyproject.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[build-system]
|
||||
requires = ["whool"]
|
||||
build-backend = "whool.buildapi"
|
||||
5
subscription_oca_portal/security/ir.model.access.csv
Normal file
5
subscription_oca_portal/security/ir.model.access.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_sale_subscription_portal,sale.subscription portal,subscription_oca.model_sale_subscription,base.group_portal,1,0,0,0
|
||||
access_sale_subscription_line_portal,sale.subscription.line portal,subscription_oca.model_sale_subscription_line,base.group_portal,1,0,0,0
|
||||
access_sale_subscription_stage_portal,sale.subscription.stage portal,subscription_oca.model_sale_subscription_stage,base.group_portal,1,0,0,0
|
||||
access_sale_subscription_template_portal,sale.subscription.template portal,subscription_oca.model_sale_subscription_template,base.group_portal,1,0,0,0
|
||||
|
@@ -0,0 +1,26 @@
|
||||
<?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 noupdate="1">
|
||||
<!-- Portal users only ever see the subscriptions billed to their own
|
||||
commercial partner, or to one of its children. Mirrors the domain used
|
||||
by account for portal invoices. -->
|
||||
<record id="sale_subscription_rule_portal" model="ir.rule">
|
||||
<field name="name">Portal Subscriptions</field>
|
||||
<field name="model_id" ref="subscription_oca.model_sale_subscription" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>[('partner_id', 'child_of', [user.commercial_partner_id.id])]</field>
|
||||
<field name="groups" eval="[Command.link(ref('base.group_portal'))]" />
|
||||
</record>
|
||||
<!-- Without this rule the read access granted above on the line model would
|
||||
expose every subscription line to every portal user. -->
|
||||
<record id="sale_subscription_line_rule_portal" model="ir.rule">
|
||||
<field name="name">Portal Subscription Lines</field>
|
||||
<field name="model_id" ref="subscription_oca.model_sale_subscription_line" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>[('sale_subscription_id.partner_id', 'child_of', [user.commercial_partner_id.id])]</field>
|
||||
<field name="groups" eval="[Command.link(ref('base.group_portal'))]" />
|
||||
</record>
|
||||
</odoo>
|
||||
11
subscription_oca_portal/static/src/img/subscription_icon.svg
Normal file
11
subscription_oca_portal/static/src/img/subscription_icon.svg
Normal file
@@ -0,0 +1,11 @@
|
||||
<svg width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M13.2 25.2 A20 20 0 0 1 50.8 25.2" stroke="#374874" stroke-width="4.5" stroke-linecap="round" fill="none"/>
|
||||
<path d="M50.8 38.8 A20 20 0 0 1 13.2 38.8" stroke="#C1DBF6" stroke-width="4.5" stroke-linecap="round" fill="none"/>
|
||||
<path d="M53.9 33.7 L55.7 25.6 L47.3 28.6 Z" fill="#374874"/>
|
||||
<path d="M10.1 30.3 L8.3 38.4 L16.7 35.4 Z" fill="#C1DBF6"/>
|
||||
<rect x="23.5" y="27" width="17" height="14.5" rx="2.5" fill="#374874"/>
|
||||
<rect x="27.2" y="22.5" width="2.6" height="9" rx="1.3" fill="#374874"/>
|
||||
<rect x="34.2" y="22.5" width="2.6" height="9" rx="1.3" fill="#374874"/>
|
||||
<rect x="23.5" y="31.2" width="17" height="1.6" fill="#C1DBF6"/>
|
||||
<rect x="27" y="34.5" width="4" height="4" rx="0.8" fill="#C1DBF6"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 831 B |
@@ -0,0 +1,17 @@
|
||||
import {redirect} from "@web/core/utils/urls";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
registry.category("web_tour.tours").add("subscription_oca_portal_tour", {
|
||||
url: "/my",
|
||||
steps: () => [
|
||||
{
|
||||
content: "Go to the subscription list",
|
||||
trigger: 'a[href*="/my/subscriptions"]',
|
||||
run: () => redirect("/my/subscriptions"),
|
||||
},
|
||||
{
|
||||
content: "Open the first subscription",
|
||||
trigger: "table.o_portal_my_doc_table tr:eq(0)",
|
||||
},
|
||||
],
|
||||
});
|
||||
1
subscription_oca_portal/tests/__init__.py
Normal file
1
subscription_oca_portal/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_portal
|
||||
281
subscription_oca_portal/tests/test_portal.py
Normal file
281
subscription_oca_portal/tests/test_portal.py
Normal file
@@ -0,0 +1,281 @@
|
||||
# Copyright 2026 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import Command, fields
|
||||
from odoo.tests import HttpCase, tagged
|
||||
|
||||
INVOICE_LINK_CLASS = "tr_subscription_invoice_link"
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestSubscriptionPortal(HttpCase):
|
||||
"""Cover the portal exposure of ``sale.subscription``.
|
||||
|
||||
The fixtures build a minimal accounting setup on purpose: the CI database
|
||||
is installed without demo data nor chart of accounts, so invoices cannot be
|
||||
posted without declaring an income account, a receivable account and a sale
|
||||
journal first.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.portal_group = cls.env.ref("base.group_portal")
|
||||
cls.draft_stage = cls.env.ref("subscription_oca.subscription_stage_draft")
|
||||
cls.template = cls.env["sale.subscription.template"].create(
|
||||
{"name": "Portal Monthly", "code": "PMON"}
|
||||
)
|
||||
cls.pricelist = cls.env["product.pricelist"].create(
|
||||
{
|
||||
"name": "Portal Test Pricelist",
|
||||
"currency_id": cls.env.company.currency_id.id,
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{"name": "Portal Subscription Service", "type": "service"}
|
||||
)
|
||||
cls.customer = cls.env["res.partner"].create(
|
||||
{"name": "Portal Customer", "is_company": True}
|
||||
)
|
||||
cls.contact = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Portal Contact",
|
||||
"parent_id": cls.customer.id,
|
||||
"email": "portal.contact@example.org",
|
||||
}
|
||||
)
|
||||
cls.outsider = cls.env["res.partner"].create(
|
||||
{"name": "Outsider Customer", "is_company": True}
|
||||
)
|
||||
cls.portal_user = cls._create_portal_user("portal-subscriber", cls.contact)
|
||||
cls.outsider_user = cls._create_portal_user("portal-outsider", cls.outsider)
|
||||
cls.subscription = cls._create_subscription(cls.customer)
|
||||
cls.outsider_subscription = cls._create_subscription(cls.outsider)
|
||||
cls._setup_minimal_accounting()
|
||||
|
||||
@classmethod
|
||||
def _create_portal_user(cls, login, partner):
|
||||
"""Create a portal user bound to an existing partner.
|
||||
|
||||
:param login: login and password of the new user.
|
||||
:param partner: ``res.partner`` record used as the user contact.
|
||||
:return: the created ``res.users`` record.
|
||||
"""
|
||||
return cls.env["res.users"].create(
|
||||
{
|
||||
"name": login,
|
||||
"login": login,
|
||||
"password": login,
|
||||
"partner_id": partner.id,
|
||||
"groups_id": [Command.set(cls.portal_group.ids)],
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _create_subscription(cls, partner):
|
||||
"""Create a one-line subscription billed to ``partner``.
|
||||
|
||||
The stage is forced because ``subscription_oca`` only defaults it when
|
||||
both ``date_start`` and ``recurring_next_date`` are passed to ``create``.
|
||||
|
||||
:param partner: ``res.partner`` record billed by the subscription.
|
||||
:return: the created ``sale.subscription`` record.
|
||||
"""
|
||||
return cls.env["sale.subscription"].create(
|
||||
{
|
||||
"partner_id": partner.id,
|
||||
"template_id": cls.template.id,
|
||||
"pricelist_id": cls.pricelist.id,
|
||||
"stage_id": cls.draft_stage.id,
|
||||
"sale_subscription_line_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"product_id": cls.product.id,
|
||||
"name": "Portal subscription line",
|
||||
"product_uom_qty": 2.0,
|
||||
"price_unit": 50.0,
|
||||
"tax_ids": [Command.clear()],
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _setup_minimal_accounting(cls):
|
||||
"""Declare the accounts and journal required to post a customer invoice.
|
||||
|
||||
:return: None. Sets ``cls.income_account`` and ``cls.sale_journal``.
|
||||
"""
|
||||
cls.income_account = cls.env["account.account"].create(
|
||||
{
|
||||
"name": "Portal Test Income",
|
||||
"code": "PTI400",
|
||||
"account_type": "income",
|
||||
}
|
||||
)
|
||||
receivable_account = cls.env["account.account"].create(
|
||||
{
|
||||
"name": "Portal Test Receivable",
|
||||
"code": "PTR110",
|
||||
"account_type": "asset_receivable",
|
||||
"reconcile": True,
|
||||
}
|
||||
)
|
||||
cls.sale_journal = cls.env["account.journal"].create(
|
||||
{
|
||||
"name": "Portal Test Sales",
|
||||
"code": "PTSAJ",
|
||||
"type": "sale",
|
||||
"default_account_id": cls.income_account.id,
|
||||
}
|
||||
)
|
||||
(cls.customer | cls.contact).property_account_receivable_id = receivable_account
|
||||
|
||||
def _create_subscription_invoice(self, post):
|
||||
"""Create an invoice attached to ``self.subscription``.
|
||||
|
||||
:param post: whether the invoice must be posted; a draft invoice is
|
||||
invisible to portal users by design.
|
||||
:return: the created ``account.move`` record.
|
||||
"""
|
||||
invoice = self.env["account.move"].create(
|
||||
{
|
||||
"move_type": "out_invoice",
|
||||
"partner_id": self.customer.id,
|
||||
"journal_id": self.sale_journal.id,
|
||||
"invoice_date": fields.Date.today(),
|
||||
"subscription_id": self.subscription.id,
|
||||
"invoice_line_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"name": "Portal invoice line",
|
||||
"quantity": 1.0,
|
||||
"price_unit": 100.0,
|
||||
"account_id": self.income_account.id,
|
||||
"tax_ids": [Command.clear()],
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
if post:
|
||||
invoice.action_post()
|
||||
invoice.message_subscribe(partner_ids=self.customer.ids)
|
||||
return invoice
|
||||
|
||||
def _authenticated_open(self, user, url, allow_redirects=True):
|
||||
"""Log ``user`` in and request ``url``.
|
||||
|
||||
:param user: ``res.users`` record whose login equals its password.
|
||||
:param url: portal URL to request.
|
||||
:param allow_redirects: whether the client follows redirections.
|
||||
:return: the ``requests.Response`` object.
|
||||
"""
|
||||
self.authenticate(user.login, user.login)
|
||||
return self.url_open(url, allow_redirects=allow_redirects)
|
||||
|
||||
def test_access_url_points_to_portal_page(self):
|
||||
self.assertEqual(
|
||||
self.subscription.access_url,
|
||||
f"/my/subscriptions/{self.subscription.id}",
|
||||
)
|
||||
|
||||
def test_record_rule_hides_other_partners_subscriptions(self):
|
||||
visible = self.env["sale.subscription"].with_user(self.portal_user).search([])
|
||||
self.assertEqual(visible, self.subscription)
|
||||
|
||||
def test_record_rule_hides_other_partners_lines(self):
|
||||
visible = (
|
||||
self.env["sale.subscription.line"].with_user(self.portal_user).search([])
|
||||
)
|
||||
self.assertEqual(visible, self.subscription.sale_subscription_line_ids)
|
||||
|
||||
def test_list_shows_only_own_subscriptions(self):
|
||||
response = self._authenticated_open(self.portal_user, "/my/subscriptions")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn(self.subscription.name, response.text)
|
||||
self.assertNotIn(self.outsider_subscription.name, response.text)
|
||||
|
||||
def test_list_accepts_every_declared_sorting(self):
|
||||
for sortby in ("date_start", "recurring_next_date", "code"):
|
||||
with self.subTest(sortby=sortby):
|
||||
response = self._authenticated_open(
|
||||
self.portal_user, f"/my/subscriptions?sortby={sortby}"
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_detail_is_readable_by_owner(self):
|
||||
response = self._authenticated_open(
|
||||
self.portal_user, f"/my/subscriptions/{self.subscription.id}"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Portal subscription line", response.text)
|
||||
|
||||
def test_detail_is_denied_to_other_portal_user(self):
|
||||
response = self._authenticated_open(
|
||||
self.outsider_user,
|
||||
f"/my/subscriptions/{self.subscription.id}",
|
||||
allow_redirects=False,
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 303)
|
||||
self.assertTrue(response.headers["Location"].endswith("/my"))
|
||||
|
||||
def test_detail_is_readable_with_access_token(self):
|
||||
token = self.subscription._portal_ensure_token()
|
||||
|
||||
# A public session, so that the request resolves to the test database.
|
||||
self.authenticate(None, None)
|
||||
response = self.url_open(
|
||||
f"/my/subscriptions/{self.subscription.id}?access_token={token}"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("Portal subscription line", response.text)
|
||||
|
||||
def test_home_counter_counts_only_own_subscriptions(self):
|
||||
self.authenticate(self.portal_user.login, self.portal_user.login)
|
||||
|
||||
counters = self.make_jsonrpc_request(
|
||||
"/my/counters", {"counters": ["subscription_count"]}
|
||||
)
|
||||
|
||||
self.assertEqual(counters["subscription_count"], 1)
|
||||
|
||||
def test_home_declares_the_subscription_entry(self):
|
||||
response = self._authenticated_open(self.portal_user, "/my")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn("subscription_count", response.text)
|
||||
|
||||
def test_detail_lists_posted_invoices_only(self):
|
||||
self._create_subscription_invoice(post=False)
|
||||
posted_invoice = self._create_subscription_invoice(post=True)
|
||||
|
||||
response = self._authenticated_open(
|
||||
self.portal_user, f"/my/subscriptions/{self.subscription.id}"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.text.count(INVOICE_LINK_CLASS), 1)
|
||||
self.assertIn(posted_invoice.name, response.text)
|
||||
|
||||
def test_detail_hides_invoices_from_token_visitor(self):
|
||||
self._create_subscription_invoice(post=True)
|
||||
token = self.subscription._portal_ensure_token()
|
||||
|
||||
self.authenticate(None, None)
|
||||
response = self.url_open(
|
||||
f"/my/subscriptions/{self.subscription.id}?access_token={token}"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotIn(INVOICE_LINK_CLASS, response.text)
|
||||
|
||||
def test_tour(self):
|
||||
self.start_tour(
|
||||
"/my", "subscription_oca_portal_tour", login=self.portal_user.login
|
||||
)
|
||||
307
subscription_oca_portal/views/subscription_portal_templates.xml
Normal file
307
subscription_oca_portal/views/subscription_portal_templates.xml
Normal 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>
|
||||
Reference in New Issue
Block a user