mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Added option to use Banxico for update USD - MXN exchange rates
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
# Copyright (c) 2008 Camtocamp SA
|
||||
# @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
|
||||
# European Central Bank and Polish National Bank invented by Grzegorz Grzelak
|
||||
# Banxico implemented by Agustin Cruz openpyme.mx
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# @author JB Aubort, Nicolas Bessi, Joel Grand-Guillaume
|
||||
# European Central Bank and Polish National Bank invented by Grzegorz Grzelak
|
||||
# Ported to OpenERP 7.0 by Lorenzo Battistini <lorenzo.battistini@agilebg.com>
|
||||
# Banxico implemented by Agustin Cruz openpyme.mx
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -47,6 +48,9 @@ The module is able to use 4 different sources:
|
||||
You should check when rates should apply to bookkeeping. If next day you should
|
||||
change the update hour in schedule settings because in OpenERP they apply from
|
||||
date of update (date - no hours).
|
||||
|
||||
5. Banxico for USD & MXN (created by Agustín Cruz)
|
||||
Updated daily
|
||||
|
||||
In the roadmap : Google Finance.
|
||||
Updated daily from Citibank N.A., source in EUR. Information may be delayed.
|
||||
|
||||
@@ -58,6 +58,7 @@ class Currency_rate_update_service(osv.Model):
|
||||
#('Google_getter','Google Finance'),
|
||||
('Yahoo_getter','Yahoo Finance '),
|
||||
('PL_NBP_getter','Narodowy Bank Polski'), # Added for polish rates
|
||||
('Banxico_getter', 'Banco de México'), # Added for mexican rates
|
||||
],
|
||||
"Webservice to use",
|
||||
required = True
|
||||
@@ -123,7 +124,7 @@ class Currency_rate_update(osv.Model):
|
||||
}
|
||||
|
||||
LOG_NAME = 'cron-rates'
|
||||
MOD_NAME = 'c2c_currency_rate_update: '
|
||||
MOD_NAME = 'currency_rate_update: '
|
||||
def get_cron_id(self, cr, uid, context):
|
||||
"""return the updater cron's id. Create one if the cron does not exists """
|
||||
|
||||
@@ -261,6 +262,7 @@ class Currency_getter_factory():
|
||||
'NYFB_getter',
|
||||
'Google_getter',
|
||||
'Yahoo_getter',
|
||||
'Banxico_getter',
|
||||
]
|
||||
if class_name in allowed:
|
||||
class_def = eval(class_name)
|
||||
@@ -540,3 +542,56 @@ class PL_NBP_getter(Curreny_getter_interface) : # class added according to pol
|
||||
self.updated_currency[curr] = rate
|
||||
_logger.debug("Rate retrieved : 1 " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
return self.updated_currency, self.log_info
|
||||
|
||||
|
||||
##Banco de México ############################################################################
|
||||
class Banxico_getter(Curreny_getter_interface) : # class added for Mexico rates
|
||||
"""Implementation of Currency_getter_factory interface
|
||||
for Banco de México service"""
|
||||
|
||||
def rate_retrieve(self):
|
||||
""" Get currency exchange from Banxico.xml and proccess it
|
||||
TODO: Get correct data from xml instead of process string
|
||||
"""
|
||||
url = 'http://www.banxico.org.mx/rsscb/rss?BMXC_canal=pagos&BMXC_idioma=es'
|
||||
|
||||
from xml.dom.minidom import parse
|
||||
from StringIO import StringIO
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.debug("Banxico currency rate service : connecting...")
|
||||
rawfile = self.get_url(url)
|
||||
|
||||
dom = parse(StringIO(rawfile))
|
||||
logger.debug("Banxico sent a valid XML file")
|
||||
|
||||
value = dom.getElementsByTagName('cb:value')[0]
|
||||
rate = value.firstChild.nodeValue
|
||||
|
||||
return float(rate)
|
||||
|
||||
|
||||
def get_updated_currency(self, currency_array, main_currency, max_delta_days=1):
|
||||
"""implementation of abstract method of Curreny_getter_interface"""
|
||||
logger = logging.getLogger(__name__)
|
||||
# we do not want to update the main currency
|
||||
if main_currency in currency_array :
|
||||
currency_array.remove(main_currency)
|
||||
|
||||
# Suported currencies
|
||||
suported = ['MXN', 'USD']
|
||||
for curr in currency_array :
|
||||
if curr in suported:
|
||||
# Get currency data
|
||||
main_rate = self.rate_retrieve()
|
||||
if main_currency == 'MXN':
|
||||
rate = 1 / main_rate
|
||||
else:
|
||||
rate = main_rate
|
||||
else:
|
||||
""" No other currency supported
|
||||
"""
|
||||
continue
|
||||
|
||||
self.updated_currency[curr] = rate
|
||||
logger.debug("Rate retrieved : " + main_currency + ' = ' + str(rate) + ' ' + curr)
|
||||
|
||||
Reference in New Issue
Block a user