-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
843 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../survey_xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
=========== | ||
Survey XLSX | ||
=========== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github | ||
:target: https://github.com/OCA/survey/tree/14.0/survey_xlsx | ||
:alt: OCA/survey | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/survey-14-0/survey-14-0-survey_xlsx | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/200/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to print a XLSX report with the survey results. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/survey/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_xlsx%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Creu Blanca | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Olga Marco <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/survey <https://github.com/OCA/survey/tree/14.0/survey_xlsx>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import report | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2022 CreuBlanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Survey XLSX", | ||
"summary": """ | ||
XLSX Report to show the survey results""", | ||
"version": "15.0.1.0.0", | ||
"license": "AGPL-3", | ||
"installable": True, | ||
"application": False, | ||
"author": "Creu Blanca, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/survey", | ||
"depends": ["survey", "report_xlsx"], | ||
"data": ["report/report_survey_xlsx.xml"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * survey_xlsx | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"PO-Revision-Date: 2022-11-23 10:45+0000\n" | ||
"Last-Translator: Sergio Zanchetta <[email protected]>\n" | ||
"Language-Team: none\n" | ||
"Language: it\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
"X-Generator: Weblate 4.14.1\n" | ||
|
||
#. module: survey_xlsx | ||
#: code:addons/survey_xlsx/report/report_survey_xlsx.py:0 | ||
#, python-format | ||
msgid "Created on" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx__display_name | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line__display_name | ||
msgid "Display Name" | ||
msgstr "Nome visualizzato" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx__id | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line__id | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx____last_update | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line____last_update | ||
msgid "Last Modified on" | ||
msgstr "Ultima modifica il" | ||
|
||
#. module: survey_xlsx | ||
#: code:addons/survey_xlsx/report/report_survey_xlsx.py:0 | ||
#, python-format | ||
msgid "Partner" | ||
msgstr "Partner" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model,name:survey_xlsx.model_survey_user_input_line | ||
msgid "Survey User Input Line" | ||
msgstr "Riga inserimento utente per sondaggio" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.actions.report,name:survey_xlsx.report_survey_xlsx | ||
msgid "XLSX Report Survey" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model,name:survey_xlsx.model_report_survey_xlsx | ||
msgid "XLSX Report to show all the results for the survey" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * survey_xlsx | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: survey_xlsx | ||
#: code:addons/survey_xlsx/report/report_survey_xlsx.py:0 | ||
#, python-format | ||
msgid "Created on" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx__display_name | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx__id | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_report_survey_xlsx____last_update | ||
#: model:ir.model.fields,field_description:survey_xlsx.field_survey_user_input_line____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: code:addons/survey_xlsx/report/report_survey_xlsx.py:0 | ||
#, python-format | ||
msgid "Partner" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model,name:survey_xlsx.model_survey_user_input_line | ||
msgid "Survey User Input Line" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.actions.report,name:survey_xlsx.report_survey_xlsx | ||
msgid "XLSX Report Survey" | ||
msgstr "" | ||
|
||
#. module: survey_xlsx | ||
#: model:ir.model,name:survey_xlsx.model_report_survey_xlsx | ||
msgid "XLSX Report to show all the results for the survey" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import survey_user_input_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2022 CreuBlanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import models | ||
|
||
|
||
class SurveyUserInputLine(models.Model): | ||
_inherit = "survey.user_input.line" | ||
|
||
def _get_xlsx_value(self): | ||
if self.answer_type == "suggestion": | ||
return self.suggested_answer_id.display_name | ||
if self.answer_type == "date": | ||
return self.value_date.isoformat() | ||
return self["value_%s" % self.answer_type] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Olga Marco <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows to print a XLSX report with the survey results. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import report_survey_xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2022 CreuBlanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
import datetime | ||
from collections import defaultdict | ||
|
||
from odoo import _, models | ||
|
||
|
||
class Iterator: | ||
def __init__(self, value=0): | ||
self.value = value | ||
|
||
def next(self): | ||
self.value += 1 | ||
return self.value | ||
|
||
|
||
class ReportSurveyXlsx(models.AbstractModel): | ||
_name = "report.survey.xlsx" | ||
_inherit = "report.report_xlsx.abstract" | ||
_description = "XLSX Report to show all the results for the survey" | ||
|
||
def _pre_generate_xlsx_report_header(self, sheet, results, cols, bold): | ||
# Hook for adding some extra headers at the beginning | ||
sheet.write(0, cols["partner_id"], _("Partner"), bold) | ||
sheet.write(0, cols["create_date"], _("Created on"), bold) | ||
|
||
def _post_generate_xlsx_report_header(self, sheet, results, cols, bold): | ||
# Hook for adding some extra headers at the end | ||
pass | ||
|
||
def _add_extra_data(self, user_input_data, user_input, cols): | ||
# Hook for adding extra data if needed | ||
for fieldname, col in cols.items(): | ||
if fieldname in user_input._fields: | ||
if not isinstance(user_input[fieldname], models.Model): | ||
user_input_data[col] = [user_input[fieldname]] | ||
elif user_input[fieldname]: | ||
user_input_data[col] = [user_input[fieldname].display_name] | ||
|
||
def generate_xlsx_report(self, workbook, data, results): | ||
n_cols = Iterator(-1) | ||
sheet = workbook.add_worksheet("Survey Results") | ||
bold = workbook.add_format({"bold": True}) | ||
no_bold = workbook.add_format({"bold": False}) | ||
cols = defaultdict(n_cols.next) | ||
data = defaultdict(lambda: defaultdict(list)) | ||
self._pre_generate_xlsx_report_header(sheet, results, cols, bold) | ||
# One column by question | ||
for question in results.question_ids: | ||
sheet.write(0, cols["question_%s" % question.id], question.title, bold) | ||
self._post_generate_xlsx_report_header(sheet, results, n_cols, bold) | ||
user_inputs = self.env["survey.user_input"].search( | ||
self._get_input_domain(results) | ||
) | ||
for user_input in user_inputs: | ||
self._add_extra_data(data[user_input.id], user_input, cols) | ||
for user_answer in user_input.user_input_line_ids: | ||
question_id = "question_%s" % user_answer.question_id.id | ||
if question_id not in cols or user_answer.skipped: | ||
# We should ignore old removed questions | ||
continue | ||
data[user_input.id][cols[question_id]].append( | ||
user_answer._get_xlsx_value() | ||
) | ||
row = 0 | ||
for answer_data in data.values(): | ||
row += 1 | ||
for col_id, answer_vals in answer_data.items(): | ||
if isinstance(answer_vals[0], datetime.datetime): | ||
date = answer_vals[0].date() | ||
answer_vals[0] = date.isoformat() | ||
result = ( | ||
answer_vals[0] if len(answer_vals) == 1 else ", ".join(answer_vals) | ||
) | ||
sheet.write( | ||
row, | ||
col_id, | ||
result, | ||
no_bold, | ||
) | ||
|
||
def _get_input_domain(self, results): | ||
return [ | ||
("survey_id", "=", results.id), | ||
("test_entry", "=", False), | ||
("state", "=", "done"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<record id="report_survey_xlsx" model="ir.actions.report"> | ||
<field name="name">XLSX Report Survey</field> | ||
<field name="model">survey.survey</field> | ||
<field name="type">ir.actions.report</field> | ||
<field name="report_type">xlsx</field> | ||
<field name="report_name">survey.xlsx</field> | ||
<field name="report_file">survey</field> | ||
<field name="attachment_use">False</field> | ||
<field name="binding_model_id" ref="survey.model_survey_survey" /> | ||
<field name="binding_type">report</field> | ||
</record> | ||
</odoo> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.