From a2cb2b308bdc0e200c38ada8c7cc50adf2f3ed92 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Wed, 7 Sep 2022 11:36:37 +0200 Subject: [PATCH] =?UTF-8?q?konfig:=20kassenbuch-default=20f=C3=BCr=20buchu?= =?UTF-8?q?ngswizard=20buchungswizard:=20ok=20+=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configuration.py | 7 +- locale/de.po | 43 ++++++++ tests/__init__.py | 3 + tests/test_bookingwiz.py | 179 +++++++++++++++++++++++++++++++ tests/test_config.py | 32 ++++++ view/configuration_form.xml | 4 + view/enterbooking_start_form.xml | 13 ++- wizard_booking.py | 108 +++++++++++++++++-- 8 files changed, 377 insertions(+), 12 deletions(-) create mode 100644 tests/test_bookingwiz.py diff --git a/configuration.py b/configuration.py index e0e460f..e8de3b6 100644 --- a/configuration.py +++ b/configuration.py @@ -15,6 +15,9 @@ field_done = fields.Boolean(string='Done', help='Show cashbook lines in Done-state.') field_catnamelong = fields.Boolean(string='Category: Show long name', help='Shows the long name of the category in the Category field of a cash book line.') +field_defbook = fields.Many2One(string='Default Cashbook', + help='The default cashbook is selected when you open the booking wizard.', + model_name='cashbook.book', ondelete='SET NULL') class Configuration(ModelSingleton, ModelSQL, ModelView, UserMultiValueMixin): @@ -36,6 +39,7 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, UserMultiValueMixin): checked = fields.MultiValue(field_checked) done = fields.MultiValue(field_done) catnamelong = fields.MultiValue(field_catnamelong) + defbook = fields.MultiValue(field_defbook) @classmethod def multivalue_model(cls, field): @@ -44,7 +48,7 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, UserMultiValueMixin): pool = Pool() if field in ['date_from', 'date_to', 'checked', 'done', - 'catnamelong']: + 'catnamelong', 'defbook']: return pool.get('cashbook.configuration_user') return super(Configuration, cls).multivalue_model(field) @@ -82,6 +86,7 @@ class UserConfiguration(ModelSQL, UserValueMixin): checked = field_checked done = field_done catnamelong = field_catnamelong + defbook = field_defbook @classmethod def default_checked(cls): diff --git a/locale/de.po b/locale/de.po index 069bc80..71403b9 100644 --- a/locale/de.po +++ b/locale/de.po @@ -998,6 +998,10 @@ msgctxt "model:cashbook.configuration,name:" msgid "Configuration" msgstr "Konfiguration" +msgctxt "view:cashbook.configuration:" +msgid "Enter Booking Wizard" +msgstr "Dialog: Buchung eingeben" + msgctxt "view:cashbook.configuration:" msgid "Open Cashbook Wizard" msgstr "Dialog: Kassenbuch öffnen" @@ -1006,6 +1010,14 @@ msgctxt "view:cashbook.configuration:" msgid "Cashbook" msgstr "Kassenbuch" +msgctxt "field:cashbook.configuration,defbook:" +msgid "Default Cashbook" +msgstr "Standardkassenbuch" + +msgctxt "help:cashbook.configuration,defbook:" +msgid "The default cashbook is selected when you open the booking wizard." +msgstr "Das Standardkassenbuch wird beim Öffnen des Buchungswizards ausgewählt." + msgctxt "field:cashbook.configuration,date_from:" msgid "Start Date" msgstr "Beginndatum" @@ -1078,6 +1090,14 @@ msgctxt "help:cashbook.configuration_user,catnamelong:" msgid "Shows the long name of the category in the Category field of a cash book line." msgstr "Zeigt im Feld 'Kategorie' einer Kassenbuchzeile den langen Namen der Kategorie." +msgctxt "field:cashbook.configuration_user,defbook:" +msgid "Default Cashbook" +msgstr "Standardkassenbuch" + +msgctxt "help:cashbook.configuration_user,defbook:" +msgid "The default cashbook is selected when you open the booking wizard." +msgstr "Das Standardkassenbuch wird beim Öffnen des Buchungswizards ausgewählt." + ################## # cashbook.recon # @@ -1270,6 +1290,10 @@ msgctxt "model:cashbook.enterbooking.start,name:" msgid "Enter Booking" msgstr "Buchung eingeben" +msgctxt "view:cashbook.enterbooking.start:" +msgid "Description" +msgstr "Beschreibung" + msgctxt "field:cashbook.enterbooking.start,cashbook:" msgid "Cashbook" msgstr "Kassenbuch" @@ -1322,6 +1346,21 @@ msgctxt "field:cashbook.enterbooking.start,amount:" msgid "Amount" msgstr "Betrag" +msgctxt "field:cashbook.enterbooking.start,owner_cashbook:" +msgid "Owner" +msgstr "Eigentümer" + +msgctxt "field:cashbook.enterbooking.start,category:" +msgid "Category" +msgstr "Kategorie" + +msgctxt "field:cashbook.enterbooking.start,booktransf:" +msgid "Source/Dest" +msgstr "Quelle/Ziel" + +msgctxt "field:cashbook.enterbooking.start,party:" +msgid "Party" +msgstr "Partei" ######################### @@ -1338,3 +1377,7 @@ msgstr "Abbruch" msgctxt "wizard_button:cashbook.enterbooking,start,save_:" msgid "Save" msgstr "Speichern" + +msgctxt "wizard_button:cashbook.enterbooking,start,savenext_:" +msgid "Save & Next" +msgstr "Speichern & Weiter" diff --git a/tests/__init__.py b/tests/__init__.py index f557851..dea659d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -11,11 +11,14 @@ 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 +from trytond.modules.cashbook.tests.test_bookingwiz import BookingWizardTestCase + __all__ = ['suite'] class CashbookTestCase(\ + BookingWizardTestCase,\ ReconTestCase,\ CategoryTestCase,\ ConfigTestCase,\ diff --git a/tests/test_bookingwiz.py b/tests/test_bookingwiz.py new file mode 100644 index 0000000..29f2665 --- /dev/null +++ b/tests/test_bookingwiz.py @@ -0,0 +1,179 @@ +# -*- 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 decimal import Decimal +from unittest.mock import MagicMock + + +class BookingWizardTestCase(ModuleTestCase): + 'Test cashbook booking wizard module' + module = 'cashbook' + + @with_transaction() + def test_bookwiz_expense(self): + """ run booking-wizard to store expense + """ + pool = Pool() + BookingWiz = pool.get('cashbook.enterbooking', type='wizard') + Book = pool.get('cashbook.book') + Category = pool.get('cashbook.category') + Party = pool.get('party.party') + IrDate = pool.get('ir.date') + + company = self.prep_company() + with Transaction().set_context({ + 'company': company.id, + }): + types = self.prep_type() + book, = Book.create([{ + 'name': 'Cash Book', + 'btype': types.id, + 'company': company.id, + 'currency': company.currency.id, + 'number_sequ': self.prep_sequence().id, + 'start_date': date(2022, 1, 1), + 'start_balance': Decimal('0.0'), + }]) + + party, = Party.create([{ + 'name': 'Foodshop Zehlendorf', + 'addresses':[('create', [{}])], + }]) + + categories = Category.create([{ + 'name':'Income', + 'cattype': 'in', + }, { + 'name': 'Food', + 'cattype': 'out', + }]) + + (sess_id, start_state, end_state) = BookingWiz.create() + w_obj = BookingWiz(sess_id) + self.assertEqual(start_state, 'start') + self.assertEqual(end_state, 'end') + + result = BookingWiz.execute(sess_id, {}, start_state) + self.assertEqual(list(result.keys()), ['view']) + self.assertEqual(result['view']['defaults']['bookingtype'], 'out') + self.assertEqual(result['view']['defaults']['cashbook'], None) + self.assertEqual(result['view']['defaults']['amount'], None) + self.assertEqual(result['view']['defaults']['party'], None) + self.assertEqual(result['view']['defaults']['booktransf'], None) + self.assertEqual(result['view']['defaults']['description'], None) + self.assertEqual(result['view']['defaults']['category'], None) + + self.assertEqual(len(book.lines), 0) + + r1 = { + 'amount': Decimal('10.0'), + 'cashbook': book.id, + 'party': party.id, + 'description': 'Test 1', + 'category': categories[1].id, + 'bookingtype': 'out', + } + for x in r1.keys(): + setattr(w_obj.start, x, r1[x]) + + IrDate.today = MagicMock(return_value=date(2022, 5, 1)) + result = BookingWiz.execute(sess_id, {'start': r1}, 'save_') + BookingWiz.delete(sess_id) + IrDate.today = MagicMock(return_value=date.today()) + + self.assertEqual(len(book.lines), 1) + self.assertEqual(book.lines[0].rec_name, '05/01/2022|Exp|-10.00 usd|Test 1 [Food]') + + @with_transaction() + def test_bookwiz_transfer(self): + """ run booking-wizard to store expense + """ + pool = Pool() + BookingWiz = pool.get('cashbook.enterbooking', type='wizard') + Book = pool.get('cashbook.book') + Category = pool.get('cashbook.category') + Party = pool.get('party.party') + IrDate = pool.get('ir.date') + + company = self.prep_company() + with Transaction().set_context({ + 'company': company.id, + }): + types = self.prep_type() + books = Book.create([{ + 'name': 'Cash Book', + 'btype': types.id, + 'company': company.id, + 'currency': company.currency.id, + 'number_sequ': self.prep_sequence().id, + 'start_date': date(2022, 1, 1), + 'start_balance': Decimal('0.0'), + }, { + 'name': 'Bank', + 'btype': types.id, + 'company': company.id, + 'currency': company.currency.id, + 'number_sequ': self.prep_sequence().id, + 'start_date': date(2022, 1, 1), + 'start_balance': Decimal('0.0'), + }]) + + party, = Party.create([{ + 'name': 'Foodshop Zehlendorf', + 'addresses':[('create', [{}])], + }]) + + categories = Category.create([{ + 'name':'Income', + 'cattype': 'in', + }, { + 'name': 'Food', + 'cattype': 'out', + }]) + + (sess_id, start_state, end_state) = BookingWiz.create() + w_obj = BookingWiz(sess_id) + self.assertEqual(start_state, 'start') + self.assertEqual(end_state, 'end') + + result = BookingWiz.execute(sess_id, {}, start_state) + self.assertEqual(list(result.keys()), ['view']) + self.assertEqual(result['view']['defaults']['bookingtype'], 'out') + self.assertEqual(result['view']['defaults']['cashbook'], None) + self.assertEqual(result['view']['defaults']['amount'], None) + self.assertEqual(result['view']['defaults']['party'], None) + self.assertEqual(result['view']['defaults']['booktransf'], None) + self.assertEqual(result['view']['defaults']['description'], None) + self.assertEqual(result['view']['defaults']['category'], None) + + self.assertEqual(len(books[0].lines), 0) + self.assertEqual(len(books[1].lines), 0) + + r1 = { + 'amount': Decimal('10.0'), + 'cashbook': books[0].id, + 'description': 'Test 1', + 'booktransf': books[1].id, + 'bookingtype': 'mvout', + } + for x in r1.keys(): + setattr(w_obj.start, x, r1[x]) + + IrDate.today = MagicMock(return_value=date(2022, 5, 1)) + result = BookingWiz.execute(sess_id, {'start': r1}, 'save_') + BookingWiz.delete(sess_id) + IrDate.today = MagicMock(return_value=date.today()) + + self.assertEqual(len(books[0].lines), 1) + self.assertEqual(len(books[1].lines), 0) + self.assertEqual(books[0].lines[0].rec_name, + '05/01/2022|to|-10.00 usd|Test 1 [Bank | 0.00 usd | Open]') + +# end BookingWizardTestCase diff --git a/tests/test_config.py b/tests/test_config.py index 7932229..368ad10 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -42,6 +42,7 @@ class ConfigTestCase(ModuleTestCase): self.assertEqual(cfg2.checked, True) self.assertEqual(cfg2.done, False) self.assertEqual(cfg2.catnamelong, True) + self.assertEqual(cfg2.defbook, None) return cfg2 def prep_party(self, name='Party'): @@ -105,6 +106,37 @@ class ConfigTestCase(ModuleTestCase): """ self.prep_config() + @with_transaction() + def test_config_defbook(self): + """ create config, add default-cashbook + """ + pool = Pool() + Configuration = pool.get('cashbook.configuration') + Book = pool.get('cashbook.book') + + self.prep_config() + 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, + }]) + self.assertEqual(book.name, 'Book 1') + + cfg1 = Configuration.get_singleton() + + Configuration.write(*[ + [cfg1], + { + 'defbook': book.id, + }]) + + cfg2 = Configuration.get_singleton() + self.assertEqual(cfg2.defbook.rec_name, 'Book 1 | 0.00 usd | Open') + @with_transaction() def test_config_create_multi_user(self): """ create config, multi-user diff --git a/view/configuration_form.xml b/view/configuration_form.xml index e3a0ee0..36c5e77 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -12,6 +12,10 @@ this repository contains the full copyright notices and license terms. -->