first commit
This commit is contained in:
2
modules/currency_ro/__init__.py
Normal file
2
modules/currency_ro/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
BIN
modules/currency_ro/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
modules/currency_ro/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/currency_ro/__pycache__/currency.cpython-311.pyc
Normal file
BIN
modules/currency_ro/__pycache__/currency.cpython-311.pyc
Normal file
Binary file not shown.
60
modules/currency_ro/currency.py
Normal file
60
modules/currency_ro/currency.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import datetime as dt
|
||||
from decimal import Decimal
|
||||
|
||||
import requests
|
||||
from lxml import etree
|
||||
|
||||
import trytond.config as config
|
||||
from trytond.modules.currency.currency import CronFetchError
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval, If
|
||||
|
||||
URL_10DAYS = 'https://bnr.ro/nbrfxrates10days.xml'
|
||||
URL_YEAR = 'https://bnr.ro/files/xml/years/nbrfxrates%s.xml'
|
||||
|
||||
|
||||
class Cron(metaclass=PoolMeta):
|
||||
__name__ = 'currency.cron'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.source.selection.append(('bnr_ro', "Romanian National Bank"))
|
||||
cls.currency.domain = [
|
||||
cls.currency.domain or [],
|
||||
If(Eval('source') == 'bnr_ro',
|
||||
('code', '=', 'RON'),
|
||||
()),
|
||||
]
|
||||
|
||||
def fetch_bnr_ro(self, date):
|
||||
if (dt.date.today() - date).days < 10:
|
||||
url = URL_10DAYS
|
||||
else:
|
||||
url = URL_YEAR % date.year
|
||||
timeout = config.getfloat(
|
||||
'currency_ro', 'requests_timeout', default=300)
|
||||
try:
|
||||
response = requests.get(url, timeout=timeout)
|
||||
except requests.HTTPError as e:
|
||||
raise CronFetchError() from e
|
||||
tree = etree.fromstring(response.content)
|
||||
|
||||
origin, = tree.xpath(
|
||||
'//x:Body/x:OrigCurrency',
|
||||
namespaces={'x': 'http://www.bnr.ro/xsd'})
|
||||
assert origin.text == self.currency.code
|
||||
|
||||
cubes = tree.xpath(
|
||||
'//x:Body/x:Cube[@date="%s"]' % date.isoformat(),
|
||||
namespaces={'x': 'http://www.bnr.ro/xsd'})
|
||||
if cubes:
|
||||
cube, = cubes
|
||||
return {
|
||||
r.get('currency'): (
|
||||
Decimal(r.get('multiplier', 1)) / Decimal(r.text))
|
||||
for r in cube.iter('{*}Rate')}
|
||||
else:
|
||||
return {}
|
||||
7
modules/currency_ro/locale/bg.po
Normal file
7
modules/currency_ro/locale/bg.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/ca.po
Normal file
7
modules/currency_ro/locale/ca.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banc Nacional de Romania"
|
||||
7
modules/currency_ro/locale/cs.po
Normal file
7
modules/currency_ro/locale/cs.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/de.po
Normal file
7
modules/currency_ro/locale/de.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Rumänische Nationalbank"
|
||||
7
modules/currency_ro/locale/es.po
Normal file
7
modules/currency_ro/locale/es.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banco Nacional de Rumanía"
|
||||
7
modules/currency_ro/locale/es_419.po
Normal file
7
modules/currency_ro/locale/es_419.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/et.po
Normal file
7
modules/currency_ro/locale/et.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/fa.po
Normal file
7
modules/currency_ro/locale/fa.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/fi.po
Normal file
7
modules/currency_ro/locale/fi.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/fr.po
Normal file
7
modules/currency_ro/locale/fr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banque nationale roumaine"
|
||||
7
modules/currency_ro/locale/hu.po
Normal file
7
modules/currency_ro/locale/hu.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/id.po
Normal file
7
modules/currency_ro/locale/id.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/it.po
Normal file
7
modules/currency_ro/locale/it.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banca nazionale Rumena"
|
||||
7
modules/currency_ro/locale/lo.po
Normal file
7
modules/currency_ro/locale/lo.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/lt.po
Normal file
7
modules/currency_ro/locale/lt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/nl.po
Normal file
7
modules/currency_ro/locale/nl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Roemeense Nationale Bank"
|
||||
7
modules/currency_ro/locale/pl.po
Normal file
7
modules/currency_ro/locale/pl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
8
modules/currency_ro/locale/pt.po
Normal file
8
modules/currency_ro/locale/pt.po
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banco Nacional Romeno"
|
||||
7
modules/currency_ro/locale/ro.po
Normal file
7
modules/currency_ro/locale/ro.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr "Banca Naţionala a României"
|
||||
7
modules/currency_ro/locale/ru.po
Normal file
7
modules/currency_ro/locale/ru.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/sl.po
Normal file
7
modules/currency_ro/locale/sl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/tr.po
Normal file
7
modules/currency_ro/locale/tr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/uk.po
Normal file
7
modules/currency_ro/locale/uk.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
7
modules/currency_ro/locale/zh_CN.po
Normal file
7
modules/currency_ro/locale/zh_CN.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:currency.cron,source:"
|
||||
msgid "Romanian National Bank"
|
||||
msgstr ""
|
||||
2
modules/currency_ro/tests/__init__.py
Normal file
2
modules/currency_ro/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
BIN
modules/currency_ro/tests/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
modules/currency_ro/tests/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
56
modules/currency_ro/tests/scenario_currency_ro.rst
Normal file
56
modules/currency_ro/tests/scenario_currency_ro.rst
Normal file
@@ -0,0 +1,56 @@
|
||||
====================
|
||||
Currency RO Scenario
|
||||
====================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> previous_month = today - dt.timedelta(days=30)
|
||||
>>> before_previous_month = previous_month - dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('currency_ro')
|
||||
|
||||
Import models::
|
||||
|
||||
>>> Currency = Model.get('currency.currency')
|
||||
>>> Cron = Model.get('currency.cron')
|
||||
|
||||
Create some currencies::
|
||||
|
||||
>>> eur = Currency(name="Euro", code='EUR', symbol="€")
|
||||
>>> eur.save()
|
||||
>>> ron = Currency(name="Romanian Leu", code='RON', symbol="L")
|
||||
>>> ron.save()
|
||||
|
||||
Setup cron::
|
||||
|
||||
>>> cron = Cron()
|
||||
>>> cron.source = 'bnr_ro'
|
||||
>>> cron.frequency = 'daily'
|
||||
>>> cron.day = None
|
||||
>>> cron.currency = ron
|
||||
>>> cron.currencies.append(Currency(eur.id))
|
||||
>>> cron.last_update = before_previous_month
|
||||
>>> cron.save()
|
||||
|
||||
Run update::
|
||||
|
||||
>>> cron.click('run')
|
||||
>>> cron.last_update >= previous_month
|
||||
True
|
||||
|
||||
>>> ron.reload()
|
||||
>>> rate = [r for r in ron.rates if r.date < today][0]
|
||||
>>> rate.rate
|
||||
Decimal('1.000000')
|
||||
>>> eur.reload()
|
||||
>>> rate = [r for r in eur.rates if r.date < today][0]
|
||||
>>> bool(rate.rate)
|
||||
True
|
||||
12
modules/currency_ro/tests/test_module.py
Normal file
12
modules/currency_ro/tests/test_module.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class CurrencyRoTestCase(ModuleTestCase):
|
||||
'Test Currency Ro module'
|
||||
module = 'currency_ro'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
10
modules/currency_ro/tests/test_scenario.py
Normal file
10
modules/currency_ro/tests/test_scenario.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import TEST_NETWORK, load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
if not TEST_NETWORK:
|
||||
kwargs.setdefault('skips', set()).add('scenario_currency_ro.rst')
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
9
modules/currency_ro/tryton.cfg
Normal file
9
modules/currency_ro/tryton.cfg
Normal file
@@ -0,0 +1,9 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
currency
|
||||
ir
|
||||
|
||||
[register]
|
||||
model:
|
||||
currency.Cron
|
||||
Reference in New Issue
Block a user