Skip to content

Commit

Permalink
Fixed access
Browse files Browse the repository at this point in the history
  • Loading branch information
rosenvladimirov committed May 11, 2024
1 parent 302a9be commit 8365a7f
Show file tree
Hide file tree
Showing 175 changed files with 13,056 additions and 9,544 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^l10n_bg_account_financial_forms/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
Expand Down
Empty file modified currency_rate_update_bg_bnb/__init__.py
100755 → 100644
Empty file.
19 changes: 9 additions & 10 deletions currency_rate_update_bg_bnb/__manifest__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Currency Rate Update BNB Static rate',
'version': '16.0.1.0.0',
'category': 'Accounting & Finance',
'summary': 'Allows to download central currency exchange rates from BNB',
'author': 'Rosen Vladimirov,'
'Odoo Community Association (OCA),',
'website': '',
'license': 'AGPL-3',
'depends': [
'currency_rate_update',
"name": "Currency Rate Update BNB Static rate",
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"summary": "Allows to download central currency exchange rates from BNB",
"author": "Rosen Vladimirov," "Odoo Community Association (OCA),",
"website": "",
"license": "AGPL-3",
"depends": [
"currency_rate_update",
],
}
Empty file.
1 change: 0 additions & 1 deletion currency_rate_update_bg_bnb/models/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import res_currency_rate_provider_bg_bnb
108 changes: 72 additions & 36 deletions currency_rate_update_bg_bnb/models/res_currency_rate_provider_bg_bnb.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import datetime
import logging

import requests

from odoo import api, fields, models, _
from lxml import etree

import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)
Expand All @@ -27,44 +24,83 @@ def _get_supported_currencies(self):
if self.service != "BG_BNB":
return super()._get_supported_currencies() # pragma: no cover
return [
"AUD", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EUR", "GBP", "BGN",
"HKD", "HRK", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "LTL", "MXN",
"MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", "SGD", "THB",
"TRY", "USD", "ZAR"]
"AUD",
"BRL",
"CAD",
"CHF",
"CNY",
"CZK",
"DKK",
"EUR",
"GBP",
"BGN",
"HKD",
"HRK",
"HUF",
"IDR",
"ILS",
"INR",
"JPY",
"KRW",
"LTL",
"MXN",
"MYR",
"NOK",
"NZD",
"PHP",
"PLN",
"RON",
"RUB",
"SEK",
"SGD",
"THB",
"TRY",
"USD",
"ZAR",
]

@api.model
def _obtain_rates(self, base_currency, currencies, date_from, date_to):
self.ensure_one()

def rate_retrieve(bnb_dom):
res = {'EUR': {'rate_currency': 1.95583, 'inverted': 1.95583, 'direct': 0.511292}}
res = {
"EUR": {
"rate_currency": 1.95583,
"inverted": 1.95583,
"direct": 0.511292,
}
}
# curr_rate = dom.xpath("//ROW/REVERSERATE")
# direct_rate = dom.xpath("//ROW/RATE")
# gold = dom.xpath("//ROW/GOLD")
rows = []
for curr_name in bnb_dom.xpath("//ROW"):
rows.append({
'GOLD': -1,
'NAME_': None,
'CODE': None,
'RATIO': 1.0,
'REVERSERATE': 0.0,
'RATE': 0.0,
'EXTRAINFO': None,
'CURR_DATE': None,
'TITLE': None,
'F_STAR': None,
})
rows.append(
{
"GOLD": -1,
"NAME_": None,
"CODE": None,
"RATIO": 1.0,
"REVERSERATE": 0.0,
"RATE": 0.0,
"EXTRAINFO": None,
"CURR_DATE": None,
"TITLE": None,
"F_STAR": None,
}
)
for el in curr_name.iter():
rows[-1][el.tag] = el.text
for line in rows:
if line['GOLD'] == 0:
if line["GOLD"] == 0:
continue
if line['GOLD'] == "1" and line['F_STAR'] != 1:
res[line['CODE']] = {
'rate_currency': float(line['REVERSERATE']) * float(line['RATIO']),
'inverted': float(line['RATE']) / float(line['RATIO']),
'direct': float(line['REVERSERATE']) * float(line['RATIO'])
if line["GOLD"] == "1" and line["F_STAR"] != 1:
res[line["CODE"]] = {
"rate_currency": float(line["REVERSERATE"])
* float(line["RATIO"]),
"inverted": float(line["RATE"]) / float(line["RATIO"]),
"direct": float(line["REVERSERATE"]) * float(line["RATIO"]),
}
return res

Expand All @@ -77,27 +113,26 @@ def rate_retrieve(bnb_dom):
)
)

