Minor adjustments after tests:

- Add Vietcombank to README.md
- Don't invert exchange rate
- Fix missing import
This commit is contained in:
Jean-Charles Drubay
2017-06-24 09:46:48 +07:00
committed by binh.lt
parent 13ffd40d2c
commit 8e54668aaa
13 changed files with 118 additions and 24 deletions

View File

@@ -37,6 +37,9 @@ The module is able to use the following sources:
7. National Bank of Romania (Banca Nationala a Romaniei)
8. Joint Stock Commercial Bank for Foreign Trade of Vietnam - Vietcombank
Configuration
=============
@@ -69,8 +72,7 @@ To fix:
Roadmap:
* Google Finance.
* Updated daily from Citibank N.A., source in EUR. Information may be delayed.
This is parsed from an HTML page, so it may be broken at anytime.
* Updated daily from Citibank N.A., source in EUR. Information may be delayed. This is parsed from an HTML page, so it may be broken at anytime.
Bug Tracker
===========

View File

@@ -106,7 +106,7 @@ class CurrencyRateUpdateService(models.Model):
# Note fileds that will be used as a logger
note = fields.Text('Update logs')
max_delta_days = fields.Integer(
string='Max delta days', default=4, required=True,
default=4, required=True,
help="If the time delta between the rate date given by the "
"webservice and the current date exceeds this value, "
"then the currency rate is not updated in Odoo.")

View File

@@ -6,3 +6,4 @@ from . import update_service_YAHOO
from . import update_service_PL_NBP
from . import update_service_MX_BdM
from . import update_service_RO_BNR
from . import update_service_VN_VCB

View File

@@ -12,7 +12,7 @@ import logging
_logger = logging.getLogger(__name__)
class CA_BOCGetter(CurrencyGetterInterface):
class CaBocGetter(CurrencyGetterInterface):
"""Implementation of Curreny_getter_factory interface
for Bank of Canada RSS service

View File

@@ -10,7 +10,7 @@ from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
_logger = logging.getLogger(__name__)
class CH_ADMINGetter(CurrencyGetterInterface):
class ChAdminGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for Admin.ch service.
"""

View File

@@ -12,7 +12,7 @@ import logging
_logger = logging.getLogger(__name__)
class ECBGetter(CurrencyGetterInterface):
class EcbGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for ECB service
"""

View File

@@ -9,7 +9,7 @@ import logging
_logger = logging.getLogger(__name__)
class MX_BdMGetter(CurrencyGetterInterface):
class MxBdmGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for Banco de México service

View File

@@ -12,7 +12,7 @@ import logging
_logger = logging.getLogger(__name__)
class PL_NBPGetter(CurrencyGetterInterface):
class PlNbpGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for PL NBP service

View File

@@ -11,7 +11,7 @@ import logging
_logger = logging.getLogger(__name__)
class RO_BNRGetter(CurrencyGetterInterface):
class RoBnrGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface for BNR service"""
code = 'RO_BNR'

View File

