# -*- 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. from trytond.tests.test_tryton import with_transaction from trytond.pool import Pool from datetime import date from decimal import Decimal class CurrencyTestCase(object): """ test currency """ @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() # TODO: check update of cashbook if currency changes currency, = Currency.search([('name', '=', 'usd')]) 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], { 'rates': [ ('write', [currency.rates[0].id], { 'rate': Decimal('1.06'), })], }]) self.assertEqual(len(currency.rates), 1) Currency.write(*[ [currency], { 'rates': [('delete', [currency.rates[0].id])], }]) # end CurrencyTestCase