Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Comunitea/CMNT_00207_2020_ASC
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusVMayor committed Jan 26, 2021
2 parents 7c8a766 + b7b4b10 commit 767478a
Show file tree
Hide file tree
Showing 22 changed files with 409 additions and 37 deletions.
2 changes: 2 additions & 0 deletions project-addons/asterisk_phonecall_info/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"base_phone",
"crm_phone",
"crm_phonecall_planner",
"partner_phonecall_schedule",
"crm_phonecall",
"asterisk_click2dial",
"base_phone_popup",
Expand All @@ -23,6 +24,7 @@
'views/assets.xml',
'wizard/phonecall_notes_wzd.xml',
'data/cdr_import_cron.xml',
'views/res_partner.xml',
],
'qweb': ['static/src/xml/note.xml'],
}
97 changes: 81 additions & 16 deletions project-addons/asterisk_phonecall_info/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-06 13:54+0000\n"
"PO-Revision-Date: 2020-08-06 13:54+0000\n"
"POT-Creation-Date: 2020-12-17 10:36+0000\n"
"PO-Revision-Date: 2020-12-17 10:36+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -17,7 +17,7 @@ msgstr ""

#. module: asterisk_phonecall_info
#. openerp-web
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:84
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:85
#, python-format
msgid "Add Notes to Phonecall"
msgstr "Añadir notas a la llamada"
Expand All @@ -28,13 +28,13 @@ msgid "Asterisk"
msgstr ""

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:53
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:55
#, python-format
msgid "Asterisk Imported Incoming Call"
msgstr "Llamada entrante importada"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:57
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:60
#, python-format
msgid "Asterisk Imported Outgoing Call"
msgstr "Llamada saliente importada"
Expand All @@ -44,6 +44,11 @@ msgstr "Llamada saliente importada"
msgid "Asterisk Servers"
msgstr "Servidores Asterisk"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__asterisk_notify
msgid "Asterisk notify"
msgstr "Notificaciones Asterisk"

#. module: asterisk_phonecall_info
#: model_terms:ir.ui.view,arch_db:asterisk_phonecall_info.asterisk_phonecall_info_asterisk_server_form
msgid "CDR LOG"
Expand All @@ -57,11 +62,16 @@ msgstr "Llamada desde la centralita"

#. module: asterisk_phonecall_info
#. openerp-web
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:61
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:62
#, python-format
msgid "Calling party number not retreived from IPBX or IPBX unreachable by Odoo"
msgstr "Número no recibido desde IPBX o IPBX inaccesible desde Odoo"

#. module: asterisk_phonecall_info
#: model_terms:ir.ui.view,arch_db:asterisk_phonecall_info.asterisk_phonecall_info_view_partner_form
msgid "Calls Summary"
msgstr "Resumen de llamadas"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_crm_phonecall__campaign_id
msgid "Campaing"
Expand Down Expand Up @@ -100,6 +110,17 @@ msgstr "CDR Password"
msgid "Cdr User"
msgstr "Usuario CDR"

#. module: asterisk_phonecall_info
#: selection:res.users,asterisk_user_type:0
msgid "Commercial"
msgstr "Comercial"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_partner__commercial_minutes_cur_month
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__commercial_minutes_cur_month
msgid "Commercial minutes this month"
msgstr "Min. comerciales este mes"

#. module: asterisk_phonecall_info
#: model:ir.model,name:asterisk_phonecall_info.model_phone_common
msgid "Common methods for phone features"
Expand All @@ -111,7 +132,12 @@ msgid "Confirm"
msgstr "Confirmar"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:148
#: model:ir.model,name:asterisk_phonecall_info.model_res_partner
msgid "Contact"
msgstr "Contacto"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:160
#, python-format
msgid "Could not create row vals for row: {}."
msgstr "No se han podido generar valores para la fila: {}."
Expand Down Expand Up @@ -161,7 +187,7 @@ msgstr ""

#. module: asterisk_phonecall_info
#. openerp-web
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:60
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:61
#, python-format
msgid "IPBX error"
msgstr ""
Expand All @@ -174,16 +200,16 @@ msgid "Import cdr logs from Asterisk"
msgstr "Importar logs CDR de Asterisk"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/phone_common.py:37
#: code:addons/asterisk_phonecall_info/models/phone_common.py:47
#, python-format
msgid "Incoming call"
msgstr "Llamada entrante"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/phone_common.py:35
#: code:addons/asterisk_phonecall_info/models/phone_common.py:45
#, python-format
msgid "Incoming call from {} ({})"
msgstr "Llamada entrante de {} ({})"
msgid "Incoming call from {} ({}) <br/> {}"
msgstr "Llamada entrante de {} ({}) <br/> {}"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_phonecall_notes_wizard____last_update
Expand Down Expand Up @@ -219,7 +245,7 @@ msgid "New Note"
msgstr "Nueva Nota"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:75
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:78
#, python-format
msgid "Not partner_id or opportunity_id for record number {}"
msgstr "No existe cliente u oportunidad para el número {}"
Expand All @@ -233,13 +259,13 @@ msgstr "Notas"