bnb_url = 'https://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm'
bnb_params = {'download': 'xml'}
bnb_url = "https://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm"
bnb_params = {"download": "xml"}
supported_currencies = self._get_supported_currencies()
data = {}
_logger.info("Bulgarian National Bank")

try:
raw_file = requests.get(bnb_url, params=bnb_params)
except IOError:
raise UserError(
_('Web Service does not exist (%s)!') % bnb_url)
except OSError:
raise UserError(_("Web Service does not exist (%s)!") % bnb_url)

dom = etree.fromstring(raw_file.content)
# 16.11.2023
rate_date = dom.xpath("//ROW/TITLE")[0].text[-10:]
rate_date = datetime.datetime.strptime(rate_date, '%d.%m.%Y')
rate_date = datetime.datetime.strptime(rate_date, "%d.%m.%Y")
rate_date = rate_date.strftime("%Y-%m-%d")

gold = dom.xpath("//ROW/GOLD")
for item, curr_name in enumerate(dom.xpath("//ROW/CODE")):
if gold[item].text == '1':
if gold[item].text == "1":
supported_currencies.append(curr_name.text)

curr_data = rate_retrieve(dom)
Expand All @@ -116,7 +151,8 @@ def rate_retrieve(bnb_dom):
data[rate_date][curr] = curr_data[curr]

_logger.debug(
"Rate retrieved : 1 %s = %s %s" % (base_currency, curr_data[curr]['rate_currency'], curr)
"Rate retrieved : 1 %s = %s %s"
% (base_currency, curr_data[curr]["rate_currency"], curr)
)
return data

