Rémi FRANÇOIS
5 years ago
7 changed files with 227 additions and 0 deletions
-
1survey_partner_input/__init__.py
-
32survey_partner_input/__manifest__.py
-
55survey_partner_input/i18n/fr.po
-
56survey_partner_input/i18n/survey_partner_input.pot
-
1survey_partner_input/models/__init__.py
-
54survey_partner_input/models/res_partner.py
-
28survey_partner_input/views/res_partner.xml
@ -0,0 +1 @@ |
|||
from . import models |
@ -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': '', |
|||
} |
@ -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é" |
@ -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 "" |
|||
|
@ -0,0 +1 @@ |
|||
from . import res_partner |
@ -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() |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="res_partner_form" model="ir.ui.view"> |
|||
<field name="name">survey_partner_input res.partner form</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="base.view_partner_form"/> |
|||
<field name="priority">24</field> |
|||
<field name="arch" type="xml"> |
|||
<xpath expr="//div[@name='button_box']/button[1]" position="before"> |
|||
<button type="object" name="action_survey_user_input" |
|||
context="{'search_default_completed':1, 'link_only':1, 'search_default_partner_id': id}" |
|||
attrs="{'invisible':[('tot_sent_survey','=',0)]}" class="oe_stat_button"> |
|||
<field string="Completed" name="sent_comp_ratio" widget="percentpie"/> |
|||
</button> |
|||
<button type="object" name="action_survey_user_input" class="oe_stat_button" icon="fa-pencil-square-o" |
|||
context="{'search_default_completed':1, 'link_only':1, 'search_default_partner_id': id}"> |
|||
<field string="Answers" name="tot_comp_survey" widget="statinfo"/> |
|||
</button> |
|||
</xpath> |
|||
<xpath expr="//div[hasclass('oe_title')]" position="after"> |
|||
<field name="tot_sent_survey" invisible="1"/> |
|||
<field name="tot_sent_comp_survey" invisible="1"/> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue