splitbuchungen + test
This commit is contained in:
parent
bdbc9dc27f
commit
aefb5cde51
9 changed files with 618 additions and 124 deletions
|
@ -7,6 +7,7 @@ import unittest
|
|||
from trytond.modules.cashbook.tests.test_type import TypeTestCase
|
||||
from trytond.modules.cashbook.tests.test_book import BookTestCase
|
||||
from trytond.modules.cashbook.tests.test_line import LineTestCase
|
||||
from trytond.modules.cashbook.tests.test_splitline import SplitLineTestCase
|
||||
from trytond.modules.cashbook.tests.test_config import ConfigTestCase
|
||||
from trytond.modules.cashbook.tests.test_category import CategoryTestCase
|
||||
from trytond.modules.cashbook.tests.test_reconciliation import ReconTestCase
|
||||
|
@ -19,6 +20,7 @@ class CashbookTestCase(\
|
|||
CategoryTestCase,\
|
||||
ConfigTestCase,\
|
||||
LineTestCase,
|
||||
SplitLineTestCase,
|
||||
BookTestCase,
|
||||
TypeTestCase,
|
||||
):
|
||||
|
|
109
tests/test_splitline.py
Normal file
109
tests/test_splitline.py
Normal file
|
@ -0,0 +1,109 @@
|
|||
# -*- 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 ModuleTestCase, with_transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from datetime import date
|
||||
from unittest.mock import MagicMock
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class SplitLineTestCase(ModuleTestCase):
|
||||
'Test split line module'
|
||||
module = 'cashbook'
|
||||
|
||||
@with_transaction()
|
||||
def test_splitline_check_clear_by_bookingtype(self):
|
||||
""" add book, line, category, set line to 'in',
|
||||
then update to 'spin'
|
||||
"""
|
||||
pool = Pool()
|
||||
Book = pool.get('cashbook.book')
|
||||
Lines = pool.get('cashbook.line')
|
||||
|
||||
types = self.prep_type()
|
||||
category1 = self.prep_category(cattype='in')
|
||||
category2 = self.prep_category(name='Cat2', cattype='in')
|
||||
company = self.prep_company()
|
||||
party = self.prep_party()
|
||||
book, = Book.create([{
|
||||
'name': 'Book 1',
|
||||
'btype': types.id,
|
||||
'company': company.id,
|
||||
'currency': company.currency.id,
|
||||
'number_sequ': self.prep_sequence().id,
|
||||
'start_date': date(2022, 5, 1),
|
||||
'lines': [('create', [{
|
||||
'date': date(2022, 5, 1),
|
||||
'description': 'Text 1',
|
||||
'category': category1.id,
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('1.0'),
|
||||
'party': party.id,
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(len(book.lines), 1)
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|1.00 usd|Text 1 [Cat1]')
|
||||
self.assertEqual(book.lines[0].amount, Decimal('1.0'))
|
||||
self.assertEqual(book.lines[0].category.rec_name, 'Cat1')
|
||||
|
||||
Lines.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'bookingtype': 'spin',
|
||||
'splitlines': [('create', [{
|
||||
'amount': Decimal('5.0'),
|
||||
'category': category1.id,
|
||||
'description': 'line 1'
|
||||
}, {
|
||||
'amount': Decimal('2.0'),
|
||||
'category': category2.id,
|
||||
'description': 'line 2',
|
||||
}])],
|
||||
}])
|
||||
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev/Sp|7.00 usd|Text 1 [-]')
|
||||
self.assertEqual(book.lines[0].amount, Decimal('7.0'))
|
||||
self.assertEqual(book.lines[0].category, None)
|
||||
|
||||
self.assertEqual(len(book.lines[0].splitlines), 2)
|
||||
self.assertEqual(book.lines[0].splitlines[0].amount, Decimal('5.0'))
|
||||
self.assertEqual(book.lines[0].splitlines[0].category.rec_name, 'Cat1')
|
||||
self.assertEqual(book.lines[0].splitlines[0].description, 'line 1')
|
||||
self.assertEqual(book.lines[0].splitlines[0].rec_name, 'Rev/Sp|5.00 usd|line 1 [Cat1]')
|
||||
|
||||
self.assertEqual(book.lines[0].splitlines[1].amount, Decimal('2.0'))
|
||||
self.assertEqual(book.lines[0].splitlines[1].category.rec_name, 'Cat2')
|
||||
self.assertEqual(book.lines[0].splitlines[1].description, 'line 2')
|
||||
self.assertEqual(book.lines[0].splitlines[1].rec_name, 'Rev/Sp|2.00 usd|line 2 [Cat2]')
|
||||
|
||||
Lines.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'splitlines': [('write',
|
||||
[book.lines[0].splitlines[0]],
|
||||
{
|
||||
'amount': Decimal('3.5'),
|
||||
})],
|
||||
}])
|
||||
self.assertEqual(book.lines[0].splitlines[0].amount, Decimal('3.5'))
|
||||
self.assertEqual(book.lines[0].splitlines[1].amount, Decimal('2.0'))
|
||||
self.assertEqual(book.lines[0].amount, Decimal('5.5'))
|
||||
|
||||
Lines.write(*[
|
||||
[book.lines[0]],
|
||||
{
|
||||
'bookingtype': 'in',
|
||||
'amount': Decimal('7.5'),
|
||||
'category': category2.id,
|
||||
}])
|
||||
self.assertEqual(book.lines[0].rec_name, '05/01/2022|Rev|7.50 usd|Text 1 [Cat2]')
|
||||
self.assertEqual(book.lines[0].category.rec_name, 'Cat2')
|
||||
self.assertEqual(len(book.lines[0].splitlines), 0)
|
||||
|
||||
# end SplitLineTestCase
|
Loading…
Add table
Add a link
Reference in a new issue