# -*- 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 datetime import date from decimal import Decimal class ReportTestCase(CashbookTestCase): 'Test cashbook book report module' module = 'cashbook_report' def prep_report_3books(self): """ create 3x cashbooks, add bookings, """ pool = Pool() Book = pool.get('cashbook.book') types = self.prep_type() company = self.prep_company() sequ_id = self.prep_sequence().id category = self.prep_category(cattype='in') party = self.prep_party() books = Book.create([{ 'name': 'Book 1', 'btype': types.id, 'company': company.id, 'currency': company.currency.id, 'number_sequ': sequ_id, 'start_date': date(2022, 4, 1), 'lines': [('create', [{ 'date': date(2022, 5, 5), 'description': 'Income 1a', 'bookingtype': 'in', 'amount': Decimal('10.0'), 'category': category.id, 'party': party.id, }, { 'date': date(2022, 5, 5), 'description': 'Income 1b', 'bookingtype': 'in', 'amount': Decimal('15.0'), 'category': category.id, 'party': party.id, }])], }, { 'name': 'Book 2', 'btype': types.id, 'company': company.id, 'currency': company.currency.id, 'number_sequ': sequ_id, 'start_date': date(2022, 4, 1), 'lines': [('create', [{ 'date': date(2022, 5, 5), 'description': 'Income 2a', 'bookingtype': 'in', 'amount': Decimal('5.0'), 'category': category.id, 'party': party.id, }, { 'date': date(2022, 5, 5), 'description': 'Income 2b', 'bookingtype': 'in', 'amount': Decimal('7.5'), 'category': category.id, 'party': party.id, }])], }, { 'name': 'Book 3', 'btype': types.id, 'company': company.id, 'currency': company.currency.id, 'number_sequ': sequ_id, 'start_date': date(2022, 4, 1), 'lines': [('create', [{ 'date': date(2022, 5, 5), 'description': 'Income 3a', 'bookingtype': 'in', 'amount': Decimal('12.5'), 'category': category.id, 'party': party.id, }, { 'date': date(2022, 5, 5), 'description': 'Income 3b', 'bookingtype': 'in', 'amount': Decimal('10.5'), 'category': category.id, 'party': party.id, }])], }]) self.assertEqual(len(books), 3) self.assertEqual(books[0].name, 'Book 1') self.assertEqual(len(books[0].lines), 2) self.assertEqual(books[0].balance, Decimal('25.0')) self.assertEqual(books[1].name, 'Book 2') self.assertEqual(len(books[1].lines), 2) self.assertEqual(books[1].balance, Decimal('12.5')) self.assertEqual(books[2].name, 'Book 3') self.assertEqual(len(books[2].lines), 2) self.assertEqual(books[2].balance, Decimal('23.0')) return books @with_transaction() def test_report_chart_pie_book_red(self): """ create 3x cashbooks, add bookings, create report, check """ Evaluation = Pool().get('cashbook_report.evaluation') books = self.prep_report_3books() company = self.prep_company() with Transaction().set_context({ 'company': company.id, }): evaluation, = Evaluation.create([{ 'name': 'Evaluation 1', 'lines': [('add', [x.id for x in books])], }]) self.assertEqual(len(evaluation.lines), 3) self.assertEqual(evaluation.dtype, 'book') self.assertEqual(evaluation.chart, 'pie') self.assertEqual(evaluation.legend, True) self.assertEqual(evaluation.posted, False) self.assertEqual(evaluation.maincolor, 'default') self.assertEqual(evaluation.bgcolor, '#ffffc0') # end ReportTestCase