From 3ddd302326d57deb08dd16c98c6f6fa82a9a3645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20FRAN=C3=87OIS?= Date: Thu, 26 Mar 2020 00:48:24 +0100 Subject: [PATCH] [ADD] survey_partner_input module --- survey_partner_input/__init__.py | 1 + survey_partner_input/__manifest__.py | 32 +++++++++++ survey_partner_input/i18n/fr.po | 55 ++++++++++++++++++ .../i18n/survey_partner_input.pot | 56 +++++++++++++++++++ survey_partner_input/models/__init__.py | 1 + survey_partner_input/models/res_partner.py | 54 ++++++++++++++++++ survey_partner_input/views/res_partner.xml | 28 ++++++++++ 7 files changed, 227 insertions(+) create mode 100644 survey_partner_input/__init__.py create mode 100644 survey_partner_input/__manifest__.py create mode 100644 survey_partner_input/i18n/fr.po create mode 100644 survey_partner_input/i18n/survey_partner_input.pot create mode 100644 survey_partner_input/models/__init__.py create mode 100644 survey_partner_input/models/res_partner.py create mode 100644 survey_partner_input/views/res_partner.xml diff --git a/survey_partner_input/__init__.py b/survey_partner_input/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/survey_partner_input/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_partner_input/__manifest__.py b/survey_partner_input/__manifest__.py new file mode 100644 index 0000000..dbb9e17 --- /dev/null +++ b/survey_partner_input/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Survey partner answers', + 'version': '1.0.0', + 'summary': """ + This module displays a counter and a percent pie on partner survey answers statistics in form stat-buttons. + """, + 'description': """ """, + 'author': 'Sudokeys', + 'website': 'http://www.sudokeys.com', + 'license': 'AGPL-3', + 'category': 'Marketing', + 'depends': [ + 'survey', + ], + 'data': [ + 'views/res_partner.xml', + ], + 'demo': [], + 'auto_install': False, + 'external_dependencies': [], + 'application': False, + 'css': [], + 'images': [], + 'js': [], + 'installable': True, + 'maintainer': 'Sudokeys', + 'pre_init_hook': '', + 'post_init_hook': '', + 'uninstall_hook': '', +} diff --git a/survey_partner_input/i18n/fr.po b/survey_partner_input/i18n/fr.po new file mode 100644 index 0000000..1e583e6 --- /dev/null +++ b/survey_partner_input/i18n/fr.po @@ -0,0 +1,55 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_partner_input +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-03-25 22:46+0000\n" +"PO-Revision-Date: 2020-03-25 22:46+0000\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_partner_input +#: model_terms:ir.ui.view,arch_db:survey_partner_input.res_partner_form +msgid "Answers" +msgstr "Réponses" + +#. module: survey_partner_input +#: model_terms:ir.ui.view,arch_db:survey_partner_input.res_partner_form +msgid "Completed" +msgstr "Répondu" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_sent_comp_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_sent_comp_survey +msgid "Completed sent survey count" +msgstr "Réponses privées terminées" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__sent_comp_ratio +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__sent_comp_ratio +msgid "Completed sent survey ratio" +msgstr "Ratio de réponses privées terminées" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_comp_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_comp_survey +msgid "Completed survey count" +msgstr "Réponses terminées" + +#. module: survey_partner_input +#: model:ir.model,name:survey_partner_input.model_res_partner +msgid "Contact" +msgstr "Contact" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_sent_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_sent_survey +msgid "Sent survey count" +msgstr "Sondages envoyés en privé" diff --git a/survey_partner_input/i18n/survey_partner_input.pot b/survey_partner_input/i18n/survey_partner_input.pot new file mode 100644 index 0000000..03c68eb --- /dev/null +++ b/survey_partner_input/i18n/survey_partner_input.pot @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_partner_input +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-03-25 22:42+0000\n" +"PO-Revision-Date: 2020-03-25 22:42+0000\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_partner_input +#: model_terms:ir.ui.view,arch_db:survey_partner_input.res_partner_form +msgid "Answers" +msgstr "" + +#. module: survey_partner_input +#: model_terms:ir.ui.view,arch_db:survey_partner_input.res_partner_form +msgid "Completed" +msgstr "" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_sent_comp_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_sent_comp_survey +msgid "Completed sent survey count" +msgstr "" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__sent_comp_ratio +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__sent_comp_ratio +msgid "Completed sent survey ratio" +msgstr "" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_comp_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_comp_survey +msgid "Completed survey count" +msgstr "" + +#. module: survey_partner_input +#: model:ir.model,name:survey_partner_input.model_res_partner +msgid "Contact" +msgstr "" + +#. module: survey_partner_input +#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_sent_survey +#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_sent_survey +msgid "Sent survey count" +msgstr "" + diff --git a/survey_partner_input/models/__init__.py b/survey_partner_input/models/__init__.py new file mode 100644 index 0000000..91fed54 --- /dev/null +++ b/survey_partner_input/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/survey_partner_input/models/res_partner.py b/survey_partner_input/models/res_partner.py new file mode 100644 index 0000000..c34c836 --- /dev/null +++ b/survey_partner_input/models/res_partner.py @@ -0,0 +1,54 @@ +from odoo import models, fields, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + tot_sent_survey = fields.Integer("Sent survey count", compute="_count_survey_input") + tot_comp_survey = fields.Integer("Completed survey count", compute="_count_survey_input") + tot_sent_comp_survey = fields.Integer("Completed sent survey count", compute="_count_survey_input") + sent_comp_ratio = fields.Integer(string="Completed sent survey ratio", compute="_get_sent_comp_ratio") + + # COMPUTES + + @api.multi + def _count_survey_input(self): + UserInput = self.env['survey.user_input'] + partners_survey = UserInput + in_onchange = self.env.in_onchange + origin = in_onchange and self._origin or False + if in_onchange: + domain = [ + ('partner_id', '=', self._origin.id), + '|', ('type', '=', 'link'), + ('state', '=', 'dones'), + ] + if self.email: + domain = ['|', ('email', '=', self.email)] + domain + partners_survey = UserInput.search(domain) + else: + partners_survey = UserInput.search([ + '|', ('partner_id', 'in', self.ids), + ('email', 'in', self.filtered('email').mapped('email')), + '|', ('type', '=', 'link'), + ('state', '=', 'done'), + ]) + for partner in self: + done = partners_survey.filtered(lambda sui: (sui.partner_id == (origin or partner) or partner.email and sui.email == partner.email) and sui.state == 'done') + link = partners_survey.filtered(lambda sui: (sui.partner_id == (origin or partner) or partner.email and sui.email == partner.email) and sui.type == 'link') + partner.tot_sent_survey = len(link) + partner.tot_comp_survey = len(done) + partner.tot_sent_comp_survey = len(link & done) + + @api.depends('tot_sent_comp_survey', 'tot_sent_survey') + def _get_sent_comp_ratio(self): + for survey in self: + if survey.tot_sent_survey == 0: + survey.sent_comp_ratio = 0 + else: + survey.sent_comp_ratio = int(round(100 * survey.tot_sent_comp_survey / survey.tot_sent_survey, 0)) + + @api.onchange('email') + def onchange_email(self): + if isinstance(self._origin.id, int): + self._count_survey_input() diff --git a/survey_partner_input/views/res_partner.xml b/survey_partner_input/views/res_partner.xml new file mode 100644 index 0000000..57a1ef6 --- /dev/null +++ b/survey_partner_input/views/res_partner.xml @@ -0,0 +1,28 @@ + + + + + survey_partner_input res.partner form + res.partner + + 24 + + + + + + + + + + + + +