#. module: asterisk_phonecall_info
#. openerp-web
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:72
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:73
#, python-format
msgid "Number Not Found"
msgstr "Número no encontrado"

#. module: asterisk_phonecall_info
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:61
#: code:addons/asterisk_phonecall_info/models/crm_phonecall.py:64
#, python-format
msgid "Record number {} not recognized"
msgstr "Número {} no reconocible"
Expand All @@ -254,9 +280,20 @@ msgstr "Fuente"
msgid "Tags"
msgstr "Etiquetas"

#. module: asterisk_phonecall_info
#: selection:res.users,asterisk_user_type:0
msgid "Technical"
msgstr "Técnico"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_partner__technical_minutes_cur_month
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__technical_minutes_cur_month
msgid "Technical minutes this month"
msgstr "Min. técnicos este mes"

#. module: asterisk_phonecall_info
#. openerp-web
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:67
#: code:addons/asterisk_phonecall_info/static/src/js/note.js:68
#, python-format
msgid "The calling number is not a phone number!"
msgstr "El número no es número de teléfono."
Expand All @@ -271,6 +308,34 @@ msgstr "Éste es el método de entrega, por ejemplo, envío postal, Email, o el
msgid "This is the link source, e.g. Search Engine, another domain,or name of email list"
msgstr "Ésta es la fuente del link, por ejemplo, buscador, otro dominio, o nombre de lista de email"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_partner__commercial_minutes
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__commercial_minutes
msgid "Total commercial minutes"
msgstr "Total minutos comerciales"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_partner__technical_minutes
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__technical_minutes
msgid "Total technical minutes"
msgstr "Total minutos técnicos"

#. module: asterisk_phonecall_info
#: selection:res.users,asterisk_user_type:0
msgid "Undefined"
msgstr "Sin seleccionar"

#. module: asterisk_phonecall_info
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_crm_phonecall__asterisk_user_type
#: model:ir.model.fields,field_description:asterisk_phonecall_info.field_res_users__asterisk_user_type
msgid "User type"
msgstr "Tipo de usuario"

#. module: asterisk_phonecall_info
#: model:ir.model,name:asterisk_phonecall_info.model_res_users
msgid "Users"
msgstr "Usuarios"

