[IMP] tax_receipt_in_portal: pick report per company, hide missing PDFs
Replace the ``tax_receipt_in_portal.report_uuid`` system parameter by a per-company setting, in Settings > Invoicing > Tax Receipts (``res.company.tax_receipt_report_id``). Each receipt is rendered with the report of its issuing company, not the current one: in the portal, the current company is the website's. The selector only offers PDF Form reports on ``l10n.fr.tax.receipt``; type and model are still checked at rendering time since the report can be edited after selection. The download buttons of the list and detail pages are only shown when the PDF can actually be rendered: a valid report is configured for the issuing company and no mapped field resolves to an empty value. The checks are those of the rendering itself, exposed as a filter (``_get_pdf_available_receipts``) and run in sudo to avoid false negatives on field paths the donor cannot read. Otherwise a discreet "PDF available soon" mention replaces the button, and the download URL redirects to the receipt page. The detail page download link now also carries the share token, so a visitor reaching the page by token can download the PDF.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
"""Portal routes exposing a donor's own tax receipts."""
|
||||
|
||||
from werkzeug.urls import url_encode
|
||||
|
||||
from odoo import http
|
||||
from odoo.exceptions import AccessError, MissingError
|
||||
from odoo.http import content_disposition, request
|
||||
@@ -97,6 +99,7 @@ class TaxReceiptCustomerPortal(CustomerPortal):
|
||||
"page_name": "tax_receipt",
|
||||
"tax_receipt": receipt_sudo,
|
||||
"invoices": self._tax_receipt_portal_invoices(receipt_sudo),
|
||||
"pdf_available": bool(receipt_sudo._get_pdf_available_receipts()),
|
||||
}
|
||||
return self._get_page_view_values(
|
||||
receipt_sudo,
|
||||
@@ -139,6 +142,11 @@ class TaxReceiptCustomerPortal(CustomerPortal):
|
||||
values.update(
|
||||
{
|
||||
"tax_receipts": receipts_page,
|
||||
# Computed on the current page only: at most one page of
|
||||
# receipts is checked per request.
|
||||
"pdf_available_ids": set(
|
||||
receipts_page._get_pdf_available_receipts().ids
|
||||
),
|
||||
"page_name": "tax_receipt",
|
||||
"pager": pager,
|
||||
"default_url": "/my/tax-receipts",
|
||||
@@ -191,11 +199,17 @@ class TaxReceiptCustomerPortal(CustomerPortal):
|
||||
rule or on the share token — so a draft receipt or another donor's
|
||||
receipt is refused.
|
||||
|
||||
When the PDF cannot be rendered (no report configured for the
|
||||
issuing company, or a blank mapped field), the visitor is sent back
|
||||
to the receipt page, which then shows no download button. This
|
||||
covers a configuration change between page display and click.
|
||||
|
||||
:param receipt_id: database id of the requested receipt.
|
||||
:param access_token: share token allowing access without
|
||||
ownership.
|
||||
:return: an ``application/pdf`` response, or a redirect to
|
||||
``/my`` when the receipt is not accessible.
|
||||
:return: an ``application/pdf`` response, a redirect to the
|
||||
receipt page when no PDF is available, or a redirect to ``/my``
|
||||
when the receipt is not accessible.
|
||||
"""
|
||||
try:
|
||||
receipt_sudo = self._document_check_access(
|
||||
@@ -203,6 +217,11 @@ class TaxReceiptCustomerPortal(CustomerPortal):
|
||||
)
|
||||
except (AccessError, MissingError):
|
||||
return request.redirect("/my")
|
||||
if not receipt_sudo._get_pdf_available_receipts():
|
||||
detail_url = f"/my/tax-receipts/{receipt_sudo.id}"
|
||||
if access_token:
|
||||
detail_url += "?" + url_encode({"access_token": access_token})
|
||||
return request.redirect(detail_url)
|
||||
pdf_bytes, filename = receipt_sudo._render_tax_receipt_pdf()
|
||||
headers = [
|
||||
("Content-Type", "application/pdf"),
|
||||
|
||||
Reference in New Issue
Block a user