auswertung: Feld 'lines', pie-chart als test

This commit is contained in:
Frederik Jaeckel 2022-10-28 19:31:37 +02:00
parent 34a3a987fa
commit 085228e047
12 changed files with 402 additions and 16 deletions

View file

@ -4,9 +4,10 @@
# full copyright notices and license terms. # full copyright notices and license terms.
from trytond.pool import Pool from trytond.pool import Pool
from .evaluation import Evaluation from .evaluation import Evaluation, EvaluationCashbookRel
def register(): def register():
Pool.register( Pool.register(
Evaluation, Evaluation,
EvaluationCashbookRel,
module='cashbook_report', type_='model') module='cashbook_report', type_='model')

View file

@ -53,11 +53,21 @@ class Evaluation(ModelSQL, ModelView):
bgcolor = fields.Selection(string='Background Color', required=True, bgcolor = fields.Selection(string='Background Color', required=True,
help='Background color of the chart area.', sort=False, help='Background color of the chart area.', sort=False,
selection=sel_bgcolor) selection=sel_bgcolor)
posted = fields.Boolean(string='Posted', help='Posted amounts only.')
lines = fields.Many2Many(string='Cashbooks',
relation_name='cashbook_report.eval_book',
origin='evaluation', target='cashbook')
@staticmethod @staticmethod
def default_company(): def default_company():
return Transaction().context.get('company') or None return Transaction().context.get('company') or None
@classmethod
def default_posted(cls):
""" default: False
"""
return False
@classmethod @classmethod
def default_bgcolor(cls): def default_bgcolor(cls):
""" default: Yellow 5 """ default: Yellow 5
@ -77,15 +87,29 @@ class Evaluation(ModelSQL, ModelView):
return True return True
@classmethod @classmethod
def default_etype(cls): def default_dtype(cls):
""" default 'book' """ default 'book'
""" """
return 'book' return 'book'
@classmethod @classmethod
def default_chart(cls): def default_chart(cls):
""" default 'pir' """ default 'pie'
""" """
return 'pie' return 'pie'
# end Evaluation # end Evaluation
class EvaluationCashbookRel(ModelSQL):
'Evaluation Cashbook Relation'
__name__ = 'cashbook_report.eval_book'
evaluation = fields.Many2One(string='Evaluation', required=True,
select=True, ondelete='CASCADE',
model_name='cashbook_report.evaluation')
cashbook = fields.Many2One(string='Cashbook', required=True,
select=True, ondelete='CASCADE',
model_name='cashbook.book')
# end EvaluationCashbookRel

17
graph.xml Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!-- This file is part of the diagram-module from m-ds for Tryton.
The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. -->
<tryton>
<data>
<!-- views -->
<record model="ir.ui.view" id="book_view_graph">
<field name="model">cashbook.book</field>
<field name="type">graph</field>
<field name="priority" eval="10"/>
<field name="name">book_graph</field>
</record>
</data>
</tryton>

View file