#. module: asterisk_phonecall_info
#: model:ir.model,name:asterisk_phonecall_info.model_crm_phonecall
msgid "crm.phonecall"
Expand Down
2 changes: 1 addition & 1 deletion project-addons/asterisk_phonecall_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# © 2020 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import crm_phonecall, phone_common, asterisk_server
from . import crm_phonecall, phone_common, asterisk_server, res_users, res_partner
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ def _get_calling_agi_uniqueid_from_channel(self, chan, user):
very old or very new versions of Asterisk'''
sip_account = user.asterisk_chan_type + '/' + user.resource
internal_number = user.internal_number
internal_number_no_outlet_suffix = internal_number.replace("-outlet", "")

_logger.info("_get_calling_agi_uniqueid_from_channel: internal_number_no_outlet_suffix {}".format(internal_number_no_outlet_suffix))
_logger.info("_get_calling_agi_uniqueid_from_channel: SIP ACC {}, INTERNAL NUMBER: {}, CHAN: {}".format(sip_account, internal_number, chan))
# 4 = Ring
# 6 = Up
if (
chan.get('ChannelState') in ('4', '6') and (
chan.get('ConnectedLineNum') == internal_number or
chan.get('EffectiveConnectedLineNum') == internal_number or
chan.get('ConnectedLineNum') in (internal_number, internal_number_no_outlet_suffix) or
chan.get('EffectiveConnectedLineNum') in (internal_number, internal_number_no_outlet_suffix) or
sip_account in chan.get('BridgedChannel', ''))):
_logger.debug(
"Found a matching Event with ID = %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CrmPhonecall(models.Model):
help="This is the delivery method, e.g. Postcard, Email, or Banner Ad",
default=lambda self: self.env.ref("utm.utm_medium_email", False),
)
asterisk_user_type = fields.Selection(related='user_id.asterisk_user_type')

def _parse_row_vals(self, row):

Expand Down
54 changes: 49 additions & 5 deletions project-addons/asterisk_phonecall_info/models/phone_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,67 @@ class PhoneCommon(models.AbstractModel):
def incall_notify_by_login(self, number, login_list):
assert isinstance(login_list, list), "login_list must be a list"
res = self.get_record_from_phone_number(number)
users = self.env["res.users"].search([("login", "in", login_list)])
users = self.env["res.users"].search([("login", "in", login_list), ('asterisk_notify', '=', True)])
logger.info(
"Notify incoming call from number %s to user IDs %s" % (number, users.ids)
)
action = self._prepare_incall_pop_action(res, number)
action = clean_action(action)
partner_id = self.env["phone.common"].get_record_from_phone_number(number)
if partner_id and partner_id[2]:
partner_name = partner_id[2]
partner_notes = False
commercial_partner_notes = False
technical_partner_notes = False
partner_commercial_phonecall_ids = False
partner_technical_phonecall_ids = False
if res and res[2]:
partner_name = res[2]
if res[1] and res[0] == 'res.partner':
partner_commercial_phonecall_ids = self.env["crm.phonecall"].search([
('partner_id', 'child_of', res[1]),
('notes', '!=', False),
('asterisk_user_type', '=', 'commercial')
], order="id desc", limit=5)

partner_technical_phonecall_ids = self.env["crm.phonecall"].search([
('partner_id', 'child_of', res[1]),
('notes', '!=', False),
('asterisk_user_type', '=', 'technical')
], order="id desc", limit=5)
elif res[1] and res[0] == 'crm.lead':
partner_commercial_phonecall_ids = self.env["crm.phonecall"].search([
('opportunity_id', '=', res[1]),
('notes', '!=', False),
('asterisk_user_type', '=', 'commercial')
], order="id desc", limit=5)

partner_technical_phonecall_ids = self.env["crm.phonecall"].search([
('opportunity_id', '=', res[1]),
('notes', '!=', False),
('asterisk_user_type', '=', 'technical')
], order="id desc", limit=5)


if partner_commercial_phonecall_ids:
commercial_partner_notes = ''
for phonecall in partner_commercial_phonecall_ids:
commercial_partner_notes += '{}: {} <br/>'.format(phonecall.date, phonecall.notes)

if partner_technical_phonecall_ids:
technical_partner_notes = ''
for phonecall in partner_commercial_phonecall_ids:
technical_partner_notes += '{}: {} <br/>'.format(phonecall.date, phonecall.notes)
else:
partner_name = "Unknown"
if action:
for user in users:
partner_notes = ''
channel = "notify_info_%s" % user.id
if user.asterisk_user_type == 'commercial':
partner_notes = commercial_partner_notes
elif user.asterisk_user_type == 'technical':
partner_notes = technical_partner_notes
bus_message = {
"message": _(
"Incoming call from {} ({})".format(partner_name, number)
"Incoming call from {} ({}) <br/> {}".format(partner_name, number, partner_notes if partner_notes else '')
),
"title": _("Incoming call"),
"action": action,
Expand Down
37 changes: 37 additions & 0 deletions project-addons/asterisk_phonecall_info/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# © 2020 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class ResPartner(models.Model):
_inherit = "res.partner"

commercial_minutes = fields.Float(string="Total commercial minutes", compute="_compute_phonecall_minutes")
technical_minutes = fields.Float(string="Total technical minutes", compute="_compute_phonecall_minutes")
commercial_minutes_cur_month = fields.Float(string="Commercial minutes this month", compute="_compute_phonecall_minutes")
technical_minutes_cur_month = fields.Float(string="Technical minutes this month", compute="_compute_phonecall_minutes")

@api.multi
def _compute_phonecall_minutes(self):
for partner in self:
cur_month = date.today().strftime('%B').lower()
cur_year = date.today().year
cur_date = "{} {}".format(cur_month, cur_year)

commercial_calls = self.env['crm.phonecall'].read_group([
('partner_id', '=', partner.id),
('asterisk_user_type', '=', 'commercial')
], fields=['length', 'date'], groupby=['date'])

partner.commercial_minutes = sum(call['length'] for call in commercial_calls)/60
partner.commercial_minutes_cur_month = sum(call['length'] for call in commercial_calls if call['date'] == cur_date)/60

technical_calls = self.env['crm.phonecall'].read_group([
('partner_id', '=', partner.id),
('asterisk_user_type', '=', 'technical')
], fields=['length', 'date'], groupby=['date'])

partner.technical_minutes = sum(call['length'] for call in technical_calls)/60
partner.technical_minutes_cur_month = sum(call['length'] for call in technical_calls if call['date'] == cur_date)/60
22 changes: 22 additions & 0 deletions project-addons/asterisk_phonecall_info/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# © 2020 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models, _, fields
import logging
from odoo.exceptions import UserError

logger = logging.getLogger(__name__)


class ResUsers(models.Model):
_inherit = "res.users"

asterisk_notify = fields.Boolean(string='Asterisk notify', default=True)
asterisk_user_type = fields.Selection(
[('commercial', 'Commercial'),
('technical', 'Technical'),
('undefined', 'Undefined')],
string='User type',
required=True,
default='undefined',
)
Loading

0 comments on commit 767478a

Please sign in to comment.