Files
account_debit_note/tests/test_module.py
T

59 lines
1.7 KiB
Python

from decimal import Decimal
import unittest
from trytond.exceptions import UserError
from trytond.modules.account_debit_note.invoice import Invoice
from trytond.tests.test_tryton import ModuleTestCase
class MockInvoice:
untaxed_amount = Decimal('100.00')
total_amount = Decimal('118.00')
class AccountDebitNoteTestCase(ModuleTestCase):
'Test Account Debit Note module'
module = 'account_debit_note'
class AccountDebitNoteLogicTestCase(unittest.TestCase):
def test_full_factor(self):
self.assertEqual(
Invoice._debit_compute_factor(
MockInvoice(), 'full', None, None, 'total'),
Decimal('1'))
def test_percent_factor_supports_user_and_internal_values(self):
self.assertEqual(
Invoice._debit_compute_factor(
MockInvoice(), 'percent', Decimal('20'), None, 'total'),
Decimal('0.2'))
self.assertEqual(
Invoice._debit_compute_factor(
MockInvoice(), 'percent', Decimal('0.20'), None, 'total'),
Decimal('0.20'))
def test_amount_factor_uses_selected_basis(self):
self.assertEqual(
Invoice._debit_compute_factor(
MockInvoice(), 'amount', None, Decimal('59'), 'total'),
Decimal('0.5'))
self.assertEqual(
Invoice._debit_compute_factor(
MockInvoice(), 'amount', None, Decimal('25'), 'untaxed'),
Decimal('0.25'))
def test_invalid_percent_is_rejected(self):
with self.assertRaises(UserError):
Invoice._debit_compute_factor(
MockInvoice(), 'percent', Decimal('101'), None, 'total')
del ModuleTestCase
def suite():
from trytond.tests.test_tryton import suite
return suite()