Skip to content

Commit

Permalink
[MIG] l10n_uy_currency_update: Migration to 18.0
Browse files Browse the repository at this point in the history
closes #257

Signed-off-by: Katherine Zaoral <[email protected]>
  • Loading branch information
docker-odoo authored and mem-adhoc committed Dec 4, 2024
1 parent 75862fc commit 59a75c7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
1 change: 0 additions & 1 deletion l10n_uy_currency_update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
# directory
##############################################################################
from . import models
from . import tests
5 changes: 2 additions & 3 deletions l10n_uy_currency_update/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
##############################################################################
{
'name': 'Uruguayan Currency Rate Update',
'version': "17.0.1.2.0",
'version': "18.0.1.0.0",
'countries': ['uy'],
'category': 'Localization/Uruguay',
'sequence': 14,
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'summary': '',
'depends': [
'currency_rate_live',
'l10n_uy',
],
'data': [
'views/res_currency_views.xml',
],
'installable': False,
'installable': True,
'auto_install': True,
'application': False,
}
27 changes: 13 additions & 14 deletions l10n_uy_currency_update/models/res_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ResCurrency(models.Model):

_inherit = "res.currency"

l10n_uy_have_bcu_code = fields.Boolean(store=False,compute='_compute_l10n_uy_bcu_have_code')
l10n_uy_have_bcu_code = fields.Boolean(compute='_compute_l10n_uy_bcu_have_code')

def _compute_l10n_uy_bcu_have_code(self):
"""
Expand All @@ -21,25 +21,22 @@ def _compute_l10n_uy_bcu_have_code(self):
It does not return any value but updates the `l10n_uy_have_bcu_code` field in each record of the current model.
This will help us hide the buttons in the view of l10n_uy_currency_update/views/res_currency_views.xml
"""
available_currencies = self.env['res.currency'].search([])
rate = self.env['res.company']._parse_bcu_data(available_currencies)
for rec in self:
if rec.name in rate.keys():
rec.l10n_uy_have_bcu_code = True
continue
rec.l10n_uy_have_bcu_code = False
available_currencies = self.env['res.company']._get_bcu_currencies_mapping()
# Remove the currency from the available currencies list to hide the button in the form view.
available_currencies.pop('UYI')
self.mapped(lambda x: x.update({'l10n_uy_have_bcu_code': x.name in available_currencies}))

def action_l10n_uy_get_bcu_rate(self):
available_currencies = self.env['res.currency'].search([])
rate = self.env['res.company']._parse_bcu_data(available_currencies)
if self.name in rate:
self.ensure_one()
rate = self.env['res.company']._parse_bcu_data(self)
if rate:
raise UserError(_('Fecha Ultimo Cierre: %s\nRate: %s' % (rate[self.name][1], rate[self.name][0])))
else:
raise UserError(_('No se encontro cotizacion para esta Moneda'))

def action_get_available_currencies(self):
""" Get the currency codes available in BCU
View specification in https://cotizaciones.bcu.gub.uy/wscotizaciones/servlet/awsbcumonedas/service.asmx?WSDL """
Specification in https://cotizaciones.bcu.gub.uy/wscotizaciones/servlet/awsbcumonedas/service.asmx?WSDL """
self.ensure_one()

wsdl = "https://cotizaciones.bcu.gub.uy/wscotizaciones/servlet/awsbcumonedas/service.asmx?WSDL"
Expand All @@ -65,6 +62,8 @@ def action_get_available_currencies(self):
else:
not_configured.update({item.Codigo: item.Nombre})

message = "\n".join(["Código/ Moneda\n\n(Configuradas):"] + ["* %s - %s" % (key, value) for key, value in configured.items()])
message += "\n\n" + "\n".join(["(No configuradas)"] + ["* %s - %s" % (key, value) for key, value in not_configured.items()])
message = "\n".join(["Código/ Moneda\n\n(Configuradas):"] + \
["* %s - %s" % (key, value) for key, value in configured.items()])
message += "\n\n" + "\n".join(["(No configuradas)"] + \
["* %s - %s" % (key, value) for key, value in not_configured.items()])
raise UserError(message)
5 changes: 3 additions & 2 deletions l10n_uy_currency_update/tests/test_l10n_uy_currency_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
class TestL10nUyCurrencyUpdate(AccountTestInvoicingCommon):

@classmethod
def setUpClass(cls, chart_template_ref="uy"):
super().setUpClass(chart_template_ref=chart_template_ref)
@AccountTestInvoicingCommon.setup_chart_template('uy')
def setUpClass(cls):
super().setUpClass()
cls.UYU = cls.env.ref('base.UYU')
cls.UYI = cls.env.ref('base.UYI')
cls.ARS = cls.env.ref('base.ARS')
Expand Down

0 comments on commit 59a75c7

Please sign in to comment.