Commit 75b0991f by Javier

Actualizacion en funcion get_cdr, para obtener datos de ddi en magnus que tengan el +34

parent 00b45e98
......@@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "API",
"type": "python",
......
......@@ -295,13 +295,14 @@ def add_cdrs() -> 'list[dict]':
# Obtención de Parámetros
sip_accounts = list(get_accounts(only_postpaid=True))
last_update = get_last_updated_cdr(*[sip.callerid for sip in sip_accounts])
# Filtrar cuentas válidas (ni None ni sin callerid)
valid_accounts = [acc for acc in sip_accounts if acc and acc.callerid]
last_update = get_last_updated_cdr(*[acc.callerid for acc in valid_accounts])
cdrs = []
# Carga en Memoria de CDRs
for account in sip_accounts:
since = last_update[account.callerid] if account.callerid in last_update.keys(
) else None
for account in valid_accounts:
since = last_update.get(account.callerid) # Más seguro que usar in + []
cdrs.extend(get_cdrs(phone_number=account.callerid, since=since))
# Almacenamiento en Servidor SQL
......
......@@ -391,29 +391,29 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) -
cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr c INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ? AND starttime > ? AND starttime <= ?',
(phone_number, since, upto)
WHERE callerid LIKE ? AND starttime > ? AND starttime <= ?',
('%' + phone_number + '%', since, upto)
)
elif since:
cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix\
WHERE callerid = ? AND starttime > ?',
(phone_number, since)
WHERE callerid LIKE ? AND starttime > ?',
('%' + phone_number + '%', since)
)
elif upto:
cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ? AND starttime <= ?',
(phone_number, upto)
WHERE callerid LIKE ? AND starttime <= ?',
('%' + phone_number + '%', upto)
)
else:
cursor.execute(
'SELECT callerid, calledstation dest, destination as description, starttime date, sessiontime duration, ROUND(sessionbill,3) \
price, ROUND(buycost,3) cost FROM mbilling.pkg_cdr INNER JOIN mbilling.pkg_prefix as p ON p.id = id_prefix \
WHERE callerid = ?',
(phone_number,)
WHERE callerid LIKE ?',
('%' + phone_number + '%',)
)
data = cursor.fetchall()
......@@ -422,6 +422,13 @@ def get_cdrs(phone_number: str, since: datetime = None, upto: datetime = None) -
headers = ['callerid', 'destination', 'description',
'timestamp', 'duration', 'price', 'cost']
for line in data:
# Modificamos el callerid si empieza con '+34'
if line[0].startswith('+34'):
line = list(line) # Convertimos la tupla en lista para modificar elementos
line[0] = line[0][3:] # Quitamos el '+34' (3 caracteres)
line = tuple(line) # Volvemos a convertirlo en tupla
# Añadimos la línea al resultado final
cdr.append(dict(zip(headers, line)))
return cdr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment