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 .category import Category
|
||||||
from .book import CategoryCashbookRel, Cashbook
|
from .book import CategoryCashbookRel, Cashbook
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
Pool.register(
|
Pool.register(
|
||||||
Category,
|
Category,
|
||||||
|
|
9
book.py
9
book.py
|
@ -9,7 +9,8 @@ from trytond.pool import PoolMeta
|
||||||
class Cashbook(metaclass=PoolMeta):
|
class Cashbook(metaclass=PoolMeta):
|
||||||
__name__ = 'cashbook.book'
|
__name__ = 'cashbook.book'
|
||||||
|
|
||||||
categories = fields.Many2Many(string='Categories',
|
categories = fields.Many2Many(
|
||||||
|
string='Categories',
|
||||||
relation_name='cashbook.bookcategory-rel',
|
relation_name='cashbook.bookcategory-rel',
|
||||||
origin='cashbook', target='category')
|
origin='cashbook', target='category')
|
||||||
|
|
||||||
|
@ -20,9 +21,11 @@ class CategoryCashbookRel(ModelSQL):
|
||||||
'Category Cashbook Relation'
|
'Category Cashbook Relation'
|
||||||
__name__ = 'cashbook.bookcategory-rel'
|
__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')
|
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')
|
model_name='cashbook.book', ondelete='CASCADE')
|
||||||
|
|
||||||
# end CategoryCashbookRel
|
# end CategoryCashbookRel
|
||||||
|
|
12
category.py
12
category.py
|
@ -11,16 +11,20 @@ class Category(tree(separator=' / '), ModelSQL, ModelView):
|
||||||
"Cashbook Category"
|
"Cashbook Category"
|
||||||
__name__ = "cashbook.bookcategory"
|
__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")
|
required=True, ondelete="RESTRICT")
|
||||||
name = fields.Char(string='Name', required=True, translate=True)
|
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')
|
model_name='cashbook.bookcategory', ondelete='CASCADE')
|
||||||
childs = fields.One2Many(string='Children', field='parent',
|
childs = fields.One2Many(
|
||||||
|
string='Children', field='parent',
|
||||||
model_name='cashbook.bookcategory')
|
model_name='cashbook.bookcategory')
|
||||||
|
|
||||||
cashbooks = fields.Many2Many(string='Cashbooks',
|
cashbooks = fields.Many2Many(
|
||||||
|
string='Cashbooks',
|
||||||
relation_name='cashbook.bookcategory-rel',
|
relation_name='cashbook.bookcategory-rel',
|
||||||
origin='category', target='cashbook')
|
origin='category', target='cashbook')
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
# -*- coding: utf-8 -*-
|
||||||
# this repository contains the full copyright notices and license terms.
|
# 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 trytond.tests.test_tryton
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from trytond.modules.cashbook_bookcategory.tests.test_category import CategoryTestCase
|
from .test_category import CategoryTestCase
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['suite']
|
__all__ = ['suite']
|
||||||
|
|
||||||
|
|
||||||
class CashbookCategoryTestCase(\
|
class CashbookCategoryTestCase(CategoryTestCase):
|
||||||
CategoryTestCase,\
|
|
||||||
):
|
|
||||||
'Test cashbook module'
|
'Test cashbook module'
|
||||||
module = 'cashbook_bookcategory'
|
module = 'cashbook_bookcategory'
|
||||||
|
|
||||||
# end CashbookCategoryTestCase
|
# end CashbookCategoryTestCase
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
suite = trytond.tests.test_tryton.suite()
|
suite = trytond.tests.test_tryton.suite()
|
||||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(CashbookCategoryTestCase))
|
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
||||||
|
CashbookCategoryTestCase))
|
||||||
return suite
|
return suite
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
# 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.
|
||||||
|
|
||||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
from trytond.tests.test_tryton import with_transaction
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.exceptions import UserError
|
|
||||||
from trytond.modules.cashbook.tests import CashbookTestCase
|
from trytond.modules.cashbook.tests import CashbookTestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,8 +21,7 @@ class CategoryTestCase(CashbookTestCase):
|
||||||
|
|
||||||
company = self.prep_company()
|
company = self.prep_company()
|
||||||
with Transaction().set_context({
|
with Transaction().set_context({
|
||||||
'company': company.id,
|
'company': company.id}):
|
||||||
}):
|
|
||||||
categories, = BookCategory.create([{
|
categories, = BookCategory.create([{
|
||||||
'name': 'Cat 0',
|
'name': 'Cat 0',
|
||||||
'childs': [('create', [{
|
'childs': [('create', [{
|
||||||
|
@ -56,8 +54,7 @@ class CategoryTestCase(CashbookTestCase):
|
||||||
types = self.prep_type()
|
types = self.prep_type()
|
||||||
company = self.prep_company()
|
company = self.prep_company()
|
||||||
with Transaction().set_context({
|
with Transaction().set_context({
|
||||||
'company': company.id,
|
'company': company.id}):
|
||||||
}):
|
|
||||||
category, = BookCategory.create([{
|
category, = BookCategory.create([{
|
||||||
'name': 'Cat 0',
|
'name': 'Cat 0',
|
||||||
'childs': [('create', [{
|
'childs': [('create', [{
|
||||||
|
@ -79,7 +76,9 @@ class CategoryTestCase(CashbookTestCase):
|
||||||
self.assertEqual(book.categories[0].rec_name, 'Cat 0')
|
self.assertEqual(book.categories[0].rec_name, 'Cat 0')
|
||||||
|
|
||||||
self.assertEqual(len(category.cashbooks), 1)
|
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
|
# replace category
|
||||||
Book.write(*[
|
Book.write(*[
|
||||||
|
|
Loading…
Reference in a new issue