formatting
This commit is contained in:
parent
2a4fbbabdd
commit
f4597378c3
5 changed files with 30 additions and 21 deletions
|
@ -7,6 +7,7 @@ from trytond.pool import Pool
|
|||
from .category import Category
|
||||
from .book import CategoryCashbookRel, Cashbook
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Category,
|
||||
|
|
9
book.py
9
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
|
||||
|
|
12
category.py
12
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')
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(*[
|
||||
|
|
Loading…
Reference in a new issue