diff --git a/currency_rate_update/README.rst b/currency_rate_update/README.rst index 02354a574..c8130cad5 100644 --- a/currency_rate_update/README.rst +++ b/currency_rate_update/README.rst @@ -31,6 +31,7 @@ The module is able to use the following sources: Updated daily 6. Bank of Canada + (WARNING: Currently not working) 7. National Bank of Romania (Banca Nationala a Romaniei) @@ -63,6 +64,9 @@ currency found in database. Know issues / Roadmap ===================== +To fix: +* Bank of Canada + Roadmap: * Google Finance. * Updated daily from Citibank N.A., source in EUR. Information may be delayed. @@ -74,8 +78,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback -`here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback. Credits @@ -84,14 +87,27 @@ Credits Contributors ------------ +* Nicolas Bessi +* Jean-Baptiste Aubort * Joël Grand-Guillaume -* JB Aubort * Grzegorz Grzelak (ECB, NBP) -* Alexis de Lattre +* Vincent Renaville +* Yannick Vaucher +* Guewen Baconnier * Lorenzo Battistini (Port to V7) * Agustin Cruz (BdM) -* Dorin Hongu (BNR) +* Jacque-Etienne Baudoux +* Juan Jose Scarafia +* Mathieu Benoi * Fekete Mihai (Port to V8) +* Dorin Hongu (BNR) +* Paul McDermott +* Alexis de Lattre +* Miku Laitinen +* Assem Bayahi +* Daniel Dico (BOC) +* Dmytro Katyukha + Maintainer ---------- diff --git a/currency_rate_update/__init__.py b/currency_rate_update/__init__.py index 75d7d0aa3..d99ae047e 100644 --- a/currency_rate_update/__init__.py +++ b/currency_rate_update/__init__.py @@ -1,22 +1,2 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - from . import model +from .services.currency_getter_interface import CurrencyGetterInterface diff --git a/currency_rate_update/__openerp__.py b/currency_rate_update/__openerp__.py index b72ba737b..b59d44c5f 100644 --- a/currency_rate_update/__openerp__.py +++ b/currency_rate_update/__openerp__.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2008-2016 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Currency Rate Update", - "version": "8.0.0.7.0", + "version": "9.0.1.0.0", "author": "Camptocamp,Odoo Community Association (OCA)", "website": "http://camptocamp.com", "license": "AGPL-3", @@ -36,7 +19,7 @@ "security/rule.xml", "security/ir.model.access.csv", ], + "images": [], "demo": [], - "active": False, - 'installable': False + 'installable': True } diff --git a/currency_rate_update/model/__init__.py b/currency_rate_update/model/__init__.py index e8bdb9041..f67366f87 100644 --- a/currency_rate_update/model/__init__.py +++ b/currency_rate_update/model/__init__.py @@ -1,23 +1,2 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - from . import currency_rate_update from . import company diff --git a/currency_rate_update/model/company.py b/currency_rate_update/model/company.py index a71d27987..f88ce6514 100644 --- a/currency_rate_update/model/company.py +++ b/currency_rate_update/model/company.py @@ -1,58 +1,25 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2009-2016 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api -class res_company(models.Model): +class ResCompany(models.Model): """override company to add currency update""" - @api.multi - def _compute_multi_curr_enable(self): - "check if multi company currency is enabled" - company_currency = self.env['res.currency'].search([('company_id', - '!=', False)]) - for company in self: - company.multi_company_currency_enable = \ - 1 if company_currency else 0 - - @api.one - def button_refresh_currency(self): - """Refresh the currencies rates !!for all companies now""" - self.services_to_use.refresh_currency() - _inherit = "res.company" + @api.multi + def button_refresh_currency(self): + """Refresh the currencies rates""" + self.ensure_one() + self.services_to_use.refresh_currency() + # Activate the currency update auto_currency_up = fields.Boolean( string='Automatic Update', help="Automatic update of the currencies for this company") - # Function field that allows to know the - # multi company currency implementation - multi_company_currency_enable = fields.Boolean( - string='Multi company currency', translate=True, - compute="_compute_multi_curr_enable", - help="When this option is unchecked it will allow users " - "to set a distinct currency updates on each company." - ) # List of services to fetch rates services_to_use = fields.One2many( 'currency.rate.update.service', diff --git a/currency_rate_update/model/currency_rate_update.py b/currency_rate_update/model/currency_rate_update.py index b0e6f1a45..f565df592 100644 --- a/currency_rate_update/model/currency_rate_update.py +++ b/currency_rate_update/model/currency_rate_update.py @@ -1,23 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2009-2016 Camptocamp +# © 2010 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -27,7 +11,8 @@ from dateutil.relativedelta import relativedelta from openerp import models, fields, api, _ from openerp import exceptions -from ..services.currency_getter import Currency_getter_factory +from ..services.currency_getter_interface import CurrencyGetterType + _logger = logging.getLogger(__name__) @@ -37,103 +22,8 @@ _intervalTypes = { 'months': lambda interval: relativedelta(months=interval), } -supported_currency_array = [ - "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", - "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", - "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", - "COP", "CRC", "CUP", "CVE", "CYP", "CZK", "DJF", "DKK", "DOP", "DZD", - "EEK", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", - "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", - "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", - "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", - "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", - "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MTL", "MUR", "MVR", - "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", - "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", - "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", - "SLL", "SOS", "SPL", "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", - "TMM", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", - "USD", "UYU", "UZS", "VEB", "VEF", "VND", "VUV", "WST", "XAF", "XAG", - "XAU", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMK", - "ZWD" -] -YAHOO_supported_currency_array = [ - "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", - "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", - "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", - "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", - "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", - "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", - "IDR", "IEP", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", - "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", - "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", - "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", - "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", - "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", - "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", - "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", - "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", - "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XCP", "XDR", "XOF", - "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL"] - -RO_BNR_supported_currency_array = [ - "AED", "AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EGP", - "EUR", "GBP", "HUF", "INR", "JPY", "KRW", "MDL", "MXN", "NOK", "NZD", - "PLN", "RON", "RSD", "RUB", "SEK", "TRY", "UAH", "USD", "XAU", "XDR", - "ZAR"] - -CA_BOC_supported_currency_array = [ - "AED", "ANG", "ARS", "AUD", "BOC", "BRL", "BSD", "CHF", "CLP", "CNY", - "COP", "CZK", "DKK", "EUR", "FJD", "GBP", "GHS", "GTQ", "HKD", "HNL", - "HRK", "HUF", "IDR", "ILS", "INR", "ISK", "JMD", "JPY", "KRW", "LKR", - "MAD", "MMK", "MXN", "MYR", "NOK", "NZD", "PAB", "PEN", "PHP", "PKR", - "PLN", "RON", "RSD", "RUB", "SEK", "SGD", "THB", "TND", "TRY", "TTD", - "TWD", "USD", "VEF", "VND", "XAF", "XCD", "XPF", "ZAR"] - -CH_ADMIN_supported_currency_array = [ - "AED", "ALL", "ARS", "AUD", "AZN", "BAM", "BDT", "BGN", "BHD", "BRL", - "CAD", "CHF", "CLP", "CNY", "COP", "CRC", "CZK", "DKK", "DOP", "EGP", - "ETB", "EUR", "GBP", "GTQ", "HKD", "HNL", "HRK", "HUF", "IDR", "ILS", - "INR", "ISK", "JPY", "KES", "KHR", "KRW", "KWD", "KYD", "KZT", "LBP", - "LKR", "LTL", "LVL", "LYD", "MAD", "MUR", "MXN", "MYR", "NGN", "NOK", - "NZD", "OMR", "PAB", "PEN", "PHP", "PKR", "PLN", "QAR", "RON", "RSD", - "RUB", "SAR", "SEK", "SGD", "THB", "TND", "TRY", "TWD", "TZS", "UAH", - "USD", "UYU", "VEF", "VND", "ZAR"] - -ECB_supported_currency_array = [ - "AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EUR", "GBP", - "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "LTL", "MXN", - "MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", "SGD", "THB", - "TRY", "USD", "ZAR"] - -MX_BdM_supported_currency_array = [ - "ARS", "AUD", "BBD", "BMD", "BOB", "BRL", "BSD", "BZD", "CAD", "CHF", - "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CZK", "DKK", "DOP", "DZD", - "EGP", "ESD", "EUR", "FJD", "GBP", "GTQ", "GYD", "HKD", "HNL", "HUF", - "IDR", "ILS", "INR", "IQD", "JMD", "JPY", "KES", "KRW", "KWD", "MAD", - "MYR", "NGN", "NIC", "NOK", "NZD", "PAB", "PEN", "PHP", "PLN", "PYG", - "RON", "RUB", "SAR", "SEK", "SGD", "SVC", "THB", "TRY", "TTD", "TWD", - "UAH", "USD", "USD", "UYP", "VEF", "VND", "ZAR"] - -PL_NBP_supported_currency_array = [ - "AUD", "BGN", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", - "GBP", "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "ISK", "JPY", "KRW", - "LTL", "MXN", "MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", - "SGD", "THB", "TRY", "UAH", "USD", "XDR", "ZAR"] - -supported_currecies = { - 'YAHOO_getter': YAHOO_supported_currency_array, - 'ECB_getter': ECB_supported_currency_array, - 'RO_BNR_getter': RO_BNR_supported_currency_array, - 'CA_BOC_getter': CA_BOC_supported_currency_array, - 'CH_ADMIN_getter': CH_ADMIN_supported_currency_array, - 'MX_BdM_getter': MX_BdM_supported_currency_array, - 'PL_NBP_getter': PL_NBP_supported_currency_array, - } - - -class Currency_rate_update_service(models.Model): +class CurrencyRateUpdateService(models.Model): """Class keep services and currencies that have to be updated""" _name = "currency.rate.update.service" @@ -163,39 +53,19 @@ class Currency_rate_update_service(models.Model): currency_list = '' if self.service: currencies = [] - currency_list = supported_currency_array - company_id = False - if self.company_id.multi_company_currency_enable: - company_id = self.company_id.id - currency_list = supported_currecies[self.service] - if company_id: - currencies = self.env['res.currency'].search( - [('name', 'in', currency_list), - '|', ('company_id', '=', company_id), - ('company_id', '=', False)]) - else: - currencies = self.env['res.currency'].search( - [('name', 'in', currency_list), - ('company_id', '=', False)]) + getter = CurrencyGetterType.get(self.service) + currency_list = getter.supported_currency_array + currencies = self.env['res.currency'].search( + [('name', 'in', currency_list)]) self.currency_list = [(6, 0, [curr.id for curr in currencies])] + def _selection_service(self, *a, **k): + res = [(x.code, x.name) for x in CurrencyGetterType.getters.values()] + return res + # List of webservicies the value sould be a class name service = fields.Selection( - [('CH_ADMIN_getter', 'Admin.ch'), - ('ECB_getter', 'European Central Bank'), - ('YAHOO_getter', 'Yahoo Finance'), - # Added for polish rates - ('PL_NBP_getter', 'National Bank of Poland'), - # Added for mexican rates - ('MX_BdM_getter', 'Bank of Mexico'), - # Bank of Canada is using RSS-CB - # http://www.cbwiki.net/wiki/index.php/Specification_1.1 - # This RSS format is used by other national banks - # (Thailand, Malaysia, Mexico...) - ('CA_BOC_getter', 'Bank of Canada - noon rates'), - # Added for romanian rates - ('RO_BNR_getter', 'National Bank of Romania') - ], + _selection_service, string="Webservice to use", required=True) # List of currencies available on webservice @@ -243,24 +113,15 @@ class Currency_rate_update_service(models.Model): _logger.info( 'Starting to refresh currencies with service %s (company: %s)', self.service, self.company_id.name) - factory = Currency_getter_factory() - curr_obj = self.env['res.currency'] rate_obj = self.env['res.currency.rate'] company = self.company_id # The multi company currency can be set or no so we handle # The two case if company.auto_currency_up: - main_currency = curr_obj.search( - [('base', '=', True), ('company_id', '=', company.id)], - limit=1) + main_currency = self.company_id.currency_id if not main_currency: - # If we can not find a base currency for this company - # we look for one with no company set - main_currency = curr_obj.search( - [('base', '=', True), ('company_id', '=', False)], - limit=1) - if not main_currency: - raise exceptions.Warning(_('There is no base currency set!')) + raise exceptions.Warning(_('There is no main ' + 'currency defined!')) if main_currency.rate != 1: raise exceptions.Warning(_('Base currency rate should ' 'be 1.00!')) @@ -268,9 +129,8 @@ class Currency_rate_update_service(models.Model): try: # We initalize the class that will handle the request # and return a dict of rate - getter = factory.register(self.service) - curr_to_fetch = map(lambda x: x.name, - self.currency_to_update) + getter = CurrencyGetterType.get(self.service) + curr_to_fetch = [x.name for x in self.currency_to_update] res, log_info = getter.get_updated_currency( curr_to_fetch, main_currency.name, @@ -322,6 +182,7 @@ class Currency_rate_update_service(models.Model): _intervalTypes[str(self.interval_type)] (self.interval_number)).date() self.next_run = next_run + return True @api.multi def run_currency_update(self): diff --git a/currency_rate_update/services/__init__.py b/currency_rate_update/services/__init__.py index 5c70dd472..e08882d2e 100644 --- a/currency_rate_update/services/__init__.py +++ b/currency_rate_update/services/__init__.py @@ -1,20 +1,8 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Note, that CA_BOC getter seems not to be working +from . import update_service_CA_BOC +from . import update_service_CH_ADMIN +from . import update_service_ECB +from . import update_service_YAHOO +from . import update_service_PL_NBP +from . import update_service_MX_BdM +from . import update_service_RO_BNR diff --git a/currency_rate_update/services/currency_getter.py b/currency_rate_update/services/currency_getter.py deleted file mode 100644 index 833d89d60..000000000 --- a/currency_rate_update/services/currency_getter.py +++ /dev/null @@ -1,81 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - - -class AbstractClassError(Exception): - def __str__(self): - return 'Abstract Class' - - def __repr__(self): - return 'Abstract Class' - - -class AbstractMethodError(Exception): - def __str__(self): - return 'Abstract Method' - - def __repr__(self): - return 'Abstract Method' - - -class UnknowClassError(Exception): - def __str__(self): - return 'Unknown Class' - - def __repr__(self): - return 'Unknown Class' - - -class UnsuportedCurrencyError(Exception): - def __init__(self, value): - self.curr = value - - def __str__(self): - return 'Unsupported currency %s' % self.curr - - def __repr__(self): - return 'Unsupported currency %s' % self.curr - - -class Currency_getter_factory(): - """Factory pattern class that will return - a currency getter class base on the name passed - to the register method - - """ - def register(self, class_name): - allowed = [ - 'CH_ADMIN_getter', - 'PL_NBP_getter', - 'ECB_getter', - 'GOOGLE_getter', - 'YAHOO_getter', - 'MX_BdM_getter', - 'CA_BOC_getter', - 'RO_BNR_getter', - ] - if class_name in allowed: - exec "from .update_service_%s import %s" % \ - (class_name.replace('_getter', ''), class_name) - class_def = eval(class_name) - return class_def() - else: - raise UnknowClassError diff --git a/currency_rate_update/services/currency_getter_interface.py b/currency_rate_update/services/currency_getter_interface.py index fc2b045bb..f1a4b1ee0 100644 --- a/currency_rate_update/services/currency_getter_interface.py +++ b/currency_rate_update/services/currency_getter_interface.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2008-2016 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging @@ -63,8 +46,55 @@ class UnsuportedCurrencyError(Exception): return 'Unsupported currency %s' % self.curr -class Currency_getter_interface(object): - "Abstract class of currency getter" +class CurrencyGetterType(type): + """ Meta class for currency getters. + Automaticaly registers new curency getter on class definition + """ + getters = {} + + def __new__(mcs, name, bases, attrs): + cls = super(CurrencyGetterType, mcs).__new__(mcs, name, bases, attrs) + if getattr(cls, 'code', None): + mcs.getters[cls.code] = cls + return cls + + @classmethod + def get(mcs, code, *args, **kwargs): + """ Get getter by code + """ + return mcs.getters[code](*args, **kwargs) + + +class CurrencyGetterInterface(object): + """ Abstract class of currency getter + + To create new getter, just subclass this class + and define class variables 'code' and 'name' + and implement *get_updated_currency* method + + For example:: + + from openerp.addons.currency_rate_update \ + import CurrencyGetterInterface + + class MySuperCurrencyGetter(CurrencyGetterInterface): + code = "MSCG" + name = "My Currency Rates" + supported_currency_array = ['USD', 'EUR'] + + def get_updated_currency(self, currency_array, main_currency, + max_delta_days): + # your code that fills self.updated_currency + + # and return result + return self.updated_currency, self.log_info + + """ + __metaclass__ = CurrencyGetterType + + # attributes required for currency getters + code = None # code for service selection + name = None # displayed name log_info = " " diff --git a/currency_rate_update/services/update_service_CA_BOC.py b/currency_rate_update/services/update_service_CA_BOC.py index 5cd0e3e49..d50fada88 100644 --- a/currency_rate_update/services/update_service_CA_BOC.py +++ b/currency_rate_update/services/update_service_CA_BOC.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from Bank of Canada -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from .currency_getter_interface import Currency_getter_interface +# © 2009 Camptocamp +# © 2014 Daniel Dico +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from .currency_getter_interface import CurrencyGetterInterface from openerp import _ from openerp.exceptions import except_orm @@ -29,11 +12,26 @@ import logging _logger = logging.getLogger(__name__) -class CA_BOC_getter(Currency_getter_interface): +class CA_BOCGetter(CurrencyGetterInterface): """Implementation of Curreny_getter_factory interface for Bank of Canada RSS service """ + # Bank of Canada is using RSS-CB + # http://www.cbwiki.net/wiki/index.php/Specification_1.1 + # This RSS format is used by other national banks + # (Thailand, Malaysia, Mexico...) + + code = 'CA_BOC' + name = 'Bank of Canada - noon rates' + + supported_currency_array = [ + "AED", "ANG", "ARS", "AUD", "BOC", "BRL", "BSD", "CHF", "CLP", "CNY", + "COP", "CZK", "DKK", "EUR", "FJD", "GBP", "GHS", "GTQ", "HKD", "HNL", + "HRK", "HUF", "IDR", "ILS", "INR", "ISK", "JMD", "JPY", "KRW", "LKR", + "MAD", "MMK", "MXN", "MYR", "NOK", "NZD", "PAB", "PEN", "PHP", "PKR", + "PLN", "RON", "RSD", "RUB", "SEK", "SGD", "THB", "TND", "TRY", "TTD", + "TWD", "USD", "VEF", "VND", "XAF", "XCD", "XPF", "ZAR"] def get_updated_currency(self, currency_array, main_currency, max_delta_days): diff --git a/currency_rate_update/services/update_service_CH_ADMIN.py b/currency_rate_update/services/update_service_CH_ADMIN.py index 6c4d48e64..e2e32aea2 100644 --- a/currency_rate_update/services/update_service_CH_ADMIN.py +++ b/currency_rate_update/services/update_service_CH_ADMIN.py @@ -1,26 +1,8 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from Swiss Federal Authorities -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from .currency_getter_interface import Currency_getter_interface +# © 2008 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from .currency_getter_interface import CurrencyGetterInterface import logging from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -28,11 +10,24 @@ from openerp.tools import DEFAULT_SERVER_DATE_FORMAT _logger = logging.getLogger(__name__) -class CH_ADMIN_getter(Currency_getter_interface): +class CH_ADMINGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for Admin.ch service. """ + code = 'CH_ADMIN' + name = 'Admin.ch' + + supported_currency_array = [ + "AED", "ALL", "ARS", "AUD", "AZN", "BAM", "BDT", "BGN", "BHD", "BRL", + "CAD", "CHF", "CLP", "CNY", "COP", "CRC", "CZK", "DKK", "DOP", "EGP", + "ETB", "EUR", "GBP", "GTQ", "HKD", "HNL", "HRK", "HUF", "IDR", "ILS", + "INR", "ISK", "JPY", "KES", "KHR", "KRW", "KWD", "KYD", "KZT", "LBP", + "LKR", "LTL", "LVL", "LYD", "MAD", "MUR", "MXN", "MYR", "NGN", "NOK", + "NZD", "OMR", "PAB", "PEN", "PHP", "PKR", "PLN", "QAR", "RON", "RSD", + "RUB", "SAR", "SEK", "SGD", "THB", "TND", "TRY", "TWD", "TZS", "UAH", + "USD", "UYU", "VEF", "VND", "ZAR"] + def rate_retrieve(self, dom, ns, curr): """Parse a dom node to retrieve currencies data""" res = {} diff --git a/currency_rate_update/services/update_service_ECB.py b/currency_rate_update/services/update_service_ECB.py index d5e815030..16156e98a 100644 --- a/currency_rate_update/services/update_service_ECB.py +++ b/currency_rate_update/services/update_service_ECB.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from European Central Bank -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from .currency_getter_interface import Currency_getter_interface +# © 2009 Camptocamp +# © 2009 Grzegorz Grzelak +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from .currency_getter_interface import CurrencyGetterInterface from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -29,10 +12,17 @@ import logging _logger = logging.getLogger(__name__) -class ECB_getter(Currency_getter_interface): +class ECBGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for ECB service """ + code = 'ECB' + name = 'European Central Bank' + supported_currency_array = [ + "AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EUR", "GBP", + "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "LTL", "MXN", + "MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", "SGD", "THB", + "TRY", "USD", "ZAR"] def rate_retrieve(self, dom, ns, curr): """Parse a dom node to retrieve- diff --git a/currency_rate_update/services/update_service_MX_BdM.py b/currency_rate_update/services/update_service_MX_BdM.py index 8b3b336f9..4d0bc30f0 100644 --- a/currency_rate_update/services/update_service_MX_BdM.py +++ b/currency_rate_update/services/update_service_MX_BdM.py @@ -1,37 +1,29 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from Banco de México -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2009 Camptocamp +# © 2013-2014 Agustin Cruz openpyme.mx +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from .currency_getter_interface import Currency_getter_interface +from .currency_getter_interface import CurrencyGetterInterface import logging _logger = logging.getLogger(__name__) -class MX_BdM_getter(Currency_getter_interface): +class MX_BdMGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for Banco de México service """ + code = 'MX_BdM' + name = 'Bank of Mexico' + supported_currency_array = [ + "ARS", "AUD", "BBD", "BMD", "BOB", "BRL", "BSD", "BZD", "CAD", "CHF", + "CLP", "CNH", "CNY", "COP", "CRC", "CUP", "CZK", "DKK", "DOP", "DZD", + "EGP", "ESD", "EUR", "FJD", "GBP", "GTQ", "GYD", "HKD", "HNL", "HUF", + "IDR", "ILS", "INR", "IQD", "JMD", "JPY", "KES", "KRW", "KWD", "MAD", + "MYR", "NGN", "NIC", "NOK", "NZD", "PAB", "PEN", "PHP", "PLN", "PYG", + "RON", "RUB", "SAR", "SEK", "SGD", "SVC", "THB", "TRY", "TTD", "TWD", + "UAH", "USD", "USD", "UYP", "VEF", "VND", "ZAR"] def rate_retrieve(self): """ Get currency exchange from Banxico.xml and proccess it diff --git a/currency_rate_update/services/update_service_PL_NBP.py b/currency_rate_update/services/update_service_PL_NBP.py index e354540b4..e25ad925e 100644 --- a/currency_rate_update/services/update_service_PL_NBP.py +++ b/currency_rate_update/services/update_service_PL_NBP.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from National Bank of Poland -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from .currency_getter_interface import Currency_getter_interface +# © 2009 Camptocamp +# © 2009 Grzegorz Grzelak +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from .currency_getter_interface import CurrencyGetterInterface from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -29,11 +12,19 @@ import logging _logger = logging.getLogger(__name__) -class PL_NBP_getter(Currency_getter_interface): +class PL_NBPGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for PL NBP service """ + code = 'PL_NBP' + name = 'National Bank of Poland' + + supported_currency_array = [ + "AUD", "BGN", "BRL", "CAD", "CHF", "CLP", "CNY", "CZK", "DKK", "EUR", + "GBP", "HKD", "HRK", "HUF", "IDR", "ILS", "INR", "ISK", "JPY", "KRW", + "LTL", "MXN", "MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", + "SGD", "THB", "TRY", "UAH", "USD", "XDR", "ZAR"] def rate_retrieve(self, dom, ns, curr): """ Parse a dom node to retrieve diff --git a/currency_rate_update/services/update_service_RO_BNR.py b/currency_rate_update/services/update_service_RO_BNR.py index c27d2b971..650bcb85f 100644 --- a/currency_rate_update/services/update_service_RO_BNR.py +++ b/currency_rate_update/services/update_service_RO_BNR.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from National Bank of Romania -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## -from .currency_getter_interface import Currency_getter_interface +# © 2009 Camptocamp +# © 2014 Dorin Hongu +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from .currency_getter_interface import CurrencyGetterInterface from datetime import datetime, timedelta @@ -28,9 +11,17 @@ import logging _logger = logging.getLogger(__name__) -class RO_BNR_getter(Currency_getter_interface): +class RO_BNRGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for BNR service""" + code = 'RO_BNR' + name = 'National Bank of Romania' + supported_currency_array = [ + "AED", "AUD", "BGN", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EGP", + "EUR", "GBP", "HUF", "INR", "JPY", "KRW", "MDL", "MXN", "NOK", "NZD", + "PLN", "RON", "RSD", "RUB", "SEK", "TRY", "UAH", "USD", "XAU", "XDR", + "ZAR"] + def rate_retrieve(self, dom, ns, curr): """ Parse a dom node to retrieve- currencies data""" diff --git a/currency_rate_update/services/update_service_YAHOO.py b/currency_rate_update/services/update_service_YAHOO.py index 56017126f..1ecde3ebe 100644 --- a/currency_rate_update/services/update_service_YAHOO.py +++ b/currency_rate_update/services/update_service_YAHOO.py @@ -1,33 +1,35 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (c) 2009 CamptoCamp. All rights reserved. -# @author Nicolas Bessi -# -# Abstract class to fetch rates from Yahoo Financial -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2009 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from .currency_getter_interface import Currency_getter_interface +from .currency_getter_interface import CurrencyGetterInterface -class YAHOO_getter(Currency_getter_interface): +class YAHOOGetter(CurrencyGetterInterface): """Implementation of Currency_getter_factory interface for Yahoo finance service """ + code = 'YAHOO' + name = 'Yahoo Finance' + + supported_currency_array = [ + "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", + "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", + "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", + "CNH", "CNY", "COP", "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", + "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", + "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", + "IDR", "IEP", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", + "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", + "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", + "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", + "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", + "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", + "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", + "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", + "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", + "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XCP", "XDR", "XOF", + "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL"] def get_updated_currency(self, currency_array, main_currency, max_delta_days): diff --git a/currency_rate_update/view/company_view.xml b/currency_rate_update/view/company_view.xml index 60ebb8a27..1700f10cf 100644 --- a/currency_rate_update/view/company_view.xml +++ b/currency_rate_update/view/company_view.xml @@ -9,7 +9,6 @@ - diff --git a/currency_rate_update/view/currency_rate_update.xml b/currency_rate_update/view/currency_rate_update.xml index e7c5fa62c..bd0cf62ab 100644 --- a/currency_rate_update/view/currency_rate_update.xml +++ b/currency_rate_update/view/currency_rate_update.xml @@ -29,6 +29,8 @@ invisible="not context.get('currency_rate_update_main_view')" required="context.get('currency_rate_update_main_view')"/> +