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

so i have a print report function as follows:

def print_first_consult_report(self):
return self.env.ref('my_model.action_my_report').report_action(self)

now I need to write a corn job to download this report and attach it to a binary field which I have 

@api.model
def download_and_attach_report(self):
# Get all timelines (you may want to filter this based on your requirements)
timelines = self.search([]) # Adjust the domain as necessary

for timeline in timelines:
report = self.env.ref('my_model.action_my_report')
if report._name == 'ir.actions.report':
# Render the PDF for the specific record ID(s)
pdf_content, _ = report._render_qweb_pdf([self.id])

# If you need to save it as an attachment
data_record = base64.b64encode(pdf_content)
attachment = self.env['attachment.model'].create({
'name': "First consult",
'datas': data_record,
'type': 'binary',
'patient_attachment_timeline_id': self.id,
'mimetype': 'application/x-pdf'
})

# Attach it to the patient timeline
self.patient_attachment_ids = [(4, attachment.id)]
else:
raise ValueError("The specified report action was not found or is not correctly defined.")

I tried the following approach by looking through other similar questions but I cant manage to do it can someone guide me on what to do

아바타
취소
관련 게시물 답글 화면 활동
3
9월 23
11615
1
8월 24
5066
0
5월 21
3526
2
1월 25
2798
1
5월 24
7248