@ -27,6 +27,22 @@ msgid "Evaluation"
msgstr "Auswertung" msgstr "Auswertung"
#############################
# cashbook_report.eval_book #
#############################
msgctxt "model:cashbook_report.eval_book,name:"
msgid "Evaluation Cashbook Relation"
msgstr "Auswertung Kassenbuch Verknüpfung"
msgctxt "field:cashbook_report.eval_book,evaluation:"
msgid "Evaluation"
msgstr "Auswertung"
msgctxt "field:cashbook_report.eval_book,cashbook:"
msgid "Cashbook"
msgstr "Kassenbuch"
############################## ##############################
# cashbook_report.evaluation # # cashbook_report.evaluation #
############################## ##############################
@ -34,6 +50,14 @@ msgctxt "model:cashbook_report.evaluation,name:"
msgid "Evaluation" msgid "Evaluation"
msgstr "Auswertung" msgstr "Auswertung"
msgctxt "view:cashbook_report.evaluation:"
msgid "Chart"
msgstr "Diagramm"
msgctxt "view:cashbook_report.evaluation:"
msgid "Settings"
msgstr "Einstellungen"
msgctxt "view:cashbook_report.evaluation:" msgctxt "view:cashbook_report.evaluation:"
msgid "Representation" msgid "Representation"
msgstr "Darstellung" msgstr "Darstellung"
@ -129,3 +153,15 @@ msgstr "Hintergrundfarbe"
msgctxt "help:cashbook_report.evaluation,bgcolor:" msgctxt "help:cashbook_report.evaluation,bgcolor:"
msgid "Background color of the chart area. (hex number, e.g. #ffffc0)" msgid "Background color of the chart area. (hex number, e.g. #ffffc0)"
msgstr "Hintergrundfarbe der Diagrammfläche. (Hexzahl, z.B. #ffffc0)" msgstr "Hintergrundfarbe der Diagrammfläche. (Hexzahl, z.B. #ffffc0)"
msgctxt "field:cashbook_report.evaluation,posted:"
msgid "Posted"
msgstr "Festgeschrieben"
msgctxt "help:cashbook_report.evaluation,posted:"
msgid "Posted amounts only."
msgstr "Nur festgeschriebene Beträge."
msgctxt "field:cashbook_report.evaluation,lines:"
msgid "Cashbooks"
msgstr "Kassenbücher"

View file

@ -2,10 +2,30 @@
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n" msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "model:ir.rule.group,name:rg_eval_write_adm"
msgid "Administrators: Evaluation read/write"
msgstr "Administrators: Evaluation read/write"
msgctxt "model:ir.rule.group,name:rg_eval_rw_owner"
msgid "Owners: Evaluation read/write"
msgstr "Owners: Evaluation read/write"
msgctxt "model:ir.rule.group,name:rg_eval_companies"
msgid "User in companies"
msgstr "User in companies"
msgctxt "model:ir.ui.menu,name:menu_evaluation"
msgid "Evaluation"
msgstr "Evaluation"
msgctxt "model:cashbook_report.evaluation,name:" msgctxt "model:cashbook_report.evaluation,name:"
msgid "Evaluation" msgid "Evaluation"
msgstr "Evaluation" msgstr "Evaluation"
msgctxt "view:cashbook_report.evaluation:"
msgid "Representation"
msgstr "Representation"
msgctxt "field:cashbook_report.evaluation,name:" msgctxt "field:cashbook_report.evaluation,name:"
msgid "Name" msgid "Name"
msgstr "Name" msgstr "Name"
@ -14,3 +34,91 @@ msgctxt "field:cashbook_report.evaluation,dtype:"
msgid "Data type" msgid "Data type"
msgstr "Data type" msgstr "Data type"
msgctxt "selection:cashbook_report.evaluation,dtype:"
msgid "Cashbooks"
msgstr "Cashbooks"
msgctxt "selection:cashbook_report.evaluation,dtype:"
msgid "Types of Cashbooks"
msgstr "Types of Cashbooks"
msgctxt "selection:cashbook_report.evaluation,dtype:"
msgid "Currencys"
msgstr "Currencys"
msgctxt "help:cashbook_report.evaluation,dtype:"
msgid "Type of data displayed"
msgstr "Type of data displayed"
msgctxt "field:cashbook_report.evaluation,chart:"
msgid "Chart type"
msgstr "Chart type"
msgctxt "help:cashbook_report.evaluation,chart:"
msgid "Type of graphical presentation."
msgstr "Type of graphical presentation."
msgctxt "selection:cashbook_report.evaluation,chart:"
msgid "Pie"
msgstr "Pie"
msgctxt "selection:cashbook_report.evaluation,chart:"
msgid "Line"
msgstr "Line"
msgctxt "selection:cashbook_report.evaluation,chart:"
msgid "Vertical Bars"
msgstr "Vertical Bars"
msgctxt "selection:cashbook_report.evaluation,chart:"
msgid "Horizontal Bars"
msgstr "Horizontal Bars"
msgctxt "field:cashbook_report.evaluation,legend:"
msgid "Legend"
msgstr "Legend"
msgctxt "field:cashbook_report.evaluation,maincolor:"
msgid "Color scheme"
msgstr "Color scheme"
msgctxt "help:cashbook_report.evaluation,maincolor:"
msgid "The color scheme determines the hue of all components of the chart."
msgstr "The color scheme determines the hue of all components of the chart."
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Default"
msgstr "Default"
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Red"
msgstr "Red"
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Green"
msgstr "Green"
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Grey"
msgstr "Grey"
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Black"
msgstr "Black"
msgctxt "selection:cashbook_report.evaluation,maincolor:"
msgid "Dark Cyan"
msgstr "Dark Cyan"
msgctxt "field:cashbook_report.evaluation,bgcolor:"
msgid "Background Color"
msgstr "Background Color"
msgctxt "help:cashbook_report.evaluation,bgcolor:"
msgid "Background color of the chart area. (hex number, e.g. #ffffc0)"
msgstr "Background color of the chart area. (hex number, e.g. #ffffc0)"
msgctxt "field:cashbook_report.evaluation,posted:"
msgid "Posted"
msgstr "Posted"

