Browse Source

[MIG] survey_partner_input

16.0
RemiFr82 5 days ago
parent
commit
88bccf704a
  1. 2
      survey_partner_input/__manifest__.py
  2. 14
      survey_partner_input/i18n/fr.po
  3. 43
      survey_partner_input/models/res_partner.py
  4. 14
      survey_partner_input/views/res_partner.xml
  5. 6
      survey_partner_input/views/survey_user_input.xml

2
survey_partner_input/__manifest__.py

@ -17,7 +17,7 @@
# "price": 0,
# "currency": "EUR",
"application": False,
"installable": False,
"installable": True,
"auto_install": False,
"pre_init_hook": "",
"post_init_hook": "",

14
survey_partner_input/i18n/fr.po

@ -29,23 +29,23 @@ 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"
msgstr "Répondus"
#. 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
#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_sent_done_survey
#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_sent_done_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
#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__sent_done_ratio
#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__sent_done_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
#: model:ir.model.fields,field_description:survey_partner_input.field_res_partner__tot_done_survey
#: model:ir.model.fields,field_description:survey_partner_input.field_res_users__tot_done_survey
msgid "Completed survey count"
msgstr "Réponses terminées"

43
survey_partner_input/models/res_partner.py

@ -6,29 +6,28 @@ class ResPartner(models.Model):
_inherit = "res.partner"
tot_sent_survey = fields.Integer("Sent survey count", compute="_count_survey_input")
tot_comp_survey = fields.Integer(
tot_done_survey = fields.Integer(
"Completed survey count", compute="_count_survey_input"
)
tot_sent_comp_survey = fields.Integer(
tot_sent_done_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"
sent_done_ratio = fields.Integer(
string="Completed sent survey ratio", compute="_get_sent_done_ratio"
)
# COMPUTES
@api.multi
def _count_survey_input(self):
UserInput = self.env["survey.user_input"]
partners_survey = UserInput
in_onchange = self.env.in_onchange
in_onchange = self.env.context.get("in_onchange", False)
origin = in_onchange and self._origin or False
if in_onchange:
domain = [
("partner_id", "=", self._origin.id),
"|",
("type", "=", "link"),
("invite_token", "not in", [False, None]),
("state", "=", "dones"),
]
if self.email:
@ -41,7 +40,7 @@ class ResPartner(models.Model):
("partner_id", "in", self.ids),
("email", "in", self.filtered("email").mapped("email")),
"|",
("type", "=", "link"),
("invite_token", "not in", [False, None]),
("state", "=", "done"),
]
)
@ -60,25 +59,24 @@ class ResPartner(models.Model):
or partner.email
and sui.email == partner.email
)
and sui.type == "link"
and sui.invite_token
)
partner.tot_sent_survey = len(link)
partner.tot_comp_survey = len(done)
partner.tot_sent_comp_survey = len(link & done)
partner.tot_done_survey = len(done)
partner.tot_sent_done_survey = len(link & done)
@api.depends("tot_sent_comp_survey", "tot_sent_survey")
def _get_sent_comp_ratio(self):
@api.depends("tot_sent_done_survey", "tot_sent_survey")
def _get_sent_done_ratio(self):
for survey in self:
if survey.tot_sent_survey == 0:
survey.sent_comp_ratio = 0
survey.sent_done_ratio = 0
else:
survey.sent_comp_ratio = int(
round(100 * survey.tot_sent_comp_survey / survey.tot_sent_survey, 0)
survey.sent_done_ratio = int(
round(100 * survey.tot_sent_done_survey / survey.tot_sent_survey, 0)
)
# ACTIONS
@api.multi
def action_survey_user_input(self):
self.ensure_one()
action = self.env.ref("survey.action_survey_user_input").read()[0]
@ -102,9 +100,14 @@ class ResPartner(models.Model):
domain = ["|", ("partner_id", "=", self.id), ("email", "ilike", self.email)]
if link_only:
if len(domain) > 1:
domain = AND([[("type", "=", "link")], normalize_domain(domain)])
domain = AND(
[
[("invite_token", "not in", [False, None])],
normalize_domain(domain),
]
)
else:
domain = [("type", "=", "link")]
domain = [("invite_token", "not in", [False, None])]
action["domain"] = domain
# return updated action
return action
@ -115,4 +118,4 @@ class ResPartner(models.Model):
def onchange_email(self):
self.ensure_one()
if isinstance(self._origin.id, int):
self._count_survey_input()
self.with_context(in_onchange=True)._count_survey_input()

14
survey_partner_input/views/res_partner.xml

@ -4,7 +4,7 @@
<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="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">
@ -12,18 +12,18 @@
context="{'link_only':1, 'search_default_by_state':1}"
attrs="{'invisible':[('tot_sent_survey','=',0)]}" class="oe_stat_button"
groups="survey.group_survey_user">
<field string="Completed" name="sent_comp_ratio" widget="percentpie"/>
<field string="Completed" name="sent_done_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, 'search_default_group_by_survey':1}"
attrs="{'invisible':[('tot_sent_survey','=',0),('tot_comp_survey','=',0)]}"
context="{'search_default_doneleted':1, 'search_default_group_by_survey':1}"
attrs="{'invisible':[('tot_sent_survey','=',0),('tot_done_survey','=',0)]}"
groups="survey.group_survey_user">
<field string="Answers" name="tot_comp_survey" widget="statinfo"/>
<field string="Answers" name="tot_done_survey" widget="statinfo" />
</button>
</xpath>
<xpath expr="//div[hasclass('oe_title')]" position="after">
<field name="tot_sent_survey" invisible="1" groups="survey.group_survey_user"/>
<field name="tot_sent_comp_survey" invisible="1" groups="survey.group_survey_user"/>
<field name="tot_sent_survey" invisible="1" groups="survey.group_survey_user" />
<field name="tot_sent_done_survey" invisible="1" groups="survey.group_survey_user" />
</xpath>
</field>
</record>

6
survey_partner_input/views/survey_user_input.xml

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="survey_user_input_search" model="ir.ui.view">
<record id="survey_user_input_view_search" model="ir.ui.view">
<field name="name">survey_partner_input survey.user_input search</field>
<field name="model">survey.user_input</field>
<field name="inherit_id" ref="survey.survey_user_input_search"/>
<field name="inherit_id" ref="survey.survey_user_input_view_search" />
<field name="priority">26</field>
<field name="arch" type="xml">
<filter name="group_by_partner" position="after">
<filter name="by_state" string="State" domain="[]" context="{'group_by': 'state'}"/>
<filter name="by_state" string="State" domain="[]" context="{'group_by': 'state'}" />
</filter>
</field>
</record>

Loading…
Cancel
Save