You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
from odoo import models, fields, api, _
|
|
|
|
|
|
class SurveySurvey(models.Model):
|
|
_inherit = "survey.survey"
|
|
|
|
answer_selection = fields.Boolean(
|
|
string="Manual selection",
|
|
help="Checking this box allows you to select completed real answers (regardless of the scoring success, if enable).",
|
|
)
|
|
answer_selected_count = fields.Integer(
|
|
"Number of selected answers", compute="_compute_selected_answer"
|
|
)
|
|
answer_selected_ratio = fields.Integer(
|
|
"Ratio of selected anwers", compute="_compute_selected_answer"
|
|
)
|
|
|
|
@api.depends("user_input_ids", "user_input_ids.select")
|
|
def _compute_selected_answer(self):
|
|
default_vals = {
|
|
"answer_count": 0,
|
|
"answer_selected_count": 0,
|
|
}
|
|
stats = dict((sid, default_vals) for sid in self.ids)
|
|
UserInput = self.env["survey.user_input"]
|
|
base_domain = [
|
|
("survey_id", "in", self.ids),
|
|
("state", "=", "done"),
|
|
("test_entry", "=", False),
|
|
]
|
|
read_group_res = UserInput._read_group(
|
|
base_domain,
|
|
["survey_id", "select"],
|
|
["survey_id", "select"],
|
|
lazy=False,
|
|
)
|
|
|
|
for item in read_group_res:
|
|
stats[item["survey_id"][0]]["answer_count"] += item["__count"]
|
|
if item["select"] == "done":
|
|
stats[item["survey_id"][0]]["answer_selected_count"] += item["__count"]
|
|
|
|
for survey_stats in stats.values():
|
|
survey_stats["answer_selected_ratio"] = (
|
|
survey_stats["answer_selected_count"]
|
|
/ (survey_stats["answer_count"] or 1)
|
|
* 100
|
|
)
|
|
|
|
for survey in self:
|
|
survey.update(stats.get(survey._origin.id, default_vals))
|
|
|
|
# ACTIONS
|
|
|
|
def action_survey_user_input(self):
|
|
action = super(SurveySurvey, self).action_survey_user_input()
|
|
if self.env.context.get("search_default_selected", False):
|
|
action["display_name"] += _(" selected")
|
|
return action
|