[ADD] survey_xlsx_expand_multiple_choice, survey_xlsx_extra_fields
survey_xlsx_expand_multiple_choice: expand multiple_choice questions into one Oui/Non column per option, and matrix questions into one column per row (value = selected option). Relies on the extension hooks added to survey_xlsx. survey_xlsx_extra_fields: bridge (auto_install) with survey_extra_fields that excludes 'file' question types from the XLSX export. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1
survey_xlsx_extra_fields/__init__.py
Normal file
1
survey_xlsx_extra_fields/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import report
|
||||
19
survey_xlsx_extra_fields/__manifest__.py
Normal file
19
survey_xlsx_extra_fields/__manifest__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Copyright 2025 Elabore
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "Survey XLSX - Extra Fields Bridge",
|
||||
"summary": """
|
||||
Excludes 'file' question types from the survey XLSX export""",
|
||||
"version": "18.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
"application": False,
|
||||
"auto_install": True,
|
||||
"author": "Elabore",
|
||||
"website": "https://elabore.coop",
|
||||
"depends": [
|
||||
"survey_xlsx_expand_multiple_choice",
|
||||
"survey_extra_fields",
|
||||
],
|
||||
}
|
||||
1
survey_xlsx_extra_fields/report/__init__.py
Normal file
1
survey_xlsx_extra_fields/report/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import report_survey_xlsx
|
||||
15
survey_xlsx_extra_fields/report/report_survey_xlsx.py
Normal file
15
survey_xlsx_extra_fields/report/report_survey_xlsx.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2025 Elabore
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import models
|
||||
|
||||
|
||||
class ReportSurveyXlsx(models.AbstractModel):
|
||||
_inherit = "report.survey.xlsx"
|
||||
|
||||
def _write_question_header(self, sheet, question, cols, bold):
|
||||
# "file" questions store uploaded attachments that cannot be rendered
|
||||
# in a spreadsheet cell: skip them so no column is created. Without a
|
||||
# column, _process_user_answer ignores their answers automatically.
|
||||
if question.question_type == "file":
|
||||
return
|
||||
return super()._write_question_header(sheet, question, cols, bold)
|
||||
1
survey_xlsx_extra_fields/tests/__init__.py
Normal file
1
survey_xlsx_extra_fields/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_report
|
||||
55
survey_xlsx_extra_fields/tests/test_report.py
Normal file
55
survey_xlsx_extra_fields/tests/test_report.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# Copyright 2025 Elabore
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import io
|
||||
|
||||
import openpyxl
|
||||
|
||||
from odoo.addons.survey.tests import common
|
||||
|
||||
|
||||
class TestExcludeFileQuestion(common.TestSurveyCommon):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.text_question = self._add_question(
|
||||
self.page_0,
|
||||
"Your name",
|
||||
"char_box",
|
||||
survey_id=self.survey.id,
|
||||
)
|
||||
self.file_question = self._add_question(
|
||||
self.page_0,
|
||||
"Upload your document",
|
||||
"file",
|
||||
constr_mandatory=False,
|
||||
survey_id=self.survey.id,
|
||||
)
|
||||
answer = self._add_answer(self.survey, False, email="test@example.com")
|
||||
self._add_answer_line(self.text_question, answer, "Alice")
|
||||
self.env["survey.user_input.line"].create({
|
||||
"user_input_id": answer.id,
|
||||
"question_id": self.file_question.id,
|
||||
"answer_type": "file",
|
||||
"skipped": False,
|
||||
"value_file": "ZmFrZQ==",
|
||||
"value_file_fname": "doc.pdf",
|
||||
})
|
||||
answer._mark_done()
|
||||
|
||||
def _get_sheet(self):
|
||||
report = self.env.ref("survey_xlsx.report_survey_xlsx")
|
||||
rep = self.env["ir.actions.report"]._render(report, self.survey.ids, {})
|
||||
wb = openpyxl.load_workbook(io.BytesIO(rep[0]))
|
||||
return wb.worksheets[0]
|
||||
|
||||
def _find_col(self, sheet, header):
|
||||
for col in range(1, sheet.max_column + 1):
|
||||
if sheet.cell(1, col).value == header:
|
||||
return col
|
||||
return None
|
||||
|
||||
def test_file_question_excluded(self):
|
||||
sheet = self._get_sheet()
|
||||
# Regular questions are still exported
|
||||
self.assertIsNotNone(self._find_col(sheet, "Your name"))
|
||||
# File questions get no column at all
|
||||
self.assertIsNone(self._find_col(sheet, "Upload your document"))
|
||||
Reference in New Issue
Block a user