I have this code bellow in odoo 16, when I want to print single document/download it works!
But if want to print three or more documents I got this error:
PyPDF2.utils.PdfReadError: Cannot read an empty file
This is my code:
def print_receituario(self):
report = self.env.ref("dental_clinic.action_dental_prescription_report", False)
dental_record = self.dental_record_id
patient = self.dental_record_id.patient_id
if not (len(dental_record) == 1):
return
if len(self) == 1:
report_name = safe_eval(report.print_report_name, {"object": self})
else:
report_name = f"Receituário - {patient.name}"
pdf_content, _ = (
self.env["ir.actions.report"]
.with_context(lang=patient.lang)
.sudo()
._render_qweb_pdf(report.id, self.ids, data={"company_id": self.env.company})
)
attachment = self.env["ir.attachment"].create(
{
"name": report_name,
"res_model": "dental.record",
"res_id": dental_record.id,
"datas": base64.b64encode(pdf_content),
}
)
return {"type": "ir.actions.act_url", "url": f"/web/content/{attachment.id}"}
Can anyone explain it to me?
Hope to hear you shortly!