From 53c36243f83a53baba224e6a417456e3ec65fb62 Mon Sep 17 00:00:00 2001 From: vrenaville Date: Fri, 30 Oct 2015 13:33:03 +0100 Subject: [PATCH 1/5] [IMP] Port to V9 --- currency_rate_update/README.rst | 4 +-- currency_rate_update/__openerp__.py | 4 +-- currency_rate_update/model/company.py | 30 +++++-------------- .../model/currency_rate_update.py | 28 ++++------------- currency_rate_update/view/company_view.xml | 1 - .../view/currency_rate_update.xml | 2 +- 6 files changed, 17 insertions(+), 52 deletions(-) diff --git a/currency_rate_update/README.rst b/currency_rate_update/README.rst index 02354a574..a37770889 100644 --- a/currency_rate_update/README.rst +++ b/currency_rate_update/README.rst @@ -74,8 +74,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 @@ -92,6 +91,7 @@ Contributors * Agustin Cruz (BdM) * Dorin Hongu (BNR) * Fekete Mihai (Port to V8) +* Vincent Renaville (Port to V9) Maintainer ---------- diff --git a/currency_rate_update/__openerp__.py b/currency_rate_update/__openerp__.py index b72ba737b..5fe2bf232 100644 --- a/currency_rate_update/__openerp__.py +++ b/currency_rate_update/__openerp__.py @@ -20,7 +20,7 @@ ############################################################################## { "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", @@ -38,5 +38,5 @@ ], "demo": [], "active": False, - 'installable': False + 'installable': True } diff --git a/currency_rate_update/model/company.py b/currency_rate_update/model/company.py index a71d27987..d7e5708a1 100644 --- a/currency_rate_update/model/company.py +++ b/currency_rate_update/model/company.py @@ -22,37 +22,21 @@ 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..dc50f478f 100644 --- a/currency_rate_update/model/currency_rate_update.py +++ b/currency_rate_update/model/currency_rate_update.py @@ -164,19 +164,9 @@ class Currency_rate_update_service(models.Model): 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)]) + currencies = self.env['res.currency'].search( + [('name', 'in', currency_list)]) self.currency_list = [(6, 0, [curr.id for curr in currencies])] # List of webservicies the value sould be a class name @@ -244,23 +234,15 @@ class Currency_rate_update_service(models.Model): '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!')) 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..c977e91b0 100644 --- a/currency_rate_update/view/currency_rate_update.xml +++ b/currency_rate_update/view/currency_rate_update.xml @@ -55,7 +55,7 @@ + parent="account.menu_finance_configuration" sequence="21"/> From 3caaaf5a38aa8709fa503faeecf68d8e7380bff2 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Wed, 4 May 2016 17:11:22 +0200 Subject: [PATCH 2/5] Fix contributors, short license headers and copyrights There was missing a bunch of people there! --- currency_rate_update/README.rst | 19 +++++++++++--- currency_rate_update/__init__.py | 21 ---------------- currency_rate_update/__openerp__.py | 21 ++-------------- currency_rate_update/model/__init__.py | 21 ---------------- currency_rate_update/model/company.py | 21 ++-------------- .../model/currency_rate_update.py | 22 +++------------- currency_rate_update/services/__init__.py | 20 --------------- .../services/currency_getter.py | 22 ++-------------- .../services/currency_getter_interface.py | 21 ++-------------- .../services/update_service_CA_BOC.py | 25 +++---------------- .../services/update_service_CH_ADMIN.py | 24 +++--------------- .../services/update_service_ECB.py | 25 +++---------------- .../services/update_service_MX_BdM.py | 24 +++--------------- .../services/update_service_PL_NBP.py | 25 +++---------------- .../services/update_service_RO_BNR.py | 25 +++---------------- .../services/update_service_YAHOO.py | 23 ++--------------- 16 files changed, 50 insertions(+), 309 deletions(-) diff --git a/currency_rate_update/README.rst b/currency_rate_update/README.rst index a37770889..011328481 100644 --- a/currency_rate_update/README.rst +++ b/currency_rate_update/README.rst @@ -83,15 +83,26 @@ 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) -* Vincent Renaville (Port to V9) +* Dorin Hongu (BNR) +* Paul McDermott +* Alexis de Lattre +* Miku Laitinen +* Assem Bayahi +* Daniel Dico (BOC) + Maintainer ---------- diff --git a/currency_rate_update/__init__.py b/currency_rate_update/__init__.py index 75d7d0aa3..9186ee3ad 100644 --- a/currency_rate_update/__init__.py +++ b/currency_rate_update/__init__.py @@ -1,22 +1 @@ -# -*- 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 diff --git a/currency_rate_update/__openerp__.py b/currency_rate_update/__openerp__.py index 5fe2bf232..c90da1c72 100644 --- a/currency_rate_update/__openerp__.py +++ b/currency_rate_update/__openerp__.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). { "name": "Currency Rate Update", "version": "9.0.1.0.0", 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 d7e5708a1..f88ce6514 100644 --- a/currency_rate_update/model/company.py +++ b/currency_rate_update/model/company.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 . -# -############################################################################## +# © 2009-2016 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import models, fields, api diff --git a/currency_rate_update/model/currency_rate_update.py b/currency_rate_update/model/currency_rate_update.py index dc50f478f..d90e881ba 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 diff --git a/currency_rate_update/services/__init__.py b/currency_rate_update/services/__init__.py index 5c70dd472..e69de29bb 100644 --- a/currency_rate_update/services/__init__.py +++ b/currency_rate_update/services/__init__.py @@ -1,20 +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 . -# -############################################################################## diff --git a/currency_rate_update/services/currency_getter.py b/currency_rate_update/services/currency_getter.py index 833d89d60..074c06a18 100644 --- a/currency_rate_update/services/currency_getter.py +++ b/currency_rate_update/services/currency_getter.py @@ -1,24 +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). class AbstractClassError(Exception): def __str__(self): diff --git a/currency_rate_update/services/currency_getter_interface.py b/currency_rate_update/services/currency_getter_interface.py index fc2b045bb..b6f4125d0 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 diff --git a/currency_rate_update/services/update_service_CA_BOC.py b/currency_rate_update/services/update_service_CA_BOC.py index 5cd0e3e49..b17ea3144 100644 --- a/currency_rate_update/services/update_service_CA_BOC.py +++ b/currency_rate_update/services/update_service_CA_BOC.py @@ -1,25 +1,8 @@ # -*- 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 . -# -############################################################################## +# © 2009 Camptocamp +# © 2014 Daniel Dico +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from .currency_getter_interface import Currency_getter_interface from openerp import _ diff --git a/currency_rate_update/services/update_service_CH_ADMIN.py b/currency_rate_update/services/update_service_CH_ADMIN.py index 6c4d48e64..a7b26d44f 100644 --- a/currency_rate_update/services/update_service_CH_ADMIN.py +++ b/currency_rate_update/services/update_service_CH_ADMIN.py @@ -1,25 +1,7 @@ # -*- 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 . -# -############################################################################## +# © 2008 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from .currency_getter_interface import Currency_getter_interface import logging from datetime import datetime diff --git a/currency_rate_update/services/update_service_ECB.py b/currency_rate_update/services/update_service_ECB.py index d5e815030..fc47ca7c9 100644 --- a/currency_rate_update/services/update_service_ECB.py +++ b/currency_rate_update/services/update_service_ECB.py @@ -1,25 +1,8 @@ # -*- 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 . -# -############################################################################## +# © 2009 Camptocamp +# © 2009 Grzegorz Grzelak +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from .currency_getter_interface import Currency_getter_interface from datetime import datetime diff --git a/currency_rate_update/services/update_service_MX_BdM.py b/currency_rate_update/services/update_service_MX_BdM.py index 8b3b336f9..5290f4193 100644 --- a/currency_rate_update/services/update_service_MX_BdM.py +++ b/currency_rate_update/services/update_service_MX_BdM.py @@ -1,25 +1,7 @@ # -*- 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 diff --git a/currency_rate_update/services/update_service_PL_NBP.py b/currency_rate_update/services/update_service_PL_NBP.py index e354540b4..c334aaa81 100644 --- a/currency_rate_update/services/update_service_PL_NBP.py +++ b/currency_rate_update/services/update_service_PL_NBP.py @@ -1,25 +1,8 @@ # -*- 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 . -# -############################################################################## +# © 2009 Camptocamp +# © 2009 Grzegorz Grzelak +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from .currency_getter_interface import Currency_getter_interface from datetime import datetime diff --git a/currency_rate_update/services/update_service_RO_BNR.py b/currency_rate_update/services/update_service_RO_BNR.py index c27d2b971..ecb9b740c 100644 --- a/currency_rate_update/services/update_service_RO_BNR.py +++ b/currency_rate_update/services/update_service_RO_BNR.py @@ -1,25 +1,8 @@ # -*- 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 . -# -############################################################################## +# © 2009 Camptocamp +# © 2014 Dorin Hongu +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + from .currency_getter_interface import Currency_getter_interface from datetime import datetime, timedelta diff --git a/currency_rate_update/services/update_service_YAHOO.py b/currency_rate_update/services/update_service_YAHOO.py index 56017126f..1b330d57d 100644 --- a/currency_rate_update/services/update_service_YAHOO.py +++ b/currency_rate_update/services/update_service_YAHOO.py @@ -1,25 +1,6 @@ # -*- 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 5e9a0b43f338de3e9c446f47fb74b66afef324c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=BE=20=D0=9A=D0=B0=D1=82?= =?UTF-8?q?=D1=8E=D1=85=D0=B0?= Date: Mon, 29 Feb 2016 18:54:18 +0200 Subject: [PATCH 3/5] [REF] currency_rate_update: refactoring related to PR #318 Conflicts: currency_rate_update/services/__init__.py currency_rate_update/services/currency_getter.py currency_rate_update/services/update_service_CA_BOC.py currency_rate_update/services/update_service_CH_ADMIN.py currency_rate_update/services/update_service_ECB.py currency_rate_update/services/update_service_PL_NBP.py currency_rate_update/services/update_service_RO_BNR.py --- currency_rate_update/README.rst | 1 + currency_rate_update/__init__.py | 1 + currency_rate_update/__openerp__.py | 2 +- .../model/currency_rate_update.py | 131 ++---------------- currency_rate_update/services/__init__.py | 8 ++ .../services/currency_getter.py | 63 --------- .../services/currency_getter_interface.py | 51 ++++++- .../services/update_service_CA_BOC.py | 19 ++- .../services/update_service_CH_ADMIN.py | 17 ++- .../services/update_service_ECB.py | 11 +- .../services/update_service_MX_BdM.py | 14 +- .../services/update_service_PL_NBP.py | 12 +- .../services/update_service_RO_BNR.py | 12 +- .../services/update_service_YAHOO.py | 25 +++- .../view/currency_rate_update.xml | 2 + 15 files changed, 171 insertions(+), 198 deletions(-) delete mode 100644 currency_rate_update/services/currency_getter.py diff --git a/currency_rate_update/README.rst b/currency_rate_update/README.rst index 011328481..fa1b2b416 100644 --- a/currency_rate_update/README.rst +++ b/currency_rate_update/README.rst @@ -102,6 +102,7 @@ Contributors * 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 9186ee3ad..d99ae047e 100644 --- a/currency_rate_update/__init__.py +++ b/currency_rate_update/__init__.py @@ -1 +1,2 @@ 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 c90da1c72..b59d44c5f 100644 --- a/currency_rate_update/__openerp__.py +++ b/currency_rate_update/__openerp__.py @@ -19,7 +19,7 @@ "security/rule.xml", "security/ir.model.access.csv", ], + "images": [], "demo": [], - "active": False, 'installable': True } diff --git a/currency_rate_update/model/currency_rate_update.py b/currency_rate_update/model/currency_rate_update.py index d90e881ba..143de88a6 100644 --- a/currency_rate_update/model/currency_rate_update.py +++ b/currency_rate_update/model/currency_rate_update.py @@ -11,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__) @@ -21,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" @@ -147,29 +53,19 @@ class Currency_rate_update_service(models.Model): currency_list = '' if self.service: currencies = [] - currency_list = supported_currency_array - currency_list = supported_currecies[self.service] + 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 @@ -217,7 +113,6 @@ 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() rate_obj = self.env['res.currency.rate'] company = self.company_id # The multi company currency can be set or no so we handle @@ -234,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, @@ -288,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 e69de29bb..e08882d2e 100644 --- a/currency_rate_update/services/__init__.py +++ b/currency_rate_update/services/__init__.py @@ -0,0 +1,8 @@ +# 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 074c06a18..000000000 --- a/currency_rate_update/services/currency_getter.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2008-2016 Camptocamp -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -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 b6f4125d0..f1a4b1ee0 100644 --- a/currency_rate_update/services/currency_getter_interface.py +++ b/currency_rate_update/services/currency_getter_interface.py @@ -46,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 b17ea3144..d50fada88 100644 --- a/currency_rate_update/services/update_service_CA_BOC.py +++ b/currency_rate_update/services/update_service_CA_BOC.py @@ -3,7 +3,7 @@ # © 2014 Daniel Dico # 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 from openerp import _ from openerp.exceptions import except_orm @@ -12,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 a7b26d44f..e2e32aea2 100644 --- a/currency_rate_update/services/update_service_CH_ADMIN.py +++ b/currency_rate_update/services/update_service_CH_ADMIN.py @@ -2,7 +2,7 @@ # © 2008 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 import logging from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -10,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 fc47ca7c9..16156e98a 100644 --- a/currency_rate_update/services/update_service_ECB.py +++ b/currency_rate_update/services/update_service_ECB.py @@ -3,7 +3,7 @@ # © 2009 Grzegorz Grzelak # 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 from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -12,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 5290f4193..4d0bc30f0 100644 --- a/currency_rate_update/services/update_service_MX_BdM.py +++ b/currency_rate_update/services/update_service_MX_BdM.py @@ -3,17 +3,27 @@ # © 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 c334aaa81..e25ad925e 100644 --- a/currency_rate_update/services/update_service_PL_NBP.py +++ b/currency_rate_update/services/update_service_PL_NBP.py @@ -3,7 +3,7 @@ # © 2009 Grzegorz Grzelak # 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 from datetime import datetime from openerp.tools import DEFAULT_SERVER_DATE_FORMAT @@ -12,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 ecb9b740c..650bcb85f 100644 --- a/currency_rate_update/services/update_service_RO_BNR.py +++ b/currency_rate_update/services/update_service_RO_BNR.py @@ -3,7 +3,7 @@ # © 2014 Dorin Hongu # 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 from datetime import datetime, timedelta @@ -11,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 1b330d57d..1ecde3ebe 100644 --- a/currency_rate_update/services/update_service_YAHOO.py +++ b/currency_rate_update/services/update_service_YAHOO.py @@ -2,13 +2,34 @@ # © 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/currency_rate_update.xml b/currency_rate_update/view/currency_rate_update.xml index c977e91b0..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')"/> +