18
templates.py Normal file
View file

@ -0,0 +1,18 @@
# -*- 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.
template_view_line = '<field %(linecolor)s name="%(yname)s" fill="%(fill)s" empty="0" string="%(string)s"/>'
template_view_point = """<?xml version="1.0"?>
<graph type="%(type)s" legend="%(legend)s" %(colscheme)s %(bgcol)s>
<x>
<field name="%(xname)s"/>
</x>
<y>
%(lines)s
</y>
</graph>
"""

24
tests/__init__.py Normal file
View file

@ -0,0 +1,24 @@
# 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 trytond.tests.test_tryton
import unittest
from trytond.modules.cashbook_report.tests.test_report import ReportTestCase
__all__ = ['suite']
class CashbookReportTestCase(\
ReportTestCase,\
):
'Test cashbook report module'
module = 'cashbook_report'
# end CashbookReportTestCase
def suite():
suite = trytond.tests.test_tryton.suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookReportTestCase))
return suite

136
tests/test_report.py Normal file
View file

@ -0,0 +1,136 @@
# -*- 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

View file

@ -4,5 +4,6 @@ depends:
cashbook cashbook
xml: xml:
icon.xml icon.xml
graph.xml
evaluation.xml evaluation.xml
menu.xml menu.xml

12
view/book_graph.xml Normal file
View file

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!-- 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. -->
<graph type="pie" legend="1" background="#ffffc0">
<x>
<field name="name"/>
</x>
<y>
<field name="balance" fill="1" empty="0"/>
</y>
</graph>

View file

@ -2,19 +2,27 @@
<!-- This file is part of the cashbook-module from m-ds for Tryton. <!-- 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 The COPYRIGHT file at the top level of this repository contains the
full copyright notices and license terms. --> full copyright notices and license terms. -->
<form col="6"> <form col="1">
<label name="name"/> <notebook>
<field name="name"/> <page id="chart" col="1" string="Chart">
<label name="dtype"/> <field name="lines" view_ids="cashbook_report.book_view_graph" readonly="1"/>
<field name="dtype"/> </page>
<newline/> <page id="config" col="6" string="Settings">
<label name="name"/>
<field name="name"/>
<label name="dtype"/>
<field name="dtype"/>
<newline/>
<separator colspan="6" id="sepdisplay" string="Representation"/> <separator colspan="6" id="sepdisplay" string="Representation"/>
<label name="chart"/> <label name="chart"/>
<field name="chart"/> <field name="chart"/>
<label name="maincolor"/> <label name="maincolor"/>
<field name="maincolor"/> <field name="maincolor"/>
<label name="legend"/> <label name="legend"/>
<field name="legend"/> <field name="legend"/>
<field name="lines" colspan="6"/>
</page>
</notebook>
</form> </form>

View file

@ -8,4 +8,5 @@ full copyright notices and license terms. -->
<field name="chart"/> <field name="chart"/>
<field name="legend"/> <field name="legend"/>
<field name="maincolor"/> <field name="maincolor"/>
<field name="lines"/>
</tree> </tree>