Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] l10n_uy_currency_update: Contemplamos los cotizaciones de los días viernes. #226

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions l10n_uy_currency_update/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo.addons.l10n_uy_edi.models.res_company import UYTransport

from dateutil.relativedelta import relativedelta
from datetime import datetime
import logging

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -73,26 +74,25 @@ def _parse_bcu_data(self, available_currencies):
# code_currencies = [0] # Todas las monedas
# code_currencies = {'item': [2224, 500, 501]} # Argentino, y Argentino Billete

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))

#Siempre tomamos el today por el freeze que tenemos en res_currency
today = fields.Date.today(self)
#Cambiamos el formato para que nos acepte el factory.wsbcucotizacionesin
today = today.strftime('%Y-%m-%d')
today = datetime.strptime(today, '%Y-%m-%d').date()

# 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