Skip to content

Commit

Permalink
Merge PR #116 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Apr 3, 2024
2 parents 21bd6ae + 0e93435 commit 742ad7a
Show file tree
Hide file tree
Showing 18 changed files with 848 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup/survey_xlsx/odoo/addons/survey_xlsx
6 changes: 6 additions & 0 deletions setup/survey_xlsx/setup.py
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,
)
76 changes: 76 additions & 0 deletions survey_xlsx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
===========
Survey XLSX
===========

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0647ba4a4a0c3a3dc8f4e7b281d9bc6482d39efc59b2da832241080c29d611ad
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/16.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-16-0/survey-16-0-survey_xlsx
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/survey&target_branch=16.0
:alt: Try me on Runboat

|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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_xlsx%0Aversion:%2016.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/16.0/survey_xlsx>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions survey_xlsx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import report
from . import models
16 changes: 16 additions & 0 deletions survey_xlsx/__manifest__.py
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": "16.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"],
}
62 changes: 62 additions & 0 deletions survey_xlsx/i18n/it.po
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: 2023-10-29 06:42+0000\n"
"Last-Translator: mymage <[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.17\n"

#. module: survey_xlsx
#: code:addons/survey_xlsx/report/report_survey_xlsx.py:0
#, python-format
msgid "Created on"
msgstr "Creato il"

#. 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 risposta utente al sondaggio"

#. module: survey_xlsx
#: model:ir.actions.report,name:survey_xlsx.report_survey_xlsx
msgid "XLSX Report Survey"
msgstr "Resoconto sondaggio XLSX"

#. 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 "Resoconto XLSX per visualizzare tutti i risultati del sondaggio"
59 changes: 59 additions & 0 deletions survey_xlsx/i18n/survey_xlsx.pot
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 ""
1 change: 1 addition & 0 deletions survey_xlsx/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import survey_user_input_line
14 changes: 14 additions & 0 deletions survey_xlsx/models/survey_user_input_line.py
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]
1 change: 1 addition & 0 deletions survey_xlsx/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Olga Marco <[email protected]>
1 change: 1 addition & 0 deletions survey_xlsx/readme/DESCRIPTION.rst
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.
1 change: 1 addition & 0 deletions survey_xlsx/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report_survey_xlsx
88 changes: 88 additions & 0 deletions survey_xlsx/report/report_survey_xlsx.py
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"),
]
14 changes: 14 additions & 0 deletions survey_xlsx/report/report_survey_xlsx.xml
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>
Binary file added survey_xlsx/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 742ad7a

Please sign in to comment.