Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inz 050 #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions addons/elearnmacomod/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
'website': "http://www.example.com",
'category': 'Services',
'version': '0.0.1',
'depends': ['base', 'hr', 'website_slides'],
'data': ['security/ir.model.access.csv', 'views/views.xml', 'views/hr_employee_view.xml',
'views/survey_survey_views.xml', 'wizard/survey_ratings_wizard.xml'],
'demo': ['demo.xml'],
'depends': ['base', 'hr', 'website_slides', 'survey'],
'data': ['security/ir.model.access.csv', 'views/views.xml', 'views/hr_employee_view.xml', 'wizard/survey_ratings_wizard.xml',
'views/survey_survey_views.xml'],
'demo': [],
'installable': True,
'application': True,
'license': 'LGPL-3',
Expand Down
15 changes: 15 additions & 0 deletions addons/elearnmacomod/models/survey_ratings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


class SurveyRatings(models.Model):
Expand Down Expand Up @@ -30,3 +31,17 @@ def _compute_survey_rating_statistic(self):
print(round(self.success_rating_count/len(rating_records), 1))
return round(self.success_rating_count/len(rating_records), 1)

@api.model
def create(self, values):
survey_id = values["survey_survey_id"]
hr_id = values["reviewer_id"]

survey_finished_attempts = self.env['survey.user_input'] \
.search([('survey_id', '=', survey_id), ('state', '=', 'done')]) \
.mapped('partner_id') \
.filtered(lambda partner: partner.id == self.env["hr.employee"].browse(hr_id).user_partner_id.id)

if len(survey_finished_attempts) == 0:
raise UserError('Sorry, You cant rate this Survey! You have to finish the course first!')

return super().create(values)
65 changes: 49 additions & 16 deletions addons/elearnmacomod/tests/test_rating.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,77 @@
# coding: utf-8
import psycopg2.errors
from odoo.exceptions import UserError
from odoo.tests import common, tagged


# This test should only be executed after all modules have been installed.
@tagged('-at_install', 'post_install')
class TestSurveyModel(common.TransactionCase):
def test_calculate_rating(self):
current_survey = self.env['survey.survey'].browse(5)
current_survey = self.env['survey.survey'].browse(3)
current_survey._compute_survey_rating_statistic()
current_survey.success_rating_count
self.assertEqual(current_survey.success_rating_count, 2.3)
self.assertEqual(current_survey.success_rating_count, 0)
test_ratings = [
{
'reviewer_id': 1,
'user_rating': '1',
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
},
{
'reviewer_id': 7,
'user_rating': '2',
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
}
]
for rating in test_ratings:
self.assertTrue(self.env['survey.ratings'].create(rating))

current_survey._compute_survey_rating_statistic()
self.assertEqual(current_survey.success_rating_count, 1.5)

def test_create_survey_rating(self):
current_survey = self.env['survey.survey'].browse(5)
current_survey = self.env['survey.survey'].browse(3)
set_rating = {
'reviewer_id': 3,
'user_rating': 12,
'reviewer_id': 1,
'user_rating': '3',
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
}
survey = self.env['survey.survey'].create(set_rating)
survey = self.env['survey.ratings'].create(set_rating)
self.assertTrue(survey)

def test_rate_survey_multiple_times(self):
current_survey = self.env['survey.survey'].browse(3)
set_rating = {
'reviewer_id': 1,
'user_rating': '3',
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
}
rating_1 = self.env['survey.ratings'].create(set_rating)
self.assertTrue(rating_1)
with self.assertRaises(psycopg2.errors.UniqueViolation):
rating_2 = self.env['survey.ratings'].create(set_rating)

def test_is_user_create_survey_rating_without_complete_survey(self):
current_survey = self.env['survey.survey'].browse(5)
current_survey = self.env['survey.survey'].browse(3)
set_rating = {
'reviewer_id': 13,
'user_rating': 12,
'reviewer_id': 13514,
'user_rating': '3',
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
}
survey = self.env['survey.survey'].create(set_rating)
self.assertTrue(survey)
with self.assertRaises(UserError):
survey = self.env['survey.ratings'].create(set_rating)

def test_create_survey_rating_without_rate(self):
current_survey = self.env['survey.survey'].browse(5)
current_survey = self.env['survey.survey'].browse(3)
set_rating = {
'reviewer_id': 13,
'reviewer_id': 1,
'survey_survey_id': current_survey.id,
'opinion': "Some Example text"
}
survey = self.env['survey.survey'].create(set_rating)
self.assertTrue(survey)
with self.assertRaises(psycopg2.errors.NotNullViolation):
survey = self.env['survey.ratings'].create(set_rating)
8 changes: 1 addition & 7 deletions addons/elearnmacomod/wizard/survey_ratings_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ def _get_active_rec_id(self):
survey_ids = fields.Many2one('survey.survey', string='Survey', default=_get_active_rec_id)
opinion = fields.Char(string='Comment', required=True)
user_rating = fields.Selection(
[('1', 'Label 1'), ('2', 'Label 2'), ('3', 'Label 3'), ('4', 'Label 4'), ('5', 'Label 5')], string='Set Rating', required=True)
[('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')], string='Set Rating', required=True)

def add_survey_ratings(self):
current_survey = self.env['survey.survey'].search([('id', '=', self.survey_ids.id)])
count_review = current_survey.user_input_ids.filtered(lambda record: record.partner_id.id == self.reviewer_id.user_partner_id.id and record.state == 'done')

if len(count_review) == 0:
raise UserError('Sorry, You cant rate this Survey! You have to finish the course first!')

self.env['survey.ratings'].create({
'reviewer_id': self.reviewer_id.id,
'survey_survey_id': self.survey_ids.id,
Expand Down