콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
5892 화면

Hi 

I have a pice of code what I use to get a PDF byte string which is created when I try to generate a PDF Document from 'account_move' module. 

But the problem is that PDF file is empty. I take only metadata of the file.

```

​import base64
import datetime
import os
import threading

from dotenv import load_dotenv
from odoo.http import request
from odoo.tools.config import config
from odoo.tools import pdf
from telebot import apihelper, types

from odoo import SUPERUSER_ID, api, fields, http, models, sql_db, _

from . import bot_controller


class AccountMove(models.Model):
​_inherit = 'account.move'
 
 
​automatic_send = fields.Char(compute='auto_send_invoice')
​pdf_file = fields.Binary(string="PDF File", readonly=True)
 
​@api.constrains('state')
​def auto_send_invoice(self, ):
​if self.state == 'posted' and self.move_type == 'out_invoice' and : ​self.env['ir.actions.report']._get_report_from_name('telegram_bot_module.report_tg')

​pdf_content = report._render_qweb_pdf(report.id)
 
​invoice_name = f"invoice_{self.id}.pdf"

 
​with open('invoice_from_action.pdf', 'wb') as file:
​file.write((pdf_file[0]))rning(f"PDF content: {(report)}")
 

 

```

아바타
취소
작성자 베스트 답변

[Solved] by using next code:

report = self.env['ir.actions.report'].sudo()._get_report_from_name(
'account.report_invoice_with_payments')

pdf_file = report._render_qweb_pdf(report.id, record.id)
pdf_file = pdf_file[0]
record.pdf_file = base64.b64encode(pdf_file)

아바타
취소
베스트 답변

Hello Oleg Zubak,

I think you have passed wrong id in report. 

Please find code in comment. 

Hope it will be helpful to you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

아바타
취소

Please find code here :-

pdf_content = report._render_qweb_pdf(report.id)

In report._render_qweb_pdf you have passed report's report.id instead of current record id(account.move)
Here, you can see how to pass current id for any report
In pdf_content you will get complete rendered report

@api.constrains('state')
def auto_send_invoice(self, ):
if self.state == 'posted' and self.move_type == 'out_invoice':
report = self.env['ir.actions.report']
pdf_content = report._render_qweb_pdf('telegram_bot_module.report_tg', res_ids=self.id)

관련 게시물 답글 화면 활동
1
2월 24
2417
1
8월 23
2907
1
3월 23
3409
PDF reports 해결 완료
5
7월 25
2254
0
3월 24
1392