Expand Down
22 changes: 10 additions & 12 deletions currency_rate_update_bg_customs/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Currency Rate Update Bg Customs',
'summary': """
"name": "Currency Rate Update Bg Customs",
"summary": """
Allows to download statistics currency exchange rates from Customs""",
'version': '16.0.1.0.0',
'license': 'AGPL-3',
'author': 'Rosen Vladimirov,Odoo Community Association (OCA)',
'website': 'https://github.com/rosenvladimirov/l10n-bulgaria',
'depends': [
'currency_rate_update',
],
'data': [
],
'demo': [
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Rosen Vladimirov,Odoo Community Association (OCA)",
"website": "https://github.com/rosenvladimirov/l10n-bulgaria",
"depends": [
"currency_rate_update",
],
"data": [],
"demo": [],
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from datetime import datetime

import requests
from bs4 import BeautifulSoup

from odoo import api, fields, models, _

import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)
Expand All @@ -27,10 +24,40 @@ def _get_supported_currencies(self):
if self.service != "BG_CUSTOMS":
return super()._get_supported_currencies() # pragma: no cover
return [
"AUD", "BRL", "CAD", "CHF", "CNY", "CZK", "DKK", "EUR", "GBP", "BGN",
"HKD", "HRK", "HUF", "IDR", "ILS", "INR", "JPY", "KRW", "LTL", "MXN",
"MYR", "NOK", "NZD", "PHP", "PLN", "RON", "RUB", "SEK", "SGD", "THB",
"TRY", "USD", "ZAR"]
"AUD",
"BRL",
"CAD",
"CHF",
"CNY",
"CZK",
"DKK",
"EUR",
"GBP",
"BGN",
"HKD",
"HRK",
"HUF",
"IDR",
"ILS",
"INR",
"JPY",
"KRW",
"LTL",
"MXN",
"MYR",
"NOK",
"NZD",
"PHP",
"PLN",
"RON",
"RUB",
"SEK",
"SGD",
"THB",
"TRY",
"USD",
"ZAR",
]

@api.model
def _obtain_rates(self, base_currency, currencies, date_from, date_to):
Expand All @@ -47,24 +74,24 @@ def _obtain_rates(self, base_currency, currencies, date_from, date_to):
_logger.info("Customs Agency of Bulgaria")
data = {}
supported_currencies = self._get_supported_currencies()
url = 'https://customs.bg/wps/portal/agency/home/info-business/bank-information/customs-exchange-rates/customs-exchange-rates'
url = "https://customs.bg/wps/portal/agency/home/info-business/bank-information/customs-exchange-rates/customs-exchange-rates"
html = requests.get(url).content
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('table', {'class': 'MsoNormalTable'})
soup = BeautifulSoup(html, "html.parser")
table = soup.find("table", {"class": "MsoNormalTable"})
current_date = fields.Datetime.now().date()
rows = []
header = []
for i, row in enumerate(table.find_all('tr')):
td = [value.text.strip() for value in row.find_all('td')]
for i, row in enumerate(table.find_all("tr")):
td = [value.text.strip() for value in row.find_all("td")]
if i == 0:
header.append(td)
elif i > 2:
rows.append(td)
date_start = header[0][0].split('от')[1].split('до')[0].strip()
date_start = header[0][0].split("от")[1].split("до")[0].strip()
rate_date = current_date.strftime("%Y-%m-%d")
date_end = header[0][0].split('до')[1].strip()
date_start = datetime.strptime(date_start, '%d.%m.%Y г.').date()
date_end = datetime.strptime(date_end, '%d.%m.%Y г.').date()
date_end = header[0][0].split("до")[1].strip()
date_start = datetime.strptime(date_start, "%d.%m.%Y г.").date()
date_end = datetime.strptime(date_end, "%d.%m.%Y г.").date()
curr_data = dict([[x[1], (x[3], x[2])] for x in rows])
if date_start >= current_date <= date_end:
for curr in currencies:
Expand All @@ -76,16 +103,21 @@ def _obtain_rates(self, base_currency, currencies, date_from, date_to):

if not data.get(rate_date):
data[rate_date] = {}
rate = float(curr_data[curr][0].replace(',', '.'))
rate = float(curr_data[curr][0].replace(",", "."))
ratio = float(curr_data[curr][1])
data[rate_date][curr] = {
'rate_currency': (1.0 / rate) * ratio,
'inverted': rate / ratio,
'direct': (1.0 / rate) * ratio
"rate_currency": (1.0 / rate) * ratio,
"inverted": rate / ratio,
"direct": (1.0 / rate) * ratio,
}

_logger.debug(
"Rate retrieved : 1 %s = %s %s" % (base_currency, float(curr_data[curr][0].replace(',', '.')), curr)
"Rate retrieved : 1 %s = %s %s"
% (
base_currency,
float(curr_data[curr][0].replace(",", ".")),
curr,
)
)
return data
return super()._obtain_rates(base_currency, currencies, date_from, date_to)
3 changes: 3 additions & 0 deletions currency_rate_update_bg_customs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
21 changes: 21 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Source: l10n-bulgaria
Maintainer: Rosen Vladimirov <vladimirov.rosen@gmail.com>
Section: net
Priority: optional
Build-Depends: debhelper-compat (= 13),
dh-python,
python3,
rsync,
python3-setuptools
Standards-Version: 4.6.2
Homepage: https://github.com/rosenvladimirov/l10n-bulgaria
Rules-Requires-Root: binary-targets
Vcs-Git: https://github.com/rosenvladimirov/l10n-bulgaria

Package: odoo-l10n-bulgaria
Architecture: all
Depends: python3-transliterate (>=1.10.2-5),
python3-bs4
Provides: odoo (=16.0)
Description: Bulgarian locales for odoo
Bulgaria taxes, chart of account, cyrillic support ...
6 changes: 6 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Contact: Rosen Vladimirov <vladimirov.rosen@gmail.com>

Files: *
Copyright: Copyright (C) 2025 Rosen Vladimirov
License: LGPL-3+
1 change: 1 addition & 0 deletions debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.md /usr/share/doc/odoo-l10n-bulgaria
Loading

0 comments on commit 8365a7f

Please sign in to comment.