From f4597378c3c0975562b546cf1ce4abcb9327cc5d Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Mon, 5 Jun 2023 21:06:03 +0200 Subject: [PATCH] formatting --- __init__.py | 1 + book.py | 9 ++++++--- category.py | 12 ++++++++---- tests/__init__.py | 16 +++++++++------- tests/test_category.py | 13 ++++++------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/__init__.py b/__init__.py index 11bfdee..e8af3da 100644 --- a/__init__.py +++ b/__init__.py @@ -7,6 +7,7 @@ from trytond.pool import Pool from .category import Category from .book import CategoryCashbookRel, Cashbook + def register(): Pool.register( Category, diff --git a/book.py b/book.py index 8390766..00a2d5e 100644 --- a/book.py +++ b/book.py @@ -9,7 +9,8 @@ from trytond.pool import PoolMeta class Cashbook(metaclass=PoolMeta): __name__ = 'cashbook.book' - categories = fields.Many2Many(string='Categories', + categories = fields.Many2Many( + string='Categories', relation_name='cashbook.bookcategory-rel', origin='cashbook', target='category') @@ -20,9 +21,11 @@ class CategoryCashbookRel(ModelSQL): 'Category Cashbook Relation' __name__ = 'cashbook.bookcategory-rel' - category = fields.Many2One(string='Category', required=True, select=True, + category = fields.Many2One( + string='Category', required=True, select=True, model_name='cashbook.bookcategory', ondelete='CASCADE') - cashbook = fields.Many2One(string='Cashbook', required=True, select=True, + cashbook = fields.Many2One( + string='Cashbook', required=True, select=True, model_name='cashbook.book', ondelete='CASCADE') # end CategoryCashbookRel diff --git a/category.py b/category.py index 42e1ec7..b428e51 100644 --- a/category.py +++ b/category.py @@ -11,16 +11,20 @@ class Category(tree(separator=' / '), ModelSQL, ModelView): "Cashbook Category" __name__ = "cashbook.bookcategory" - company = fields.Many2One(string='Company', model_name='company.company', + company = fields.Many2One( + string='Company', model_name='company.company', required=True, ondelete="RESTRICT") name = fields.Char(string='Name', required=True, translate=True) - parent = fields.Many2One(string='Parent', select=True, + parent = fields.Many2One( + string='Parent', select=True, model_name='cashbook.bookcategory', ondelete='CASCADE') - childs = fields.One2Many(string='Children', field='parent', + childs = fields.One2Many( + string='Children', field='parent', model_name='cashbook.bookcategory') - cashbooks = fields.Many2Many(string='Cashbooks', + cashbooks = fields.Many2Many( + string='Cashbooks', relation_name='cashbook.bookcategory-rel', origin='category', target='cashbook') diff --git a/tests/__init__.py b/tests/__init__.py index ead6f2c..a6930ba 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,24 +1,26 @@ -# This file is part of Tryton. The COPYRIGHT file at the top level of -# this repository contains the full copyright notices and license terms. +# -*- 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. import trytond.tests.test_tryton import unittest -from trytond.modules.cashbook_bookcategory.tests.test_category import CategoryTestCase +from .test_category import CategoryTestCase __all__ = ['suite'] -class CashbookCategoryTestCase(\ - CategoryTestCase,\ - ): +class CashbookCategoryTestCase(CategoryTestCase): 'Test cashbook module' module = 'cashbook_bookcategory' # end CashbookCategoryTestCase + def suite(): suite = trytond.tests.test_tryton.suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookCategoryTestCase)) + suite.addTests(unittest.TestLoader().loadTestsFromTestCase( + CashbookCategoryTestCase)) return suite diff --git a/tests/test_category.py b/tests/test_category.py index 6ec3c31..4bf63d5 100644 --- a/tests/test_category.py +++ b/tests/test_category.py @@ -3,10 +3,9 @@ # 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.tests.test_tryton import with_transaction from trytond.pool import Pool from trytond.transaction import Transaction -from trytond.exceptions import UserError from trytond.modules.cashbook.tests import CashbookTestCase @@ -22,8 +21,7 @@ class CategoryTestCase(CashbookTestCase): company = self.prep_company() with Transaction().set_context({ - 'company': company.id, - }): + 'company': company.id}): categories, = BookCategory.create([{ 'name': 'Cat 0', 'childs': [('create', [{ @@ -56,8 +54,7 @@ class CategoryTestCase(CashbookTestCase): types = self.prep_type() company = self.prep_company() with Transaction().set_context({ - 'company': company.id, - }): + 'company': company.id}): category, = BookCategory.create([{ 'name': 'Cat 0', 'childs': [('create', [{ @@ -79,7 +76,9 @@ class CategoryTestCase(CashbookTestCase): self.assertEqual(book.categories[0].rec_name, 'Cat 0') self.assertEqual(len(category.cashbooks), 1) - self.assertEqual(category.cashbooks[0].rec_name, 'Book 1 | 0.00 usd | Open') + self.assertEqual( + category.cashbooks[0].rec_name, + 'Book 1 | 0.00 usd | Open') # replace category Book.write(*[