[FIX] account: handle download unconfirmed invoice

Steps to reproduce:
-------------------
- create an invoice without confirm it;
- go to the preview and download it;

Issue:
------
A traceback appears.

Cause:
------
We try to get `ids` field of a non "record" object.

Solution:
---------
Make sure you are in the case of an invoice
that is `posted` to download a pdf.

sentry-4612532780

closes odoo/odoo#141640

Signed-off-by: Laurent Smet (las) <las@odoo.com>
Co-authored-by: adwid <awt@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-11-25 01:23:17 +00:00
co-authored by adwid
parent 081966e8b0
commit 4d69358386
+1 -1
View File
@@ -131,7 +131,7 @@ class PortalAccount(CustomerPortal):
except (AccessError, MissingError):
return request.redirect('/my')
if report_type == 'pdf' and download:
if report_type == 'pdf' and download and invoice_sudo.state == 'posted':
# Send & Print wizard with only the 'download' checkbox to get the official attachment(s)
template = request.env.ref(invoice_sudo._get_mail_template())
attachment_ids = invoice_sudo._generate_pdf_and_send_invoice(template, bypass_download=True, checkbox_send_mail=False, checkbox_download=True)