From 588bf6b2bb6d5b6c9e4bea62566dc5abb45fa4b5 Mon Sep 17 00:00:00 2001 From: mizosoft Date: Fri, 12 Apr 2024 16:47:46 +0200 Subject: [PATCH] [FIX] account: use proforma preview for non-printed invoices Issue ----- If an invoice is created, but not yet "Send & Print", the portal preview shows a normal invoice, but when "Download"ed from the portal preview, a proforma invoice is downloaded. The download behavior is intended since the client shouldn't be able to get a "final" invoice themselves, before the accountant generates one with "Send & Print". However, the HTML preview should also show a proforma invoice to be consistent with this, so the user downloads what they see. Steps ----- - Create a new invoice: Accounting -> Customers -> Invoices -> New -> ... - Go to portal by clicking on "Preview". - You'll see a normal invoice. Now click "Download". - A proforma invoice is downloaded. Cause ----- The HTML-rendered invoice in the portal preview isn't configured to be proforma. opw-3848049 closes odoo/odoo#161726 Signed-off-by: Claire Bretton (clbr) --- addons/account/controllers/portal.py | 2 ++ addons/account/models/ir_actions_report.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 5f4d5cffb40..c59286cf381 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -143,6 +143,8 @@ class PortalAccount(CustomerPortal): return request.make_response(attachments.raw, list(headers.items())) elif report_type in ('html', 'pdf', 'text'): + has_generated_invoice = bool(invoice_sudo.invoice_pdf_report_id) + request.update_context(proforma_invoice=not has_generated_invoice) return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download) values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) diff --git a/addons/account/models/ir_actions_report.py b/addons/account/models/ir_actions_report.py index a1d46948c50..b2216f0eb1b 100644 --- a/addons/account/models/ir_actions_report.py +++ b/addons/account/models/ir_actions_report.py @@ -75,3 +75,9 @@ class IrActionsReport(models.Model): master_report = self.env.ref(f"account.{master_xmlid}", raise_if_not_found=False) if master_report and master_report in self: raise UserError(_("You cannot delete this report (%s), it is used by the accounting PDF generation engine.", master_report.name)) + + def _get_rendering_context(self, report, docids, data): + data = super()._get_rendering_context(report, docids, data) + if self.env.context.get('proforma_invoice'): + data['proforma'] = True + return data