From fa84f48a434bab4862378e9ecb69fc691167d488 Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Tue, 9 Nov 2021 10:49:47 +0500 Subject: [PATCH 1/7] typo in gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index dcb7ddb..5289316 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.pyc -idea/ -.DS_store +.idea/ +.DS_store \ No newline at end of file From c49ad27df77e29901af348da72328c642d9ed619 Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Thu, 18 Nov 2021 15:12:35 +0500 Subject: [PATCH 2/7] fix content lenght parameter --- controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/main.py b/controllers/main.py index 5da4b78..6e563b5 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -54,7 +54,7 @@ class DocxReportController(ReportController): "Content-Type", "application/pdf", ), - ("Content-Length", len(pdf)), + ("Content-Length", len(pdf[0])), ] return request.make_response(pdf, headers=pdfhttpheaders) else: From 54c049c104fc11be747c99a1a114d8c018f86489 Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Thu, 18 Nov 2021 15:14:55 +0500 Subject: [PATCH 3/7] add get url gotenberg server and auth for basic authentification --- models/ir_actions_report.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/models/ir_actions_report.py b/models/ir_actions_report.py index efcbe40..a36569a 100644 --- a/models/ir_actions_report.py +++ b/models/ir_actions_report.py @@ -11,6 +11,7 @@ from requests import codes as codes_request, post as post_request from requests.exceptions import RequestException from odoo import _, api, fields, models +from odoo.addons.gotenberg.service.utils import get_auth, convert_pdf_from_office_url from odoo.exceptions import AccessError, UserError from odoo.http import request from odoo.tools.safe_eval import safe_eval, time @@ -356,10 +357,13 @@ class IrActionsReport(models.Model): Вызов конвертации docx в pdf с помощью gotenberg """ result = None + url = convert_pdf_from_office_url() + auth = get_auth() try: response = post_request( - "http://gotenberg:8808/convert/office", + url, files={"file": ("converted_file.docx", content_stream.read())}, + auth=auth ) if response.status_code == codes_request.ok: result = response.content From 6373f1f62e703dfaeeb8c37169ff5b029ec3f5cd Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Fri, 19 Nov 2021 10:28:02 +0500 Subject: [PATCH 4/7] black formatter --- models/ir_actions_report.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/ir_actions_report.py b/models/ir_actions_report.py index a36569a..a04f16e 100644 --- a/models/ir_actions_report.py +++ b/models/ir_actions_report.py @@ -11,7 +11,7 @@ from requests import codes as codes_request, post as post_request from requests.exceptions import RequestException from odoo import _, api, fields, models -from odoo.addons.gotenberg.service.utils import get_auth, convert_pdf_from_office_url +from odoo.addons.gotenberg.service.utils import get_auth, convert_pdf_from_office_url from odoo.exceptions import AccessError, UserError from odoo.http import request from odoo.tools.safe_eval import safe_eval, time @@ -363,7 +363,7 @@ class IrActionsReport(models.Model): response = post_request( url, files={"file": ("converted_file.docx", content_stream.read())}, - auth=auth + auth=auth, ) if response.status_code == codes_request.ok: result = response.content From ca21f97af74c6560ee6f8b0706df1f355b5a58e5 Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Tue, 23 Nov 2021 10:42:29 +0500 Subject: [PATCH 5/7] try import gotenber module if is installed --- models/ir_actions_report.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/models/ir_actions_report.py b/models/ir_actions_report.py index a04f16e..1bd6eec 100644 --- a/models/ir_actions_report.py +++ b/models/ir_actions_report.py @@ -11,11 +11,20 @@ from requests import codes as codes_request, post as post_request from requests.exceptions import RequestException from odoo import _, api, fields, models -from odoo.addons.gotenberg.service.utils import get_auth, convert_pdf_from_office_url from odoo.exceptions import AccessError, UserError from odoo.http import request 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 + ) + + gotenberg_installed = True +except ImportError: + gotenberg_installed = False + _logger = getLogger(__name__) @@ -113,7 +122,10 @@ class IrActionsReport(models.Model): return self_sudo._post_pdf(save_in_attachment), "pdf" 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 gotenberg_installed else None + ) if not pdf_content: raise UserError( From 6aa28edbd8951830a8fc3afaa4f44c1cba38708f Mon Sep 17 00:00:00 2001 From: Vitaly D Date: Mon, 6 Dec 2021 11:34:00 +0500 Subject: [PATCH 6/7] check module gotenberg installed --- models/ir_actions_report.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/ir_actions_report.py b/models/ir_actions_report.py index 1bd6eec..8a8c5e2 100644 --- a/models/ir_actions_report.py +++ b/models/ir_actions_report.py @@ -19,11 +19,12 @@ try: from odoo.addons.gotenberg.service.utils import ( get_auth, # noqa convert_pdf_from_office_url, # noqa + check_gotenberg_installed, # noqa ) - gotenberg_installed = True + gotenberg_imported = True except ImportError: - gotenberg_installed = False + gotenberg_imported = False _logger = getLogger(__name__) @@ -124,7 +125,7 @@ class IrActionsReport(models.Model): docx_content = self._render_docx(res_ids, data=data) pdf_content = ( - self._get_pdf_from_office(docx_content) if gotenberg_installed else None + self._get_pdf_from_office(docx_content) if check_gotenberg_installed() else None ) if not pdf_content: From 22d7a2b4624b9b626a307ea460d46f4b554f354c Mon Sep 17 00:00:00 2001 From: "alexandr.uritskiy" Date: Wed, 16 Mar 2022 01:04:03 +0500 Subject: [PATCH 7/7] format --- models/ir_actions_report.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/ir_actions_report.py b/models/ir_actions_report.py index 8a8c5e2..5179528 100644 --- a/models/ir_actions_report.py +++ b/models/ir_actions_report.py @@ -19,7 +19,7 @@ try: from odoo.addons.gotenberg.service.utils import ( get_auth, # noqa convert_pdf_from_office_url, # noqa - check_gotenberg_installed, # noqa + check_gotenberg_installed, # noqa ) gotenberg_imported = True @@ -125,7 +125,9 @@ class IrActionsReport(models.Model): docx_content = self._render_docx(res_ids, data=data) pdf_content = ( - self._get_pdf_from_office(docx_content) if check_gotenberg_installed() else None + self._get_pdf_from_office(docx_content) + if check_gotenberg_installed() + else None ) if not pdf_content: