Trade Finance + Other changes
This commit is contained in:
117
modules/trade_finance/tests/test_module.py
Normal file
117
modules/trade_finance/tests/test_module.py
Normal file
@@ -0,0 +1,117 @@
|
||||
# This file is part of Tradon. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.currency.tests import create_currency
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class TradeFinanceTestCase(ModuleTestCase):
|
||||
'Test Trade Finance module'
|
||||
module = 'trade_finance'
|
||||
|
||||
def create_facility(self):
|
||||
pool = Pool()
|
||||
Bank = pool.get('bank')
|
||||
Facility = pool.get('trade_finance.facility')
|
||||
Party = pool.get('party.party')
|
||||
|
||||
currency = create_currency('USD')
|
||||
party = Party(name='Test Bank')
|
||||
party.save()
|
||||
bank = Bank(party=party)
|
||||
bank.save()
|
||||
facility = Facility(
|
||||
name='Test Facility',
|
||||
tfe=bank,
|
||||
currency=currency,
|
||||
commitment_status='committed',
|
||||
date_from=date(2026, 1, 1),
|
||||
date_to=date(2026, 12, 31))
|
||||
facility.save()
|
||||
return facility, currency
|
||||
|
||||
@with_transaction()
|
||||
def test_sublimit_inherits_currency_and_dates(self):
|
||||
'Test sublimit inherits currency and dates from parent'
|
||||
pool = Pool()
|
||||
Limit = pool.get('trade_finance.facility_limit')
|
||||
|
||||
facility, currency = self.create_facility()
|
||||
root, = Limit.create([{
|
||||
'facility': facility.id,
|
||||
'name': 'Global limit',
|
||||
'currency': currency.id,
|
||||
'amount': Decimal('100.00'),
|
||||
'date_from': date(2026, 1, 1),
|
||||
'date_to': date(2026, 12, 31),
|
||||
}])
|
||||
child, = Limit.create([{
|
||||
'parent': root.id,
|
||||
'name': 'Trading limit',
|
||||
'amount': Decimal('50.00'),
|
||||
}])
|
||||
|
||||
self.assertEqual(child.facility, facility)
|
||||
self.assertEqual(child.currency, currency)
|
||||
self.assertEqual(child.date_from, root.date_from)
|
||||
self.assertEqual(child.date_to, root.date_to)
|
||||
|
||||
@with_transaction()
|
||||
def test_sublimit_dates_must_stay_within_parent(self):
|
||||
'Test sublimit dates stay within parent dates'
|
||||
pool = Pool()
|
||||
Limit = pool.get('trade_finance.facility_limit')
|
||||
|
||||
facility, currency = self.create_facility()
|
||||
root, = Limit.create([{
|
||||
'facility': facility.id,
|
||||
'name': 'Global limit',
|
||||
'currency': currency.id,
|
||||
'amount': Decimal('100.00'),
|
||||
'date_from': date(2026, 1, 1),
|
||||
'date_to': date(2026, 12, 31),
|
||||
}])
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
Limit.create([{
|
||||
'parent': root.id,
|
||||
'name': 'Late limit',
|
||||
'amount': Decimal('50.00'),
|
||||
'date_from': date(2026, 1, 1),
|
||||
'date_to': date(2027, 1, 1),
|
||||
}])
|
||||
|
||||
@with_transaction()
|
||||
def test_currency_change_cascades_to_sublimits(self):
|
||||
'Test root currency changes cascade to sublimits'
|
||||
pool = Pool()
|
||||
Limit = pool.get('trade_finance.facility_limit')
|
||||
|
||||
facility, currency = self.create_facility()
|
||||
other_currency = create_currency('EUR')
|
||||
root, = Limit.create([{
|
||||
'facility': facility.id,
|
||||
'name': 'Global limit',
|
||||
'currency': currency.id,
|
||||
'amount': Decimal('100.00'),
|
||||
'date_from': date(2026, 1, 1),
|
||||
'date_to': date(2026, 12, 31),
|
||||
}])
|
||||
child, = Limit.create([{
|
||||
'parent': root.id,
|
||||
'name': 'Trading limit',
|
||||
'amount': Decimal('50.00'),
|
||||
}])
|
||||
|
||||
Limit.write([root], {'currency': other_currency.id})
|
||||
child = Limit(child.id)
|
||||
|
||||
self.assertEqual(child.currency, other_currency)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
Reference in New Issue
Block a user