Files
tryton/modules/account_credit_limit/tests/test_module.py
T

84 lines
3.3 KiB
Python
Raw Normal View History

2014-12-02 12:54:33 +01:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2014-03-17 23:10:33 +01:00
from decimal import Decimal
2021-12-11 17:58:41 +01:00
from trytond.exceptions import UserError, UserWarning
2016-02-06 19:11:46 +01:00
from trytond.modules.account.tests import create_chart, get_fiscalyear
2021-12-11 17:58:41 +01:00
from trytond.modules.company.tests import (
CompanyTestMixin, create_company, set_company)
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
2016-02-06 19:11:46 +01:00
2014-03-17 23:10:33 +01:00
class AccountCreditLimitTestCase(CompanyTestMixin, ModuleTestCase):
2014-03-17 23:10:33 +01:00
'Test AccountCreditLimit module'
2015-01-27 18:12:49 +01:00
module = 'account_credit_limit'
2019-01-17 17:22:22 +01:00
extras = ['account_dunning']
2014-03-17 23:10:33 +01:00
2016-02-06 19:11:46 +01:00
@with_transaction()
def test_check_credit_limit(self):
2014-03-17 23:10:33 +01:00
'Test check_credit_limit'
2016-02-06 19:11:46 +01:00
pool = Pool()
Account = pool.get('account.account')
Move = pool.get('account.move')
Journal = pool.get('account.journal')
Party = pool.get('party.party')
company = create_company()
with set_company(company):
create_chart(company)
fiscalyear = get_fiscalyear(company)
fiscalyear.save()
fiscalyear.create_period([fiscalyear])
period = fiscalyear.periods[0]
receivable, = Account.search([
2019-03-24 18:00:01 +01:00
('type.receivable', '=', True),
2014-03-17 23:10:33 +01:00
])
2016-02-06 19:11:46 +01:00
revenue, = Account.search([
2019-03-24 18:00:01 +01:00
('type.revenue', '=', True),
2014-03-17 23:10:33 +01:00
])
2016-02-06 19:11:46 +01:00
journal, = Journal.search([], limit=1)
party, = Party.create([{
2014-03-17 23:10:33 +01:00
'name': 'Party',
}])
2016-02-06 19:11:46 +01:00
Move.create([{
2014-03-17 23:10:33 +01:00
'journal': journal.id,
'period': period.id,
'date': period.start_date,
'lines': [
('create', [{
'debit': Decimal(100),
'account': receivable.id,
'party': party.id,
}, {
'credit': Decimal(100),
'account': revenue.id,
}]),
],
}])
self.assertEqual(party.credit_amount, Decimal(100))
self.assertEqual(party.credit_limit_amount, None)
party.check_credit_limit(Decimal(0))
party.check_credit_limit(Decimal(0), 'test')
party.check_credit_limit(Decimal(100))
party.check_credit_limit(Decimal(100), 'test')
party.credit_limit_amount = Decimal(0)
party.save()
self.assertRaises(UserError, party.check_credit_limit,
Decimal(0))
self.assertRaises(UserWarning, party.check_credit_limit,
Decimal(0), 'test')
party.credit_limit_amount = Decimal(200)
party.save()
party.check_credit_limit(Decimal(0))
party.check_credit_limit(Decimal(0), 'test')
self.assertRaises(UserError, party.check_credit_limit,
Decimal(150))
self.assertRaises(UserWarning, party.check_credit_limit,
Decimal(150), 'test')
del ModuleTestCase