cashbook/tests/currency.py

60 lines
1.7 KiB
Python
Raw Normal View History

2023-02-26 21:49:21 +00:00
# -*- coding: utf-8 -*-
# This file is part of the cashbook-module from m-ds for Tryton.
# The COPYRIGHT file at the top level of this repository contains the
# full copyright notices and license terms.
2023-06-02 19:08:56 +00:00
from trytond.tests.test_tryton import with_transaction
2023-02-26 21:49:21 +00:00
from trytond.pool import Pool
from datetime import date
from decimal import Decimal
2023-06-02 19:08:56 +00:00
class CurrencyTestCase(object):
""" test currency
"""
2023-02-26 21:49:21 +00:00
@with_transaction()
def test_currency_update_cache(self):
""" add/update/del rate of currency, check cache
"""
pool = Pool()
Currency = pool.get('currency.currency')
CurrencyRate = pool.get('currency.currency.rate')
self.prep_config()
self.prep_company()
2023-12-23 09:36:58 +00:00
# TODO: check update of cashbook if currency changes
2023-02-26 21:49:21 +00:00
2023-12-23 09:36:58 +00:00
currency, = Currency.search([('name', '=', 'usd')])
2023-02-26 21:49:21 +00:00
CurrencyRate.delete(currency.rates)
self.assertEqual(len(currency.rates), 0)
# add rate
Currency.write(*[
[currency],
{
'rates': [('create', [{
'date': date(2022, 5, 1),
'rate': Decimal('1.05'),
}])],
}])
self.assertEqual(len(currency.rates), 1)
Currency.write(*[
[currency],
{
2023-06-02 18:40:12 +00:00
'rates': [
('write', [currency.rates[0].id], {
2023-02-26 21:49:21 +00:00
'rate': Decimal('1.06'),
})],
}])
self.assertEqual(len(currency.rates), 1)
Currency.write(*[
[currency],
{
'rates': [('delete', [currency.rates[0].id])],
}])
# end CurrencyTestCase