From d0b4f784b205276d5b478b5ed58a16b75c4adc1a Mon Sep 17 00:00:00 2001 From: Daniel Blanco Date: Thu, 21 May 2015 20:37:09 -0300 Subject: [PATCH 01/31] Actualizacion branch 8.0 --- .gitignore | 2 ++ LICENSE | 0 __init__.py | 0 __openerp__.py | 2 +- apikey.py.sample | 0 ir_cron.xml | 0 l10n_cl_financial_indicators.py | 0 static/description/icon.png | Bin static/description/index.html | 36 ++++++++++++++++++++++++++++++++ 9 files changed, 39 insertions(+), 1 deletion(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 __init__.py mode change 100644 => 100755 __openerp__.py mode change 100644 => 100755 apikey.py.sample mode change 100644 => 100755 ir_cron.xml mode change 100644 => 100755 l10n_cl_financial_indicators.py mode change 100644 => 100755 static/description/icon.png create mode 100644 static/description/index.html diff --git a/.gitignore b/.gitignore index 51f7adb..5a86419 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.pyc +.~* apikey.py + diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/__init__.py b/__init__.py old mode 100644 new mode 100755 diff --git a/__openerp__.py b/__openerp__.py old mode 100644 new mode 100755 index d707c7b..47355c9 --- a/__openerp__.py +++ b/__openerp__.py @@ -27,7 +27,7 @@ 'category': 'Tools', 'complexity': "easy", 'description': "Update UF, UTM and Dollar Official Value in a daily basis using SBIF webservices", - 'author': 'Blanco Martin y Asociados', + 'author': 'Blanco Martin & Asociados', 'website': 'http://blancomartin.cl', 'depends': ['base'], 'init_xml': [], diff --git a/apikey.py.sample b/apikey.py.sample old mode 100644 new mode 100755 diff --git a/ir_cron.xml b/ir_cron.xml old mode 100644 new mode 100755 diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py old mode 100644 new mode 100755 diff --git a/static/description/icon.png b/static/description/icon.png old mode 100644 new mode 100755 diff --git a/static/description/index.html b/static/description/index.html new file mode 100644 index 0000000..52a209e --- /dev/null +++ b/static/description/index.html @@ -0,0 +1,36 @@ +
+
+

Odoo regionalización para Chile

+

Actualización de índices financieros desde Superintendencia de Bancos e Instituciones Financieras de Chile (SBIF).
por Blanco Martín & Asociados

+
+
+

+ Requiere una clave API, la cual se obtiene desde
+ http://api.sbif.cl (Actualiza los índices y los toma como una moneda (UTM, UF, Dolar y Euro).
+ Esto permite por ejemplo, fijar precios de productos en UF y que el precio en CLP se actualice al momento de facturar. +

+ +
+
+
+
+

Cómo se usa:


+
+ + + +
+
+
+

Mejoras que faltan realizar: (TO-DOs)


+
+
+
  • Ingresar las monedas, o actualizarlas al momento de facturar.
  • +
  • Mejorar los tutoriales en video, con más ejemplos.
  • +
  • Agregar un modelo que agregue un lugar en la configuración para incluir la clave API (actualmente se debe colocar en el archivo, antes de instalar).
  • +
    +
    +
    + + +
    From 68a9cda6ff920b0639857e1bcd69e29e7d23c42f Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 21:49:04 -0300 Subject: [PATCH 02/31] Agrego yml travis --- .travis.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b1a6821 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +addons: + apt: + packages: + - python-httplib2 + +language: python +sudo: false +cache: pip + +python: + - '2.7' + +env: + - VERSION="8.0" LINT_CHECK="1" + - VERSION="8.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0" + - VERSION="8.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0" + + matrix: + - TESTS="1" ODOO_REPO="odoo/odoo" + - UNIT_TEST="1" + +virtualenv: + system_site_packages: true + +install: + + - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools + - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - travis_install_nightly + +script: + - travis_run_tests + +after_success: + coveralls \ No newline at end of file From 94bd46cd43d4382f73c812a2d818abc09f84996e Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 21:51:28 -0300 Subject: [PATCH 03/31] remove lint by now --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b1a6821..77a641c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ python: - '2.7' env: - - VERSION="8.0" LINT_CHECK="1" + #- VERSION="8.0" LINT_CHECK="1" - VERSION="8.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0" - VERSION="8.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0" From c84929e1cd9d92653645654b8fcb7e0b81d655eb Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 22:01:48 -0300 Subject: [PATCH 04/31] Correct yaml --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 77a641c..854831d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,16 +8,16 @@ sudo: false cache: pip python: - - '2.7' +- '2.7' env: - #- VERSION="8.0" LINT_CHECK="1" - - VERSION="8.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0" - - VERSION="8.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0" +- VERSION="8.0" LINT_CHECK="1" +- VERSION="8.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0" +- VERSION="8.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0" - matrix: - - TESTS="1" ODOO_REPO="odoo/odoo" - - UNIT_TEST="1" +matrix: +- TESTS="1" ODOO_REPO="odoo/odoo" +- UNIT_TEST="1" virtualenv: system_site_packages: true From 416c1503b50110ccf8e37a345b70ddf32522be26 Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 22:20:54 -0300 Subject: [PATCH 05/31] Syntax and library checks travis --- __init__.py | 2 +- __openerp__.py | 36 ++++++++++++++++----------------- l10n_cl_financial_indicators.py | 28 ++++++++++++++----------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/__init__.py b/__init__.py index aed4ce3..036acfe 100755 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -import l10n_cl_financial_indicators \ No newline at end of file +import l10n_cl_financial_indicators diff --git a/__openerp__.py b/__openerp__.py index 47355c9..08cde5d 100755 --- a/__openerp__.py +++ b/__openerp__.py @@ -1,22 +1,19 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Odoo, Open Source Management Solution -# Copyright (C) 2004-2015 OdooL (). -# -# 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 module authored by Daniel Blanco, Blanco Martín & Asociados -# -# 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 . +# Odoo, Open Source Management Solution +# Copyright (C) 2004-2015 OdooL (). +# 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 module authored by Daniel Blanco, Blanco Martín & Asociados +# 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 . # ############################################################################## @@ -26,17 +23,18 @@ 'version': '0.1', 'category': 'Tools', 'complexity': "easy", - 'description': "Update UF, UTM and Dollar Official Value in a daily basis using SBIF webservices", + 'description': """Update UF, UTM and Dollar Official Value in a daily basis + using SBIF webservices""", 'author': 'Blanco Martin & Asociados', 'website': 'http://blancomartin.cl', 'depends': ['base'], 'init_xml': [], 'update_xml': [ - 'ir_cron.xml' + 'ir_cron.xml' ], 'demo_xml': [ ], - 'test':[ + 'test': [ ], 'installable': True, } diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index a8ab0f2..a8c594b 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -1,32 +1,36 @@ # -*- coding: utf-8 -*- -from openerp.osv import osv,fields +from openerp.osv import osv import urllib2 as u -import string + import simplejson as json + class l10n_cl_financial_indicators(osv.osv): _name = "res.currency.rate" _inherit = "res.currency.rate" - - def currency_schedule_update(self,cr,uid,context=None): + + # schedule update + def currency_schedule_update(self, cr, uid, context=None): from apikey import apikey indicadores = { - ('dolar','Dolares','USD'), - ('euro','Euros','EUR'), - ('uf','UFs','UF'), - ('utm','UTMs','UTM'), + ('dolar', 'Dolares', 'USD'), + ('euro', 'Euros', 'EUR'), + ('uf', 'UFs', 'UF'), + ('utm', 'UTMs', 'UTM'), } for indic in indicadores: - url = 'http://api.sbif.cl/api-sbifv3/recursos_api/'+indic[0]+'?apikey='+apikey+'&formato=json' + url = 'http://api.sbif.cl/api-sbifv3/recursos_api/'+indic[0] + url += '?apikey='+apikey+'&formato=json' f = u.urlopen(url) data = f.read() data_json = json.loads(data) - rate = float(data_json[indic[1]][0]['Valor'].replace('.','').replace(',','.')) - + rate = data_json[indic[1]][0]['Valor'].replace('.', '') + rate = float(rate.replace(',', '.')) currency_obj = self.pool.get('res.currency') currency_rate_obj = self.pool.get('res.currency.rate') - currency_id = currency_obj.search(cr, uid, [('name', '=', indic[2])]) + currency_id = currency_obj.search(cr, uid, [( + 'name', '=', indic[2])]) #print "Actualizacion " + indic[2] if not currency_id: print "No esta cargado el " + indic[2] From 93b2eec36d967060d6e34173621b80563f4495ed Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 22:25:50 -0300 Subject: [PATCH 06/31] correcciones de espacios --- l10n_cl_financial_indicators.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index a8c594b..9a22a15 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -25,13 +25,14 @@ def currency_schedule_update(self, cr, uid, context=None): f = u.urlopen(url) data = f.read() data_json = json.loads(data) - rate = data_json[indic[1]][0]['Valor'].replace('.', '') - rate = float(rate.replace(',', '.')) + rate = float( + data_json[indic[1]][0]['Valor'].replace( + '.', '').replace(',', '.')) currency_obj = self.pool.get('res.currency') currency_rate_obj = self.pool.get('res.currency.rate') currency_id = currency_obj.search(cr, uid, [( 'name', '=', indic[2])]) - #print "Actualizacion " + indic[2] + # print "Actualizacion " + indic[2] if not currency_id: print "No esta cargado el " + indic[2] else: @@ -41,8 +42,8 @@ def currency_schedule_update(self, cr, uid, context=None): 'currency_id': currency_id[0], 'currency_type_id': '' } - currency_rate_obj.create(cr,uid,values) + currency_rate_obj.create(cr, uid, values) return True - + l10n_cl_financial_indicators() From c4dfb65e0850b8898845a9331be70ffd329e4292 Mon Sep 17 00:00:00 2001 From: Danisan Date: Sun, 20 Sep 2015 22:31:48 -0300 Subject: [PATCH 07/31] cambios travis --- __init__.py | 2 +- __openerp__.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 036acfe..2e565d1 100755 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -import l10n_cl_financial_indicators +import l10n_cl_financial_indicators.l10n_cl_financial_indicators diff --git a/__openerp__.py b/__openerp__.py index 08cde5d..52803c9 100755 --- a/__openerp__.py +++ b/__openerp__.py @@ -22,9 +22,9 @@ 'name': 'Chilean Financial Indicators', 'version': '0.1', 'category': 'Tools', - 'complexity': "easy", - 'description': """Update UF, UTM and Dollar Official Value in a daily basis - using SBIF webservices""", + 'complexity': 'easy', + 'description': '''Update UF, UTM and Dollar Official Value in a daily basis +using SBIF webservices''', 'author': 'Blanco Martin & Asociados', 'website': 'http://blancomartin.cl', 'depends': ['base'], From ffc78b2e6dee824d80c1148c395e6696fb12863a Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 00:51:21 -0300 Subject: [PATCH 08/31] Eliminated print lines --- l10n_cl_financial_indicators.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index 9a22a15..140e506 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -1,9 +1,12 @@ # -*- coding: utf-8 -*- from openerp.osv import osv import urllib2 as u - import simplejson as json +import logging + +_logger = logging.getLogger(__name__) + class l10n_cl_financial_indicators(osv.osv): _name = "res.currency.rate" @@ -20,8 +23,8 @@ def currency_schedule_update(self, cr, uid, context=None): } for indic in indicadores: - url = 'http://api.sbif.cl/api-sbifv3/recursos_api/'+indic[0] - url += '?apikey='+apikey+'&formato=json' + baseurl = 'http://api.sbif.cl/api-sbifv3/recursos_api/' + url = baseurl + indic[0] + '?apikey=' + apikey + '&formato=json' f = u.urlopen(url) data = f.read() data_json = json.loads(data) @@ -34,9 +37,9 @@ def currency_schedule_update(self, cr, uid, context=None): 'name', '=', indic[2])]) # print "Actualizacion " + indic[2] if not currency_id: - print "No esta cargado el " + indic[2] + _logger.warning('No esta cargado el %s' % (indic[2])) else: - print "Actualizando " + indic[2] + _logger.info('Actualizando %s' % (indic[2])) values = { 'rate': 1/rate, 'currency_id': currency_id[0], @@ -46,4 +49,4 @@ def currency_schedule_update(self, cr, uid, context=None): return True -l10n_cl_financial_indicators() +#l10n_cl_financial_indicators() From a1cb125226fefb12753926bf5721cacdefc9668f Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 00:55:14 -0300 Subject: [PATCH 09/31] Clean comments --- l10n_cl_financial_indicators.py | 1 - 1 file changed, 1 deletion(-) diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index 140e506..b442e6a 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -49,4 +49,3 @@ def currency_schedule_update(self, cr, uid, context=None): return True -#l10n_cl_financial_indicators() From 31ad1bde5c418fd0ecfc720e07b1fe1858dcb44a Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 00:58:08 -0300 Subject: [PATCH 10/31] delete blank line at the end --- l10n_cl_financial_indicators.py | 1 - 1 file changed, 1 deletion(-) diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index b442e6a..937227d 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -48,4 +48,3 @@ def currency_schedule_update(self, cr, uid, context=None): currency_rate_obj.create(cr, uid, values) return True - From 62dab2f7422585123babfbcb4febe931abd738f9 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 01:07:29 -0300 Subject: [PATCH 11/31] Modify readme file --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5e567c8..949c50c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Build Status](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators.svg?branch=8.0)](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators) +[![Coverage Status](https://coveralls.io/repos/odoo-chile/l10n_cl_financial_indicators/badge.png?branch=8.0)](https://coveralls.io/r/odoo-chile/l10n_cl_financial_indicators?branch=8.0) + Odoo - Update Chilean Financial Indicators ========================================== From 02e1ba6c81c9bab9335e36e6f8df8ae0dd853dd9 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 01:12:01 -0300 Subject: [PATCH 12/31] Add coverage file --- .coveragerc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..6e8a280 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,16 @@ +# Config file .coveragerc + +[report] +include = + */odoo-chile/l10n_cl_financial_indicators/* + +omit = + *__init__.py + *__openerp__.py + +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + # Don't complain about null context checking + if context is None: \ No newline at end of file From 860f9c89d2e04f9e22a9895d236ad85d3ebc6524 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 01:35:30 -0300 Subject: [PATCH 13/31] include coveralls in yaml file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 854831d..01d439d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,4 +32,4 @@ script: - travis_run_tests after_success: - coveralls \ No newline at end of file + - coveralls \ No newline at end of file From 34713033ee29a2cea5da8f4c654c59dbb4e30a96 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 01:49:22 -0300 Subject: [PATCH 14/31] send to coveralls.io --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 949c50c..fee19d0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Odoo - Update Chilean Financial Indicators ========================================== - Module that updates the following indicators used in Chile for Odoo sofware: From 62f02f5f0ca7546d404a174d83571a6b8b926ca9 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 01:55:57 -0300 Subject: [PATCH 15/31] Cambios al readme (coveralls) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fee19d0..34d487c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Build Status](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators.svg?branch=8.0)](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators) -[![Coverage Status](https://coveralls.io/repos/odoo-chile/l10n_cl_financial_indicators/badge.png?branch=8.0)](https://coveralls.io/r/odoo-chile/l10n_cl_financial_indicators?branch=8.0) +[![Coverage Status](https://coveralls.io/repos/odoo-chile/l10n_cl_financial_indicators/badge.svg?branch=8.0&service=github)](https://coveralls.io/github/odoo-chile/l10n_cl_financial_indicators?branch=8.0) Odoo - Update Chilean Financial Indicators ========================================== From 96aaa2d51bdad153438092603438590d1c6ac4d4 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 10:09:56 -0300 Subject: [PATCH 16/31] Add options to omit in coverage config file --- .coveragerc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.coveragerc b/.coveragerc index 6e8a280..52de78a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,6 +5,10 @@ include = */odoo-chile/l10n_cl_financial_indicators/* omit = + */scenario/* + */scenarios/* + */test/* + */tests/* *__init__.py *__openerp__.py From a642422f80d85e922136610631b3ef8d18185c7f Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 11:35:08 -0300 Subject: [PATCH 17/31] Change readme image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 34d487c..507d2a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators.svg?branch=8.0)](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators) +[![Build Status](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators.svg)](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators) [![Coverage Status](https://coveralls.io/repos/odoo-chile/l10n_cl_financial_indicators/badge.svg?branch=8.0&service=github)](https://coveralls.io/github/odoo-chile/l10n_cl_financial_indicators?branch=8.0) Odoo - Update Chilean Financial Indicators From 77dc9819a8058c67a758aac37bb2060d0dfeb680 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 16:34:00 -0300 Subject: [PATCH 18/31] Add codeclimate info addons to .travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 01d439d..600a52a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ addons: apt: packages: - python-httplib2 + code_climate: + repo_token: 97a9e35b387576e47a2c78ad5430580fb9764423cb692e088ef2392524860159 language: python sudo: false From efe2eef78ad6cf2d47f49b8a90739d4803af5812 Mon Sep 17 00:00:00 2001 From: Danisan Date: Mon, 21 Sep 2015 16:43:38 -0300 Subject: [PATCH 19/31] Add codeclimate.yml to run code climate test in new platform. Add codeclimate badge to readme. --- .codeclimate.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 52 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..9360882 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,50 @@ +# This is a sample .codeclimate.yml configured for Engine analysis on Code +# Climate Platform. For an overview of the Code Climate Platform, see here: +# http://docs.codeclimate.com/article/300-the-codeclimate-platform + +# Under the engines key, you can configure which engines will analyze your repo. +# Each key is an engine name. For each value, you need to specify enabled: true +# to enable the engine as well as any other engines-specific configuration. + +# For more details, see here: +# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform + +# For a list of all available engines, see here: +# http://docs.codeclimate.com/article/296-engines-available-engines + +engines: +# to turn on an engine, add it here and set enabled to `true` +# to turn off an engine, set enabled to `false` or remove it + rubocop: + enabled: true + golint: + enabled: true + gofmt: + enabled: true + eslint: + enabled: true + csslint: + enabled: true + +# Engines can analyze files and report issues on them, but you can separately +# decide which files will receive ratings based on those issues. This is +# specified by path patterns under the ratings key. + +# For more details see here: +# http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform + +# Note: If the ratings key is not specified, this will result in a 0.0 GPA on your dashboard. + +# ratings: +# paths: +# - app/** +# - lib/** +# - "**.rb" +# - "**.go" + +# You can globally exclude files from being analyzed by any engine using the +# exclude_paths key. + +#exclude_paths: +#- spec/**/* +#- vendor/**/* diff --git a/README.md b/README.md index 507d2a7..ff20b94 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![Build Status](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators.svg)](https://travis-ci.org/odoo-chile/l10n_cl_financial_indicators) [![Coverage Status](https://coveralls.io/repos/odoo-chile/l10n_cl_financial_indicators/badge.svg?branch=8.0&service=github)](https://coveralls.io/github/odoo-chile/l10n_cl_financial_indicators?branch=8.0) +[![Code Climate](https://codeclimate.com/github/odoo-chile/l10n_cl_financial_indicators/badges/gpa.svg)](https://codeclimate.com/github/odoo-chile/l10n_cl_financial_indicators) + Odoo - Update Chilean Financial Indicators ========================================== From 82bfeabe63020d4fab43891e2b76a9a037f9d297 Mon Sep 17 00:00:00 2001 From: Danisan Date: Thu, 1 Oct 2015 12:27:23 -0300 Subject: [PATCH 20/31] Update README.rst file --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index ff20b94..5ac41ed 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,13 @@ UTM If the spell is not the same, this implementation won't be able to find the currencies or the indexes to update. + +## Credits +

    +Logo BMYA +

    +**Blanco Martin & Asociados EIRL** - http://blancomartin.cl + Actualizador de indices financieros chilenos para Odoo ====================================================== @@ -68,3 +75,8 @@ UTM Si la nomenclatura no es exactamente la misma, esta implementacion no podrá encontrar las monedas para ser actualizadas. +## Credits +

    +Logo BMYA +

    +**Blanco Martin & Asociados EIRL** - http://blancomartin.cl From e159178a8b94dbf8edb75baecb70ec6b623c9b62 Mon Sep 17 00:00:00 2001 From: Danisan Date: Thu, 1 Oct 2015 15:42:23 -0300 Subject: [PATCH 21/31] add absolute ref to apikey.py --- l10n_cl_financial_indicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py index 937227d..6489e7a 100755 --- a/l10n_cl_financial_indicators.py +++ b/l10n_cl_financial_indicators.py @@ -14,7 +14,7 @@ class l10n_cl_financial_indicators(osv.osv): # schedule update def currency_schedule_update(self, cr, uid, context=None): - from apikey import apikey + from l10n_cl_financial_indicators.apikey import apikey indicadores = { ('dolar', 'Dolares', 'USD'), ('euro', 'Euros', 'EUR'), From 39200a368f455f47d19a3033a7e0e8bdddd0c130 Mon Sep 17 00:00:00 2001 From: Danisan Date: Thu, 1 Oct 2015 15:58:13 -0300 Subject: [PATCH 22/31] Change import method --- __init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 2e565d1..cca830e 100755 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -import l10n_cl_financial_indicators.l10n_cl_financial_indicators +from . import l10n_cl_financial_indicators From 07d51ce3660603e30f427a0d5e97b25551a97498 Mon Sep 17 00:00:00 2001 From: Danisan Date: Wed, 6 Jan 2016 14:28:12 -0300 Subject: [PATCH 23/31] Include License AGPL in manifest --- __openerp__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/__openerp__.py b/__openerp__.py index 52803c9..a076efe 100755 --- a/__openerp__.py +++ b/__openerp__.py @@ -22,6 +22,7 @@ 'name': 'Chilean Financial Indicators', 'version': '0.1', 'category': 'Tools', + 'license': 'AGPL-3', 'complexity': 'easy', 'description': '''Update UF, UTM and Dollar Official Value in a daily basis using SBIF webservices''', From 8743bdbe37078e0916604ceb3286602d167e17f4 Mon Sep 17 00:00:00 2001 From: Danisan Date: Sat, 16 Jan 2016 21:29:29 -0300 Subject: [PATCH 24/31] backup --- __init__.py | 3 +- __openerp__.py | 8 +- apikey.py.sample | 1 - data/res.currency.csv | 7 ++ data/webservices.server.csv | 5 ++ l10n_cl_financial_indicators.py | 50 ------------ models/__init__.py | 2 + models/l10n_cl_financial_indicators.py | 103 +++++++++++++++++++++++++ views/update_button.xml | 16 ++++ 9 files changed, 141 insertions(+), 54 deletions(-) delete mode 100755 apikey.py.sample create mode 100644 data/res.currency.csv create mode 100644 data/webservices.server.csv delete mode 100755 l10n_cl_financial_indicators.py create mode 100644 models/__init__.py create mode 100644 models/l10n_cl_financial_indicators.py create mode 100644 views/update_button.xml diff --git a/__init__.py b/__init__.py index cca830e..601ffa6 100755 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- -from . import l10n_cl_financial_indicators +from . import models + diff --git a/__openerp__.py b/__openerp__.py index a076efe..556414d 100755 --- a/__openerp__.py +++ b/__openerp__.py @@ -17,7 +17,6 @@ # ############################################################################## - { 'name': 'Chilean Financial Indicators', 'version': '0.1', @@ -28,7 +27,7 @@ using SBIF webservices''', 'author': 'Blanco Martin & Asociados', 'website': 'http://blancomartin.cl', - 'depends': ['base'], + 'depends': ['base','webservices_generic'], 'init_xml': [], 'update_xml': [ 'ir_cron.xml' @@ -37,6 +36,11 @@ ], 'test': [ ], + 'data': [ + 'views/update_button.xml', + 'data/res.currency.csv', + 'data/webservices.server.csv', + ], 'installable': True, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/apikey.py.sample b/apikey.py.sample deleted file mode 100755 index 56ebaba..0000000 --- a/apikey.py.sample +++ /dev/null @@ -1 +0,0 @@ -apikey = 'put here your own api key' diff --git a/data/res.currency.csv b/data/res.currency.csv new file mode 100644 index 0000000..6f8784d --- /dev/null +++ b/data/res.currency.csv @@ -0,0 +1,7 @@ +"id","active","base","rounding","name","position","accuracy","symbol" +"base.EUR","True","False","0.01","EUR","before","4","€" +"base.UF","True","False","","UF","after","15","UF" +"base.USD","True","False","0.01","USD","before","4","$" +"base.UTM","True","False","1e-06","UTM","after","6","UTM" +"base.CLP","True","True","1.0","CLP","before","4","$" + diff --git a/data/webservices.server.csv b/data/webservices.server.csv new file mode 100644 index 0000000..b6b76a0 --- /dev/null +++ b/data/webservices.server.csv @@ -0,0 +1,5 @@ +"id","active","additional_parameter","auth_method","auth_method_name","http_auth_method","name","response_format","response_format_name","scope","just_url","url" +"sbif_usd","True","formato","data_token","apikey","GET","SBIFUSD","JSON","formato","generic","FALSE","http://api.sbif.cl/api-sbifv3/recursos_api/dolar/" +"sbif_uf","True","formato","data_token","apikey","GET","SBIFUF","JSON","formato","generic","FALSE","http://api.sbif.cl/api-sbifv3/recursos_api/uf/" +"sbif_utm","True","formato","data_token","apikey","GET","SBIFUTM","JSON","formato","generic","FALSE","http://api.sbif.cl/api-sbifv3/recursos_api/utm/" +"sbif_eur","True","formato","data_token","apikey","GET","SBIFEUR","JSON","formato","generic","FALSE","http://api.sbif.cl/api-sbifv3/recursos_api/euro/" diff --git a/l10n_cl_financial_indicators.py b/l10n_cl_financial_indicators.py deleted file mode 100755 index 6489e7a..0000000 --- a/l10n_cl_financial_indicators.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -from openerp.osv import osv -import urllib2 as u -import simplejson as json - -import logging - -_logger = logging.getLogger(__name__) - - -class l10n_cl_financial_indicators(osv.osv): - _name = "res.currency.rate" - _inherit = "res.currency.rate" - - # schedule update - def currency_schedule_update(self, cr, uid, context=None): - from l10n_cl_financial_indicators.apikey import apikey - indicadores = { - ('dolar', 'Dolares', 'USD'), - ('euro', 'Euros', 'EUR'), - ('uf', 'UFs', 'UF'), - ('utm', 'UTMs', 'UTM'), - } - - for indic in indicadores: - baseurl = 'http://api.sbif.cl/api-sbifv3/recursos_api/' - url = baseurl + indic[0] + '?apikey=' + apikey + '&formato=json' - f = u.urlopen(url) - data = f.read() - data_json = json.loads(data) - rate = float( - data_json[indic[1]][0]['Valor'].replace( - '.', '').replace(',', '.')) - currency_obj = self.pool.get('res.currency') - currency_rate_obj = self.pool.get('res.currency.rate') - currency_id = currency_obj.search(cr, uid, [( - 'name', '=', indic[2])]) - # print "Actualizacion " + indic[2] - if not currency_id: - _logger.warning('No esta cargado el %s' % (indic[2])) - else: - _logger.info('Actualizando %s' % (indic[2])) - values = { - 'rate': 1/rate, - 'currency_id': currency_id[0], - 'currency_type_id': '' - } - currency_rate_obj.create(cr, uid, values) - - return True diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..cca830e --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import l10n_cl_financial_indicators diff --git a/models/l10n_cl_financial_indicators.py b/models/l10n_cl_financial_indicators.py new file mode 100644 index 0000000..d1ff381 --- /dev/null +++ b/models/l10n_cl_financial_indicators.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +from openerp import models, fields, api +from datetime import datetime, time +from dateutil.relativedelta import relativedelta +import logging +from openerp.tools.translate import _ +import json +import openerp.addons.decimal_precision as dp +# import openerp.tools.config as cf + +#print "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa" +#print wsg +# from openerp.osv import fields as old_fields +# import openerp.addons.decimal_precision as dp + +# urllib3.disable_warnings() +# http = urllib3.PoolManager() + +indicadores = { + 'SBIFUSD':['dolar', 'Dolares', 'sbif_usd', 'USD'], + 'SBIFEUR':['euro', 'Euros', 'sbif_eur', 'EUR'], + 'SBIFUF':['uf', 'UFs', 'sbif_uf', 'UF'], + 'SBIFUTM':['utm', 'UTMs', 'sbif_utm', 'UTM'], +} + +_logger = logging.getLogger(__name__) + +class l10n_cl_financial_indicators(models.Model): + _inherit = "webservices.server" + + @api.multi + def action_update_currency(self): + self.ensure_one() + _logger.warning('nombre: %s' % self.name) + _logger.warning('url: %s' % self.url) + a = self.generic_connection() + _logger.warning('Datos recibidos... status: %s' % a['status']) + if a['status'] != 200: + _logger.warning('no se pudo conectar: %s' % a['data']) + return + + data_json = a['data'] + + _logger.warning('datos mostrados localmente... Fecha: %s, Valor: %s' % + (data_json[indicadores[self.name][1]][0]['Fecha'], + data_json[indicadores[self.name][1]][0]['Valor']) + + rate = float( + data_json[indicadores[self.name][1]][0]['Valor'].replace( + '.', '').replace(',', '.')) + + _logger.warning('rate: %s' % str(rate)) + + rate_name = fields.Datetime.to_string(datetime.utcnow().replace( + hour=0, minute=0, second=0, microsecond=0)) + + currency_id = self.env['res.currency'].search([( + 'name', '=', indicadores[self.name][3])]) + + if not currency_id: + _logger.warning( + 'No esta cargada "%s" como moneda. No se actualiza.' + % indicadores[self.name][1]) + else: + _logger.info( + 'Actualizando la moneda "%s"' % indicadores[self.name][1]) + values = { + 'currency_id': currency_id.id, + 'rate': 1/rate, + 'name': rate_name + } + self.env['res.currency.rate'].create(values) + _logger.info( + 'Se actualizó la moneda "%s"' % indicadores[self.name][1]) + + ''' + Ejemplo de resultado bueno: + Result: {u'UFs': [{u'Fecha': u'2016-01-16', u'Valor': u'25.629,09'}]}! + Ejemplo de resultado malo: + Result: {"CodigoHTTP": 404, "CodigoError": 81, "Mensaje": "El recurso correspondiente al dia actual aun no ha sido cargado" }! + ''' + # _columns = { + # 'rate': old_fields.function( + # _printed_pices, type='float', + # digits_compute=dp.get_precision('Account'), + # string='Unit Price', multi='printed',), + # + # + + @api.multi + def currency_schedule_update(self): + self.ensure_one() + + for indic in indicadores.iteritems(): + + sbif_svr_data = self.env['webservices.server'].browse( + [('name', '=', indic[0])]) + print 'encontrados!...' + + sbif_svr_data.action_update_currency() + + return True + diff --git a/views/update_button.xml b/views/update_button.xml new file mode 100644 index 0000000..865be86 --- /dev/null +++ b/views/update_button.xml @@ -0,0 +1,16 @@ + + + + + financial.indicators.form + webservices.server + + + +