kategorie: typ 'einnahme/ausgabe' - test muß noch

This commit is contained in:
Frederik Jaeckel 2022-08-10 17:06:20 +02:00
parent d57d76ba3b
commit 52ffa0536e
7 changed files with 95 additions and 1 deletions

View file

@ -6,6 +6,14 @@
from trytond.model import ModelView, ModelSQL, fields, Unique, tree, sequence_ordered
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.exceptions import UserError
from trytond.i18n import gettext
sel_categorytype = [
('in', 'Revenue'),
('out', 'Expense'),
]
class Category(tree(separator='/'), sequence_ordered(), ModelSQL, ModelView):
@ -14,6 +22,9 @@ class Category(tree(separator='/'), sequence_ordered(), ModelSQL, ModelView):
name = fields.Char(string='Name', required=True, translate=True)
description = fields.Char(string='Description', translate=True)
cattype = fields.Selection(string='Type', required=True,
help='Type of Category', selection=sel_categorytype)
account = fields.Many2One(string='Account', select=True,
model_name='account.account', ondelete='RESTRICT')
account_code = fields.Function(fields.Char(string='Account', readonly=True),
@ -40,6 +51,10 @@ class Category(tree(separator='/'), sequence_ordered(), ModelSQL, ModelView):
('account_uniq', Unique(t, t.account, t.company), 'cashbook.msg_category_account_unique'),
])
@classmethod
def default_cattype(cls):
return 'out'
@staticmethod
def default_company():
return Transaction().context.get('company') or None
@ -96,4 +111,34 @@ class Category(tree(separator='/'), sequence_ordered(), ModelSQL, ModelView):
"""
return [('account.code',) + tuple(clause[1:])]
@classmethod
def write(cls, *args):
""" parent.cattape == cattype,
update sub-categories
"""
to_write = []
actions = iter(args)
for categories, values in zip(actions, actions):
if 'cattype' in values.keys():
for category in categories:
if category.parent:
if category.parent.cattype != values['cattype']:
raise UserError(gettext(
'cashbook.msg_category_type_not_like_parent',
parentname = category.parent.rec_name,
catname = category.rec_name,
))
cats = Category.search([('parent', 'child_of', [x.id for x in categories])])
if len(cats) > 0:
to_write.extend([
cats,
{
'cattype': values['cattype'],
}])
super(Category, cls).write(*args)
if len(to_write) > 0:
print('\n## to_write:',to_write)
Category.write(*to_write)
# end Category