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

256 lines
11 KiB
Python
Raw Normal View History

2014-12-02 12:54:39 +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.
import datetime
from decimal import Decimal
2016-02-06 19:11:56 +01:00
from trytond.modules.account_invoice.exceptions import (
PaymentTermValidationError)
from trytond.modules.company.tests import (
2021-12-11 17:58:41 +01:00
CompanyTestMixin, PartyCompanyCheckEraseMixin)
2016-02-06 19:11:56 +01:00
from trytond.modules.currency.tests import create_currency
2021-12-11 17:58:41 +01:00
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
2020-12-05 11:53:48 +01:00
2016-02-06 19:11:56 +01:00
def set_invoice_sequences(fiscalyear):
pool = Pool()
Sequence = pool.get('ir.sequence.strict')
2021-03-11 23:00:09 +01:00
SequenceType = pool.get('ir.sequence.type')
2017-03-30 09:45:15 +02:00
InvoiceSequence = pool.get('account.fiscalyear.invoice_sequence')
2016-02-06 19:11:56 +01:00
2021-03-11 23:00:09 +01:00
sequence_type, = SequenceType.search([
('name', '=', "Invoice"),
], limit=1)
sequence = Sequence(name=fiscalyear.name, sequence_type=sequence_type)
2016-02-06 19:11:56 +01:00
sequence.company = fiscalyear.company
sequence.save()
2017-03-30 09:45:15 +02:00
fiscalyear.invoice_sequences = []
invoice_sequence = InvoiceSequence()
invoice_sequence.fiscalyear = fiscalyear
invoice_sequence.in_invoice_sequence = sequence
invoice_sequence.in_credit_note_sequence = sequence
invoice_sequence.out_invoice_sequence = sequence
invoice_sequence.out_credit_note_sequence = sequence
invoice_sequence.save()
2016-02-06 19:11:56 +01:00
return fiscalyear
2009-06-28 14:12:43 +02:00
class AccountInvoiceTestCase(
PartyCompanyCheckEraseMixin, CompanyTestMixin, ModuleTestCase):
2014-01-12 19:59:22 +01:00
'Test AccountInvoice module'
2015-01-27 18:12:55 +01:00
module = 'account_invoice'
2009-06-28 14:12:43 +02:00
2016-02-06 19:11:56 +01:00
@with_transaction()
def test_payment_term(self):
2014-01-12 19:59:22 +01:00
'Test payment_term'
2016-02-06 19:11:56 +01:00
pool = Pool()
PaymentTerm = pool.get('account.invoice.payment_term')
2016-02-06 19:11:56 +01:00
cu1 = create_currency('cu1')
term, = PaymentTerm.create([{
'name': '30 days, 1 month, 1 month + 15 days',
'lines': [
('create', [{
'sequence': 0,
'type': 'percent',
'divisor': 4,
'ratio': Decimal('.25'),
'relativedeltas': [('create', [{
'days': 30,
},
]),
],
}, {
'sequence': 1,
'type': 'percent_on_total',
'divisor': 4,
'ratio': Decimal('.25'),
'relativedeltas': [('create', [{
'months': 1,
},
]),
],
}, {
'sequence': 2,
'type': 'fixed',
'amount': Decimal('396.84'),
'currency': cu1.id,
'relativedeltas': [('create', [{
'months': 1,
'days': 30,
},
]),
],
}, {
'sequence': 3,
'type': 'remainder',
'relativedeltas': [('create', [{
'months': 2,
'days': 30,
'day': 15,
},
]),
],
}])]
}])
terms = term.compute(Decimal('1587.35'), cu1,
date=datetime.date(2011, 10, 1))
self.assertEqual(terms, [
(datetime.date(2011, 10, 31), Decimal('396.84')),
2016-02-28 20:51:18 +01:00
(datetime.date(2011, 11, 1), Decimal('396.84')),
(datetime.date(2011, 12, 1), Decimal('396.84')),
(datetime.date(2012, 1, 14), Decimal('396.83')),
2016-02-06 19:11:56 +01:00
])
@with_transaction()
def test_payment_term_with_repeating_decimal(self):
"Test payment_term with repeating decimal"
pool = Pool()
PaymentTerm = pool.get('account.invoice.payment_term')
PaymentTerm.create([{
'name': "Repeating Decimal",
'lines': [
('create', [{
'type': 'percent',
'divisor': Decimal(3),
'ratio': Decimal('0.3333333333'),
}, {
'type': 'remainder',
}]),
],
}])
@with_transaction()
def test_payment_term_with_invalid_ratio_divisor(self):
"Test payment_term with invalid ratio and divisor"
pool = Pool()
PaymentTerm = pool.get('account.invoice.payment_term')
with self.assertRaises(PaymentTermValidationError):
PaymentTerm.create([{
'name': "Invalid ratio and divisor",
'lines': [
('create', [{
'type': 'percent',
'divisor': Decimal(2),
'ratio': Decimal('0.4'),
}, {
'type': 'remainder',
}]),
],
}])
2016-05-25 12:59:48 +02:00
@with_transaction()
def test_payment_term_with_empty_value(self):
'Test payment_term with empty'
pool = Pool()
PaymentTerm = pool.get('account.invoice.payment_term')
cu1 = create_currency('cu1')
remainder_term, percent_term = PaymentTerm.create([{
'name': 'Remainder',
'lines': [
('create', [{'type': 'remainder',
'relativedeltas': [('create', [{
'months': 1,
},
]),
],
}])]
}, {
'name': '25% tomorrow, remainder un month later ',
'lines': [
('create', [{'type': 'percent',
'divisor': 4,
'ratio': Decimal('.25'),
'relativedeltas': [('create', [{
'days': 1,
},
]),
],
}, {'type': 'remainder',
'relativedeltas': [('create', [{
'months': 1,
},
]),
],
}])]
}])
terms = remainder_term.compute(Decimal('0.0'), cu1,
2018-06-26 19:11:42 +02:00
date=datetime.date(2016, 5, 17))
2016-05-25 12:59:48 +02:00
self.assertEqual(terms, [
2018-06-26 19:11:42 +02:00
(datetime.date(2016, 5, 17), Decimal('0.0')),
2016-05-25 12:59:48 +02:00
])
terms = percent_term.compute(Decimal('0.0'), cu1,
2018-06-26 19:11:42 +02:00
date=datetime.date(2016, 5, 17))
2016-05-25 12:59:48 +02:00
self.assertEqual(terms, [
2018-06-26 19:11:42 +02:00
(datetime.date(2016, 5, 17), Decimal('0.0')),
2016-05-25 12:59:48 +02:00
])
@with_transaction()
def test_negative_amount(self):
'Test payment term with negative amount'
pool = Pool()
PaymentTerm = pool.get('account.invoice.payment_term')
cu1 = create_currency('cu1')
term, = PaymentTerm.create([{
'name': '30 days, 1 month, 1 month + 15 days',
'lines': [
('create', [{
'sequence': 0,
'type': 'percent',
'divisor': 4,
'ratio': Decimal('.25'),
'relativedeltas': [('create', [{
'days': 30,
},
]),
],
}, {
'sequence': 1,
'type': 'percent_on_total',
'divisor': 4,
'ratio': Decimal('.25'),
'relativedeltas': [('create', [{
'months': 1,
},
]),
],
}, {
'sequence': 2,
'type': 'fixed',
'amount': Decimal('4.0'),
'currency': cu1.id,
'relativedeltas': [('create', [{
'months': 1,
'days': 30,
},
]),
],
}, {
'sequence': 3,
'type': 'remainder',
'relativedeltas': [('create', [{
'months': 2,
'days': 30,
'day': 15,
},
]),
],
}])]
}])
terms = term.compute(Decimal('-10.00'), cu1,
date=datetime.date(2011, 10, 1))
self.assertListEqual(terms, [
(datetime.date(2011, 10, 31), Decimal('-2.5')),
(datetime.date(2011, 11, 1), Decimal('-2.5')),
(datetime.date(2011, 12, 1), Decimal('-4.0')),
(datetime.date(2012, 1, 14), Decimal('-1.0')),
])
del ModuleTestCase