← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~atin81/account-financial-tools/account-financial-tools-7.0 into lp:account-financial-tools

 

Agustín has proposed merging lp:~atin81/account-financial-tools/account-financial-tools-7.0 into lp:account-financial-tools.

Requested reviews:
  Account Core Editors (account-core-editors)

For more details, see:
https://code.launchpad.net/~atin81/account-financial-tools/account-financial-tools-7.0/+merge/198990

Just porting the changes done on this MP: https://code.launchpad.net/~atin81/account-financial-tools/account-financial-tools/+merge/183064 to OE 7.0
-- 
https://code.launchpad.net/~atin81/account-financial-tools/account-financial-tools-7.0/+merge/198990
Your team OpenERP Community Reviewer/Maintainer is subscribed to branch lp:account-financial-tools.
=== modified file 'currency_rate_update/__init__.py'
--- currency_rate_update/__init__.py	2013-03-19 11:01:15 +0000
+++ currency_rate_update/__init__.py	2013-12-13 19:36:49 +0000
@@ -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

=== modified file 'currency_rate_update/__openerp__.py'
--- currency_rate_update/__openerp__.py	2013-03-19 11:01:15 +0000
+++ currency_rate_update/__openerp__.py	2013-12-13 19:36:49 +0000
@@ -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@xxxxxxxxxxx>
+#    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 @@
    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.

=== modified file 'currency_rate_update/currency_rate_update.py'
--- currency_rate_update/currency_rate_update.py	2013-03-19 11:01:15 +0000
+++ currency_rate_update/currency_rate_update.py	2013-12-13 19:36:49 +0000
@@ -58,6 +58,7 @@
                                                     #('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 @@
     }
 
     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 @@
                           'NYFB_getter',
                           'Google_getter',
                           'Yahoo_getter',
+                          'Banxico_getter',
                     ]
         if class_name in allowed:
             class_def = eval(class_name)
@@ -540,3 +542,56 @@
             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)


Follow ups