portal.py 4.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# -*- coding: utf-8 -*-

from odoo import fields, http, _
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager
from odoo.tools import date_utils, groupby as groupbyelem
from odoo.osv.expression import AND
from dateutil.relativedelta import relativedelta
from operator import itemgetter
from collections import OrderedDict
from odoo.exceptions import AccessError, MissingError, UserError
from odoo.addons.portal.controllers.mail import _message_post_helper
from datetime import datetime, timedelta
import json
import base64
import werkzeug
import logging
_logger = logging.getLogger(__name__)
from odoo.addons.sh_all_in_one_helpdesk.controllers.portal import PortalHelpdesk


class PortalHelpdeskMorsa(PortalHelpdesk):

24
    def _prepare_home_portal_values(self):
25
        
26
        return {}
27

28 29 30 31
    @http.route('/my/ti',type='http',auth="user",website=True)
    def prepare_portal_ti(self,**kw):
        values = self._prepare_home_portal_values()
        return request.render("helpdesk_morsa.portal_my_ti",values)
32 33 34 35 36 37 38 39 40


    @http.route('/selected-partner-data',type="http",auth="public",csrf=False)
    def selected_partner_data(self, **kw):
        dic = {}
        if kw.get('partner_id') and kw.get('partner_id') != '':
            partner = request.env['res.partner'].sudo().search(
                [('id', '=', int(kw.get('partner_id')))], limit=1)
            if partner:
41
                email = partner.email if partner.email else partner.user_ids[0].login
42 43
                dic.update({
                    'name': partner.name,
44
                    'email': email,
45 46 47 48 49 50 51
                    'phone': partner.phone,
                })
            
        return json.dumps(dic)

    @http.route(['/unvaluated/tickets'],type='http',auth="none",website=True,csrf=False)
    def verify_unvaluated_tikets(self,**kw):
52 53 54 55 56 57
        try:
            partner_id = False
            if kw.get('partner_id') and kw.get('partner_id') != '':
                partner_id = request.env['res.partner'].sudo().search([('id','=',int(kw.get('partner_id')))],limit=1)
            elif kw.get('portal_email') and kw.get('portal_email') != '':
                partner_id = request.env['res.partner'].sudo().search([('email','=',kw.get('portal_email'))],limit=1)
58
            
59
            if partner_id:
60
                
61 62 63 64 65 66 67
                unvalued_tickets = request.env['helpdesk.ticket'].sudo().search([
                        ('partner_id','=',partner_id.id),
                        ('team_id','=',request.env.ref('helpdesk_morsa.techinnical_support').id),
                        ('stage_id','=',request.env.ref('sh_all_in_one_helpdesk.close_stage').id),
                        ('priority_new','=',False)])
                    

68
                if len(unvalued_tickets) >= 10:
69 70 71 72 73 74 75 76 77 78 79
                    unvalued = []
                    for t in unvalued_tickets:
                        unvalued.append({'t_id': t.id, 't_name' : t.name})

                    return json.dumps({
                        "resp":"Error",
                        "message":"Tienes demasiados tickets sin evaluar, favor de evaluarlos",
                        "unvalued":unvalued
                    })
                else:
                    return json.dumps({"resp":"Success","message":"","unvalued":[]})
80
            else:
81 82 83
                return json.dumps({"resp":"Error","message":"Favor de agregar un contacto valido"})
        except Exception as e:
            return json.dumps({"resp":"Error","message":str(e),"unvalued":[]})
84 85 86 87 88 89 90 91 92

    @http.route(['/cerrar-ticket'], type='http',auth="user",website=True)
    def portal_ticket_closed(self,**kw):
        url = "/my"
        if kw.get('option'):
            url = "/my/"+kw.get('option')+"?ctr=False"
        try:
            ticket = request.env['helpdesk.ticket'].sudo().browse(int(kw.get('ticket_id')))
            if ticket:
93 94
                if not ticket.descripcion_solution:
                    ticket.sudo().update({'descripcion_solution':"Cerrado por el usuario"})
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
                ticket.sudo().done_and_close()
                
        except Exception as e:
            _logger.exception('Something went wrong %s',str(e))
        finally:
            return request.redirect(url)
        
    @http.route(['/cancel-ticket'], type='http',auth="user",website=True)
    def portal_ticket_cancel(self,**kw):

        url = "/my"
        if kw.get('option'):
            url = "/my/"+kw.get('option')+"?ctr=False"
        try:
            ticket = request.env['helpdesk.ticket'].sudo().browse(int(kw.get('ticket_id')))
            if ticket:     
                ticket.sudo().action_cancel()      
        except Exception as e:
            _logger.exception('Something went wrong %s',str(e))
        finally:
            return request.redirect(url)