Skip to content

Commit

Permalink
[FIX] l10n_uy_currency_update: Contemplamos pluralidad de posibles re…
Browse files Browse the repository at this point in the history
…tornos del metodo _parse_bcu_data

Ticket: 79770
  • Loading branch information
mem-adhoc committed Sep 18, 2024
1 parent d87ac51 commit a4e89b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 3 additions & 7 deletions l10n_uy_currency_update/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,22 @@ def _parse_bcu_data(self, available_currencies):
# code_currencies = [0] # Todas las monedas
# code_currencies = {'item': [2224, 500, 501]} # Argentino, y Argentino Billete

#Siempre tomamos el today por el freeze que tenemos en res_currency
today = fields.Date.context_today(self.with_context(tz='America/Montevideo'))
last_date = self.env.company.get_bcu_last_date()
yesterday = (today - relativedelta(days=1))


# NOTA: Esto fue necesario agregarlo porque sino me saltaba este error al correr actualizar moneda con proveedor
# BCU: ""Su moneda principal (UYU) no es soportada por este servicio de tasas de cambio. Favor de elegir otro.""
# Si logramos un mejora manera de definir esto mejor, porque estamos creando la tasa de moneda UYU todos los
# dias con tasa 1, y no tiene sentido :(
res = {'UYU': (1.0, today)}

if last_date != yesterday:
return False

response_data = []

try:
_logger.log(25, "Connecting to BCU to update the currency rates for %s", available_currencies.mapped('name'))
client = self._get_bcu_client('awsbcucotizaciones')
factory = client.type_factory('ns0')
Entrada = factory.wsbcucotizacionesin(Moneda=code_currencies, FechaDesde=yesterday, FechaHasta=yesterday, Grupo=0)
Entrada = factory.wsbcucotizacionesin(Moneda=code_currencies, FechaDesde=today, FechaHasta=today, Grupo=0)
response = client.service.Execute(Entrada)
response_data = response.datoscotizaciones['datoscotizaciones.dato']
if response.respuestastatus.codigoerror:
Expand Down
15 changes: 13 additions & 2 deletions l10n_uy_currency_update/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from odoo import _, fields, models
from odoo.exceptions import UserError

from dateutil.relativedelta import relativedelta
from freezegun import freeze_time

class ResCurrency(models.Model):

Expand All @@ -9,9 +11,18 @@ class ResCurrency(models.Model):
l10n_uy_bcu_code = fields.Integer('Código BCU', help='Este codigo idenfica cada moneda y permite extraer el valor de la tasa del Banco Central Uruguayo')

def action_l10n_uy_get_bcu_rate(self):
rate, _date = self._l10n_uy_get_bcu_rate()

today = fields.Date.context_today(self.with_context(tz='America/Montevideo'))
last_date = self.env.company.get_bcu_last_date()
raise UserError(_('Fecha Ultimo Cierre') + ': %s' % last_date + '\n' + _('Rate:') + ' %s' % rate)
yesterday = (today - relativedelta(days=1))

with freeze_time(yesterday) as frozen:
#En caso de que el dia lunes queramos traer las cotizaciones del viernes movemos la fecha
if last_date != yesterday:
frozen.move_to(last_date)

rate, _date = self._l10n_uy_get_bcu_rate()
raise UserError(_('Fecha Ultimo Cierre') + ': %s' % last_date + '\n' + _('Rate:') + ' %s' % rate)

def _l10n_uy_get_bcu_rate(self):
""" Return the date and rate for a given currency
Expand Down

0 comments on commit a4e89b4

Please sign in to comment.