@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
# © 2017 Binh Lam
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import datetime
import logging
@@ -10,11 +13,10 @@ from .currency_getter_interface import CurrencyGetterInterface
_logger = logging.getLogger(__name__)
class VCBGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for VCB service
"""
code = 'VCB'
class VnVcbGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface for VCB service."""
code = 'VN_VCB'
name = 'Joint Stock Commercial Bank for Foreign ' \
'Trade of Vietnam - Vietcombank'
supported_currency_array = [
@@ -22,9 +24,7 @@ class VCBGetter(CurrencyGetterInterface):
"KWD", "MYR", "NOK", "RUB", "SAR", "SEK", "SGD", "THB", "USD", "VND"]
def rate_retrieve(self, dom, ns, curr):
"""Parse a dom node to retrieve-
currencies data
"""
"""Parse a dom node to retrieve-currencies data."""
res = {}
xpath_curr_rate = ("/ExrateList/Exrate[@CurrencyCode='%s']/@Transfer"
% curr.upper())
@@ -36,8 +36,7 @@ class VCBGetter(CurrencyGetterInterface):
def get_updated_currency(self, currency_array, main_currency,
max_delta_days):
"""implementation of abstract method of Curreny_getter_interface"""
"""Implementation of abstract method of Curreny_getter_interface."""
url = 'http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx'
# we do not want to update the main currency
if main_currency in currency_array:
@@ -72,14 +71,15 @@ class VCBGetter(CurrencyGetterInterface):
for curr in currency_array:
self.validate_cur(curr)
if curr == 'VND':
rate = 1 / main_curr_data['rate_currency']
rate = main_curr_data['rate_currency']
else:
curr_data = self.rate_retrieve(dom, vcb_ns, curr)
if main_currency == 'VND':
rate = curr_data['rate_currency']
rate = 1 / curr_data['rate_currency']
else:
rate = (curr_data['rate_currency'] /
main_curr_data['rate_currency'])
rate = (
main_curr_data['rate_currency'] /
curr_data['rate_currency'])
self.updated_currency[curr] = rate
_logger.debug(

View File

@@ -5,7 +5,7 @@
from .currency_getter_interface import CurrencyGetterInterface
class YAHOOGetter(CurrencyGetterInterface):
class YahooGetter(CurrencyGetterInterface):
"""Implementation of Currency_getter_factory interface
for Yahoo finance service
"""

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Author: Lam Thai Binh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_currency_rate_update

View File

@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# Author: Lam Thai Binh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import datetime
import logging
from odoo import fields
from odoo.tests.common import TransactionCase
class TestCurrencyRateUpdate(TransactionCase):
def setUp(self):
super(TestCurrencyRateUpdate, self).setUp()
self.env.user.company_id.auto_currency_up = True
self.env.user.company_id.currency_id = self.env.ref('base.EUR')
self.service_env = self.env['currency.rate.update.service']
self.rate_env = self.env['res.currency.rate']
def _test_cron_by_service(self, service_code, currency_xml_ids):
"""Test the ir.cron with any service for some currencies
"""
currency_ids = [
self.env.ref(currency_xml_id).id
for currency_xml_id in currency_xml_ids]
service_x = self.service_env.create({
'service': service_code,
'currency_to_update': [(6, 0, currency_ids)]
})
rate_name = \
fields.Datetime.to_string(datetime.datetime.utcnow().replace(
hour=0, minute=0, second=0, microsecond=0))
for currency_id in currency_ids:
rates = self.rate_env.search([
('currency_id', '=', currency_id),
('company_id', '=', self.env.user.company_id.id),
('name', '=', rate_name)])
rates.unlink()
self.service_env._run_currency_update()
logging.info("Service note: %s", service_x.note)
self.assertFalse('ERROR' in service_x.note)
# FIXME: except_orm(u'Error !', u'Exchange data for USD is not reported
# by Bank of Canada.')
# def test_cron_CA_BOC(self):
# """Test the ir.cron with Bank of Canada service for USD
# """
# self._test_cron_by_service('CA_BOC', ['base.USD'])
def test_cron_CH_ADMIN(self):
"""Test the ir.cron with Admin.ch service for USD
"""
self._test_cron_by_service('CH_ADMIN', ['base.USD'])
def test_cron_ECB(self):
"""Test the ir.cron with European Central Bank service for USD
"""
self._test_cron_by_service('ECB', ['base.USD'])
def test_cron_MX_BdM(self):
"""Test the ir.cron with Bank of Mexico service for USD
"""
self._test_cron_by_service('MX_BdM', ['base.USD'])
def test_cron_PL_NBP(self):
"""Test the ir.cron with National Bank of Poland service for USD
"""
self._test_cron_by_service('PL_NBP', ['base.USD'])
def test_cron_RO_BNR(self):
"""Test the ir.cron with National Bank of Romania service for USD
"""
self._test_cron_by_service('RO_BNR', ['base.USD'])
def test_cron_VN_VCB(self):
"""Test the ir.cron with Vietcombank service for USD
"""
self._test_cron_by_service('VN_VCB', ['base.USD'])
def test_cron_YAHOO(self):
"""Test the ir.cron with Yahoo service for USD
"""
self._test_cron_by_service('YAHOO', ['base.USD'])