Skip to content

Commit

Permalink
[FIX] Fixed pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AmmarOfficewalaSerpentCS committed Mar 22, 2024
1 parent 18724b4 commit d4a952a
Show file tree
Hide file tree
Showing 28 changed files with 915 additions and 678 deletions.
36 changes: 18 additions & 18 deletions connector_phone_cloudcti_event_manager/README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:alt: License LGPL-3

======================================
Connector Phone CloudCTI Event Manager
======================================

This module integrates odoo with Phone CloudCTI Event Manager.


Credits
=======

Contributors
------------

* Murtuza Saleh <[email protected]>
* Balaji Kannan <[email protected]>
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:alt: License LGPL-3

======================================
Connector Phone CloudCTI Event Manager
======================================

This module integrates odoo with Phone CloudCTI Event Manager.


Credits
=======

Contributors
------------

* Murtuza Saleh <[email protected]>
* Balaji Kannan <[email protected]>
4 changes: 2 additions & 2 deletions connector_phone_cloudcti_event_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import models
from . import controllers
from . import models
from . import controllers
16 changes: 11 additions & 5 deletions connector_phone_cloudcti_event_manager/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"summary": "This module integrates odoo with Phone Connector CloudCTI.",
"version": "17.0.1.0.0",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/field-service",
"depends": ["base_phone_cdr", "inputmask_widget", "sale", "stock","crm", 'sale_crm'],
"website": "https://github.com/OCA/connector-telephony",
"depends": [
"base_phone_cdr",
"inputmask_widget",
"sale",
"stock",
"crm",
"sale_crm",
],
"data": [
"views/res_company.xml",
"views/res_users_view.xml",
Expand All @@ -15,9 +22,8 @@
"views/stock_picking_views.xml",
"views/crm_views.xml",
],
'assets': {
'web.assets_backend': [

"assets": {
"web.assets_backend": [
"connector_phone_cloudcti_event_manager/static/src/services/*.js",
# 'connector_phone_cloudcti_event_manager/static/src/core/**/*'
# 'connector_phone_cloudcti_event_manager/static/src/js/widget.js',
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import main
from . import main
76 changes: 36 additions & 40 deletions connector_phone_cloudcti_event_manager/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import logging
import json
import logging
import re
from datetime import datetime

from odoo import http
from odoo.http import request, Response
import pytz
import phonenumbers
import pytz

from odoo import http
from odoo.http import Response, request

from datetime import datetime
_logger = logging.getLogger(__name__)

class CloudCTIVOIP(http.Controller):

class CloudCTIVOIP(http.Controller):
def map_state(self, instate, currentstate=False):
outstate = 'on_hold'
if instate == 'ringing':
outstate = 'offering'
elif instate == 'answered':
outstate = 'connected'
elif instate == 'ended':
if currentstate == 'offering':
outstate = 'missed'
elif currentstate == 'connected':
outstate = 'completed'
outstate = "on_hold"
if instate == "ringing":
outstate = "offering"
elif instate == "answered":
outstate = "connected"
elif instate == "ended":
if currentstate == "offering":
outstate = "missed"
elif currentstate == "connected":
outstate = "completed"
else:
outstate = 'on_hold'
outstate = "on_hold"
return outstate

def create_cdr_record(self, user, payload):
startdate = False
if payload.get('starttime'):
if payload.get("starttime"):
startdate = self.convert_into_correct_timezone(
payload.get("starttime"),
user
payload.get("starttime"), user
)
vals = {
"guid": payload.get("callid"),
Expand All @@ -43,15 +43,15 @@ def create_cdr_record(self, user, payload):
"call_start_time": startdate,
"state": self.map_state(payload.get("state")),
"user_id": user.id,
"partner_ids": payload.get("partner_ids")
"partner_ids": payload.get("partner_ids"),
}
return request.env["phone.cdr"].sudo().create(vals)

def convert_into_correct_timezone(self, record_date, user):
#CloudCTI provides date in UTC, so no conversion needed.
return re.sub(r"[TtzZ]"," ", record_date)
record_date = datetime.strptime(record_date, '%Y-%m-%d %H:%M:%S')
timezone = request.env.context.get('tz', False) or user.partner_id.tz
# CloudCTI provides date in UTC, so no conversion needed.
return re.sub(r"[TtzZ]", " ", record_date)
record_date = datetime.strptime(record_date, "%Y-%m-%d %H:%M:%S")
timezone = request.env.context.get("tz", False) or user.partner_id.tz
return_date = None
if timezone:
src_tz = pytz.timezone("UTC")
Expand Down Expand Up @@ -88,33 +88,29 @@ def cloudcti_status_change(self, *args, **kw):
check = True if state == "answered" else False
update = False if state == "ringing" else True
phone = phonenumbers.format_number(
phonenumbers.parse(phone, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
phonenumbers.parse(phone, "US"), phonenumbers.PhoneNumberFormat.NATIONAL
)
other = phonenumbers.format_number(
phonenumbers.parse(other, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
phonenumbers.parse(other, "US"), phonenumbers.PhoneNumberFormat.NATIONAL
)
user = request.env["res.users"].sudo().search([("phone", "=", phone)], limit=1)
if not user:
user = request.env["res.users"].sudo().browse(1)
if not user:
return Response(json.dumps({'message': 'User Not found.', 'status': 404}))
return Response(json.dumps({"message": "User Not found.", "status": 404}))
else:
partner = (
request.env["phone.common"]
.sudo()
.get_record_from_phone_number(other)
request.env["phone.common"].sudo().get_record_from_phone_number(other)
)
if create:
payload = {
"callid": guid,
"callerid": phone if direction=="outbound" else other,
"calledid": phone if direction=="inbound" else other,
"callerid": phone if direction == "outbound" else other,
"calledid": phone if direction == "inbound" else other,
"direction": direction,
"state": state,
"starttime": starttime,
"partner_ids": [(6, 0, partner.ids)]
"partner_ids": [(6, 0, partner.ids)],
}
_logger.info("CDR Payload ---- %s", payload)
cdr = self.create_cdr_record(user, payload)
Expand All @@ -141,12 +137,12 @@ def cloudcti_status_change(self, *args, **kw):
if check and not cdr:
payload = {
"callid": guid,
"callerid": phone if direction=="outbound" else other,
"calledid": phone if direction=="inbound" else other,
"callerid": phone if direction == "outbound" else other,
"calledid": phone if direction == "inbound" else other,
"direction": direction,
"state": state,
"starttime": starttime,
"partner_ids": [(6, 0, partner.ids)]
"partner_ids": [(6, 0, partner.ids)],
}
_logger.info("CDR Payload ---- %s", payload)
cdr = self.create_cdr_record(user, payload)
Expand All @@ -157,7 +153,7 @@ def cloudcti_status_change(self, *args, **kw):
payload = {
"state": self.map_state(state, cdr.state),
"call_end_time": enddate,
"call_duration": duration
"call_duration": duration,
}
cdr.sudo().write(payload)
return Response(json.dumps({}))
16 changes: 8 additions & 8 deletions connector_phone_cloudcti_event_manager/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from . import res_users
from . import phone_common
from . import phone_cdr
from . import res_company
from . import res_partner
from . import sale_order
from . import stock_picking
from . import crm_lead
from . import res_users
from . import phone_common
from . import phone_cdr
from . import res_company
from . import res_partner
from . import sale_order
from . import stock_picking
from . import crm_lead
25 changes: 12 additions & 13 deletions connector_phone_cloudcti_event_manager/models/crm_lead.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import phonenumbers

from odoo import _, api, fields, models
from odoo import models


class CRMLead(models.Model):
_inherit = "crm.lead"

def cloudcti_open_outgoing_notification(self):
print("\n\n\n:::::::::::::::/nn/nnnself")
called_id = self._context.get('call_no')
called_id = self._context.get("call_no")
caller_id = self.env.user.phone
call_phone = self._context.get('phone_parter')
call_mobile = self._context.get('mobile_parter')
call_phone = self._context.get("phone_parter")
call_mobile = self._context.get("mobile_parter")
if caller_id and called_id and caller_id != called_id:
phone = phonenumbers.format_number(
phonenumbers.parse(caller_id, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
phonenumbers.parse(caller_id, "US"),
phonenumbers.PhoneNumberFormat.NATIONAL,
)
other = phonenumbers.format_number(
phonenumbers.parse(called_id, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
phonenumbers.parse(called_id, "US"),
phonenumbers.PhoneNumberFormat.NATIONAL,
)
partner = (
self.env["phone.common"]
.sudo()
.get_record_from_phone_number(other)
self.env["phone.common"].sudo().get_record_from_phone_number(other)
)
self.partner_id.cloudcti_outgoing_call_notification()
'''
"""
if partner:
partner[0].sudo().called_for_phone = True if call_phone else False
partner[0].sudo().called_for_mobile = True if call_mobile else False
Expand All @@ -39,4 +38,4 @@ def cloudcti_open_outgoing_notification(self):
"id": partner[0].id,
}
self.env["bus.bus"].sendone(channel, bus_message)
'''
"""
83 changes: 41 additions & 42 deletions connector_phone_cloudcti_event_manager/models/phone_cdr.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import phonenumbers

from odoo import _, api, models

class PhoneCDR(models.Model):
_inherit = "phone.cdr"

def cloudcti_open_outgoing_notification(self):
called_id = self._context.get('call_no')
caller_id = self.env.user.phone
if caller_id and called_id and caller_id != called_id:
phone = phonenumbers.format_number(
phonenumbers.parse(caller_id, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
)
other = phonenumbers.format_number(
phonenumbers.parse(called_id, 'US'),
phonenumbers.PhoneNumberFormat.NATIONAL
)
partner = (
self.env["phone.common"]
.sudo()
.get_record_from_phone_number(other)
)
# if len(self.partner_ids):
# self.partner_ids[0].cloudcti_outgoing_call_notification()
if self.partner_id:
self.partner_id.cloudcti_outgoing_call_notification()
'''
if partner:
partner[0].sudo().called_for_phone = True
partner[0].sudo().called_for_mobile = False
channel = "notify_info_%s" % self.env.user.id
bus_message = {
"message": _("Calling from : %s" % self.env.user.phone),
"title": _("Outgoing Call to %s" % called_id),
"action_link_name": "action_link_name",
"Outnotification": "OutGoingNotification",
"id": self.id,
}
self.env["bus.bus"].sendone(channel, bus_message)
'''
import phonenumbers

from odoo import models


class PhoneCDR(models.Model):
_inherit = "phone.cdr"

def cloudcti_open_outgoing_notification(self):
called_id = self._context.get("call_no")
caller_id = self.env.user.phone
if caller_id and called_id and caller_id != called_id:
phone = phonenumbers.format_number(
phonenumbers.parse(caller_id, "US"),
phonenumbers.PhoneNumberFormat.NATIONAL,
)
other = phonenumbers.format_number(
phonenumbers.parse(called_id, "US"),
phonenumbers.PhoneNumberFormat.NATIONAL,
)
partner = (
self.env["phone.common"].sudo().get_record_from_phone_number(other)
)
# if len(self.partner_ids):
# self.partner_ids[0].cloudcti_outgoing_call_notification()
if self.partner_id:
self.partner_id.cloudcti_outgoing_call_notification()
"""
if partner:
partner[0].sudo().called_for_phone = True
partner[0].sudo().called_for_mobile = False
channel = "notify_info_%s" % self.env.user.id
bus_message = {
"message": _("Calling from : %s" % self.env.user.phone),
"title": _("Outgoing Call to %s" % called_id),
"action_link_name": "action_link_name",
"Outnotification": "OutGoingNotification",
"id": self.id,
}
self.env["bus.bus"].sendone(channel, bus_message)
"""
Loading

0 comments on commit d4a952a

Please sign in to comment.