I'd like to generate a PDF containing all "stock.report_picking" reports for all deliveries for a given sale order, merged into one file.
I've already done something similar for shipping labels where each label was saved as an "ir.attachment" record. But in this case, the "stock.report_picking" report doesn't appear to be saved anywhere as far as I can tell. It appears to be regenerated on the fly whenever the user opens the "Print" menu and clicks on the report action (or if I go to "/report/pdf/stock.report_picking/{id}").
So how would I generate the report in Python such that I can get the binary PDF data for the report (similar to the "datas" field on an attachment record) so I can then pass a list of report "datas" to the "merge_pdf" function in the Odoo "tools" module?
I can then get my final result and do whatever I want with it (send it back via an HTTP response, save it in an attachment record, or whatever).
I know I could just make an HTTP request to "/report/pdf/stock.report_picking/{id}" for each record I want a report for, and then grab the binary data from the response. That just seems like the wrong way to achieve something I should be able to do right inside of Python. I can't find anything in the official documentation concerning how to achieve this.
So then, back to the title: How do I generate a PDF report from Python?
I figured it out, but apparently I need more karma to post an answer. 🙄
I also asked this question on StackOverflow yesterday and answered it there. Since the formatting tools for code are 1000x better over there, I'm not going to repost it here.
https://stackoverflow.com/a/71970692/14953293