Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init #10

Closed
wants to merge 4 commits into from
Closed

init #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools
rev: 969238e47c07d0c40573acff81d170f63245d738
rev: 9a170331575a265c092ee6b24b845ec508e8ef75
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
Expand All @@ -49,12 +49,12 @@ repos:
- --repo-name=l10n-venezuela
- --if-source-changed
- repo: https://github.com/OCA/odoo-pre-commit-hooks
rev: v0.0.25
rev: v0.0.29
hooks:
- id: oca-checks-odoo-module
- id: oca-checks-po
- repo: https://github.com/myint/autoflake
rev: v1.6.1
rev: v2.2.1
hooks:
- id: autoflake
args:
Expand All @@ -65,11 +65,11 @@ repos:
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v4.0.0-alpha.8
hooks:
- id: prettier
name: prettier (with plugin-xml)
Expand All @@ -80,15 +80,15 @@ repos:
- --plugin=@prettier/plugin-xml
files: \.(css|htm|html|js|json|jsx|less|md|scss|toml|ts|xml|yaml|yml)$
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.24.0
rev: v9.0.0-alpha.0
hooks:
- id: eslint
verbose: true
args:
- --color
- --fix
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
# exclude autogenerated files
Expand All @@ -110,20 +110,20 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
- repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.8
rev: 3.2.1
hooks:
- id: setuptools-odoo-make-default
- id: setuptools-odoo-get-requirements
Expand All @@ -133,13 +133,13 @@ repos:
- --header
- "# generated from manifests external_dependencies"
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
rev: 6.1.0
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==21.9.2"]
- repo: https://github.com/OCA/pylint-odoo
rev: v8.0.19
rev: v9.0.5
hooks:
- id: pylint_odoo
name: pylint with optional checks
Expand Down
21 changes: 21 additions & 0 deletions res_currency_rate_provider_BCV/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
BCV Currency provider
=================

Hace web scrap del sitio BCV para obtener la tasa de cambio oficial


Autor
~~~~~~~
* Luis Pinzon. https://www.linkedin.com/in/luis-a-pinz%C3%B3n-38103911/

Colaboradores
~~~~~~~~~~~~~


Mantenedor
~~~~~~~~~~~
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

Este módulo es mantenido por la OCA.
1 change: 1 addition & 0 deletions res_currency_rate_provider_BCV/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions res_currency_rate_provider_BCV/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "res_currency_rate_provider_BCV",
"summary": """OCA version for BCV scrapping rates
""",
"version": "16.0.1.1.2",
"development_status": "Beta",
"category": "Financial Management/Configuration",
"website": "https://github.com/OCA/l10n-venezuela",
"author": "Luis Pinzón, Odoo Community Association (OCA)",
"maintainers": ["lapinzon"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["currency_rate_update"],
"data": [
"views/views.xml",
],
}
1 change: 1 addition & 0 deletions res_currency_rate_provider_BCV/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
78 changes: 78 additions & 0 deletions res_currency_rate_provider_BCV/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import logging
from collections import defaultdict
from datetime import datetime

import pytz
import requests
from lxml import etree

from odoo import fields, models

_logger = logging.getLogger(__name__)

TIMEOUT = 5000
MONEDAS = {"EUR": "euro", "CNY": "yuan", "TRY": "lira", "RUB": "rublo", "USD": "dolar"}
CARACAS_TZ = pytz.timezone(
"America/Caracas"
) # se necesita porque la hora de bcv es de vzla


class ResCompany(models.Model):
_inherit = "res.currency.rate.provider"
service = fields.Selection(
selection_add=[("bcv", "BCV scrapping")],
ondelete={"bcv": "set default"},
default="bcv",
)

def _get_supported_currencies(self):
self.ensure_one()
if self.service != "bcv":
return super()._get_supported_currencies()
return list(MONEDAS.keys())

def _obtain_rates(self, base_currency, currencies, date_from, date_to):
self.ensure_one()
if self.service != "bcv":
return super()._obtain_rates(base_currency, currencies, date_from, date_to)

content = defaultdict(dict)

bcv_data = self._scrap(currencies)

for k, v in bcv_data.items():
dt = v[1].isoformat()
content[dt][k] = v[0]

return content

def _scrap(self, available_currencies):
request_url = "http://www.bcv.org.ve/"

rslt = {}
try:
fetched_data = requests.get(request_url, verify=False, timeout=TIMEOUT)
except Exception as e:
_logger.debug("%s, %s", self._name, e)
return rslt

available_currency_names = available_currencies

htmlelem = etree.fromstring(fetched_data.content, etree.HTMLParser())

dt = datetime.now(CARACAS_TZ)
for currency_name in available_currency_names:
try:
if currency_name in ["Bs", "VES", "VEF", "VED"]:
rslt[currency_name] = (1.0, dt)
else:
sValue = htmlelem.xpath(
f".//div[@id='{MONEDAS[currency_name]}']/div/div/div[2]/strong"
)[0].text
value = float(sValue.replace(" ", "").replace(",", "."))

rslt[currency_name] = (1.0 / value, dt)
except Exception as e:
_logger.debug("%s, %s", self._name, e)

return rslt
20 changes: 20 additions & 0 deletions res_currency_rate_provider_BCV/views/views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="res_currency_rate_update_wizard_form" model="ir.ui.view">
<field name="name">res.currency.rate.update.wizard.form</field>
<field name="model">res.currency.rate.update.wizard</field>
<field
name="inherit_id"
ref="currency_rate_update.res_currency_rate_update_wizard_form"
/>
<field name="arch" type="xml">
<xpath expr="//group[@name='date_range']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//group[@name='filter']" position="inside">
<h2>Se tomará la tasa de Hoy</h2>
</xpath>

</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/res_currency_rate_provider_BCV/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading