Merge branch 'dev-brk-14.0' of :odoo/docx_report into dev-brk-14.0
This commit is contained in:
commit
4575eb773c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
idea/
|
.idea/
|
||||||
.DS_store
|
.DS_store
|
@ -54,7 +54,7 @@ class DocxReportController(ReportController):
|
|||||||
"Content-Type",
|
"Content-Type",
|
||||||
"application/pdf",
|
"application/pdf",
|
||||||
),
|
),
|
||||||
("Content-Length", len(pdf)),
|
("Content-Length", len(pdf[0])),
|
||||||
]
|
]
|
||||||
return request.make_response(pdf, headers=pdfhttpheaders)
|
return request.make_response(pdf, headers=pdfhttpheaders)
|
||||||
else:
|
else:
|
||||||
|
@ -15,6 +15,17 @@ from odoo.exceptions import AccessError, UserError
|
|||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
from odoo.tools.safe_eval import safe_eval, time
|
from odoo.tools.safe_eval import safe_eval, time
|
||||||
|
|
||||||
|
try:
|
||||||
|
from odoo.addons.gotenberg.service.utils import (
|
||||||
|
get_auth, # noqa
|
||||||
|
convert_pdf_from_office_url, # noqa
|
||||||
|
check_gotenberg_installed, # noqa
|
||||||
|
)
|
||||||
|
|
||||||
|
gotenberg_imported = True
|
||||||
|
except ImportError:
|
||||||
|
gotenberg_imported = False
|
||||||
|
|
||||||
_logger = getLogger(__name__)
|
_logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +124,12 @@ class IrActionsReport(models.Model):
|
|||||||
return self_sudo._post_pdf(save_in_attachment), "pdf"
|
return self_sudo._post_pdf(save_in_attachment), "pdf"
|
||||||
|
|
||||||
docx_content = self._render_docx(res_ids, data=data)
|
docx_content = self._render_docx(res_ids, data=data)
|
||||||
pdf_content = self._get_pdf_from_office(docx_content)
|
|
||||||
|
pdf_content = (
|
||||||
|
self._get_pdf_from_office(docx_content)
|
||||||
|
if check_gotenberg_installed()
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
if not pdf_content:
|
if not pdf_content:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
@ -357,10 +373,13 @@ class IrActionsReport(models.Model):
|
|||||||
Вызов конвертации docx в pdf с помощью gotenberg
|
Вызов конвертации docx в pdf с помощью gotenberg
|
||||||
"""
|
"""
|
||||||
result = None
|
result = None
|
||||||
|
url = convert_pdf_from_office_url()
|
||||||
|
auth = get_auth()
|
||||||
try:
|
try:
|
||||||
response = post_request(
|
response = post_request(
|
||||||
"http://gotenberg:8808/convert/office",
|
url,
|
||||||
files={"file": ("converted_file.docx", content_stream.read())},
|
files={"file": ("converted_file.docx", content_stream.read())},
|
||||||
|
auth=auth,
|
||||||
)
|
)
|
||||||
if response.status_code == codes_request.ok:
|
if response.status_code == codes_request.ok:
|
||||||
result = response.content
|
result = response.content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user