From f33e5593e0e01f41f76f76217ade0702d786a4b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Fri, 15 Mar 2019 22:11:30 +0100
Subject: [PATCH] workflows: export as PDF by default when available (#31230)

---
 tests/test_form_pages.py  | 5 +++++
 tests/test_workflows.py   | 3 +++
 wcs/wf/export_to_model.py | 2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py
index 58b641ff7..2c51612fe 100644
--- a/tests/test_form_pages.py
+++ b/tests/test_form_pages.py
@@ -2912,6 +2912,7 @@ def test_formdata_generated_document_download(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     export_to = ExportToModel()
+    export_to.convert_to_pdf = False
     export_to.label = 'create doc'
     upload = QuixoteUpload('/foo/test.rtf', content_type='application/rtf')
     upload.fp = StringIO.StringIO()
@@ -3001,6 +3002,7 @@ def test_formdata_generated_document_odt_download(pub, odt_template):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     export_to = ExportToModel()
+    export_to.convert_to_pdf = False
     export_to.label = 'create doc'
     template_filename = os.path.join(os.path.dirname(__file__), odt_template)
     template = open(template_filename).read()
@@ -3088,6 +3090,7 @@ def test_formdata_generated_document_odt_download_with_substitution_variable(pub
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     export_to = ExportToModel()
+    export_to.convert_to_pdf = False
     export_to.label = 'create doc'
     export_to.varname = 'created_doc'
     template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
@@ -3361,6 +3364,7 @@ def test_formdata_generated_document_non_interactive(pub):
     wf = Workflow(name='status')
     st1 = wf.add_status('Status1', 'st1')
     export_to = ExportToModel()
+    export_to.convert_to_pdf = False
     export_to.method = 'non-interactive'
     template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
     template = open(template_filename).read()
@@ -3420,6 +3424,7 @@ def test_formdata_generated_document_to_backoffice_field(pub):
 
     st1 = wf.add_status('Status1', 'st1')
     export_to = ExportToModel()
+    export_to.convert_to_pdf = False
     export_to.method = 'non-interactive'
     template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
     template = open(template_filename).read()
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index 0b5521581..241660940 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -2750,6 +2750,7 @@ def test_export_to_model_image(pub):
     pub.substitutions.feed(formdata)
 
     item = ExportToModel()
+    item.convert_to_pdf = False
     item.method = 'non-interactive'
     template_filename = os.path.join(os.path.dirname(__file__), 'template-with-image.odt')
     template = open(template_filename).read()
@@ -2811,6 +2812,7 @@ def test_export_to_model_backoffice_field(pub):
 
     item = ExportToModel()
     item.method = 'non-interactive'
+    item.convert_to_pdf = False
     template_filename = os.path.join(os.path.dirname(__file__), 'template.odt')
     template = open(template_filename).read()
     upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')
@@ -2875,6 +2877,7 @@ def test_export_to_model_django_template(pub):
     upload.fp.write(template)
     upload.fp.seek(0)
     item.model_file = UploadedFile(pub.app_dir, None, upload)
+    item.convert_to_pdf = False
     item.perform(formdata)
 
     new_content = zipfile.ZipFile(open(formdata.evolution[0].parts[0].filename)).read('content.xml')
diff --git a/wcs/wf/export_to_model.py b/wcs/wf/export_to_model.py
index 8c4358e5e..4b54fd5c3 100644
--- a/wcs/wf/export_to_model.py
+++ b/wcs/wf/export_to_model.py
@@ -194,7 +194,7 @@ class ExportToModel(WorkflowStatusItem):
     by = ['_receiver']
     backoffice_info_text = None
     varname = None
-    convert_to_pdf = False
+    convert_to_pdf = bool(transform_to_pdf)
     push_to_portfolio = False
     method = 'interactive'
     backoffice_filefield_id = None
-- 
2.20.1

