cashbook_investment/tests/test_book.py
2022-12-22 00:32:26 +01:00

191 lines
6.2 KiB
Python

# -*- 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 trytond.modules.cashbook.tests import CashbookTestCase
from trytond.modules.investment.tests import InvestmentTestCase
from datetime import date
from decimal import Decimal
class CbInvTestCase(CashbookTestCase, InvestmentTestCase):
'Test cashbook-investment module'
module = 'cashbook_investment'
@with_transaction()
def test_assetbook_create(self):
""" create cashbook, set 'btype' to asset
"""
pool = Pool()
Book = pool.get('cashbook.book')
BType = pool.get('cashbook.type')
types = self.prep_type()
company = self.prep_company()
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
}])
BType.write(*[
[types],
{
'feature': 'asset',
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
self.assertEqual(book.btype.rec_name, 'CAS - Cash')
self.assertEqual(book.state, 'open')
self.assertEqual(book.state_string, 'Open')
self.assertEqual(book.feature, 'asset')
self.assertEqual(book.quantity_digits, 4)
@with_transaction()
def test_assetbook_create_line(self):
""" create cashbook, add line
"""
pool = Pool()
Book = pool.get('cashbook.book')
BType = pool.get('cashbook.type')
types = self.prep_type()
BType.write(*[
[types],
{
'feature': 'asset',
}])
category = self.prep_category(cattype='in')
company = self.prep_company()
party = self.prep_party()
asset = self.prep_asset_item(
company=company,
product = self.prep_asset_product(name='Product 1'))
self.assertEqual(asset.symbol, 'usd/u')
book, = Book.create([{
'start_date': date(2022, 4, 1),
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'asset': asset.id,
'quantity_uom': asset.uom.id,
'quantity_digits': 3,
'lines': [('create', [{
'date': date(2022, 5, 1),
'description': 'Text 1',
'category': category.id,
'bookingtype': 'in',
'amount': Decimal('2.5'),
'party': party.id,
'quantity': Decimal('1.453'),
}],
)],
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.rec_name, 'Book 1 | 2.50 usd | Open')
self.assertEqual(book.state, 'open')
self.assertEqual(book.feature, 'asset')
self.assertEqual(book.quantity_digits, 3)
self.assertEqual(book.balance_all, Decimal('2.5'))
self.assertEqual(len(book.lines), 1)
self.assertEqual(book.lines[0].amount, Decimal('2.5'))
self.assertEqual(book.lines[0].quantity, Decimal('1.453'))
self.assertEqual(book.lines[0].quantity_digits, 3)
self.assertEqual(book.lines[0].quantity_symbol, 'u')
@with_transaction()
def test_assetbook_book_uom(self):
""" check default auf uom
"""
pool = Pool()
Book = pool.get('cashbook.book')
BType = pool.get('cashbook.type')
company = self.prep_company()
types = self.prep_type()
BType.write(*[
[types],
{
'feature': 'asset',
'name': 'Asset',
'short': 'A',
}])
asset = self.prep_asset_item(
company=company,
product = self.prep_asset_product(name='Product 1'))
self.assertEqual(asset.symbol, 'usd/u')
book = Book(
asset = asset,
quantity_uom = None,
)
self.assertEqual(book.quantity_uom, None)
book.on_change_asset()
self.assertEqual(book.quantity_uom.rec_name, 'Unit')
@with_transaction()
def test_assetbook_book_with_asset(self):
""" create cashbook, set 'btype' to asset
"""
pool = Pool()
Book = pool.get('cashbook.book')
BType = pool.get('cashbook.type')
company = self.prep_company()
types = self.prep_type()
BType.write(*[
[types],
{
'feature': 'asset',
'name': 'Asset',
'short': 'A',
}])
asset = self.prep_asset_item(
company=company,
product = self.prep_asset_product(name='Product 1'))
self.assertEqual(asset.symbol, 'usd/u')
book, = Book.create([{
'name': 'Book 1',
'btype': types.id,
'company': company.id,
'currency': company.currency.id,
'number_sequ': self.prep_sequence().id,
'asset': asset.id,
'quantity_uom': asset.uom.id,
}])
self.assertEqual(book.name, 'Book 1')
self.assertEqual(book.rec_name, 'Book 1 | 0.00 usd | Open')
self.assertEqual(book.btype.rec_name, 'A - Asset')
self.assertEqual(book.state, 'open')
self.assertEqual(book.feature, 'asset')
self.assertEqual(book.asset.rec_name, 'Product 1 | - usd/u | -')
self.assertEqual(book.quantity_uom.rec_name, 'Unit')
self.assertRaisesRegex(UserError,
'A value is required for field "Asset" in "Cashbook".',
Book.write,
*[
[book],
{
'asset': None,
}
])
# end CbInvTestCase