neu: kategorie, config + test
This commit is contained in:
parent
b9bb433c39
commit
d6a8b254a3
28 changed files with 1255 additions and 35 deletions
85
category.py
Normal file
85
category.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
# -*- 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.model import ModelView, ModelSQL, fields, Unique, tree
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class Category(tree(separator='/'), ModelSQL, ModelView):
|
||||
'Category'
|
||||
__name__ = 'cashbook.category'
|
||||
|
||||
name = fields.Char(string='Name', required=True, translate=True)
|
||||
description = fields.Char(string='Description', translate=True)
|
||||
account = fields.Many2One(string='Account', select=True,
|
||||
model_name='account.account', ondelete='RESTRICT')
|
||||
account_code = fields.Function(fields.Char(string='Account', readonly=True),
|
||||
'on_change_with_account_code', searcher='search_account_code')
|
||||
|
||||
company = fields.Many2One(string='Company', model_name='company.company',
|
||||
required=True, ondelete="RESTRICT")
|
||||
parent = fields.Many2One(string="Parent",
|
||||
model_name='cashbook.category', ondelete='RESTRICT',
|
||||
left='left', right='right')
|
||||
childs = fields.One2Many(string='Children', field='parent',
|
||||
model_name='cashbook.category')
|
||||
left = fields.Integer(string='Left', required=True, select=True)
|
||||
right = fields.Integer(string='Right', required=True, select=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Category, cls).__setup__()
|
||||
cls._order.insert(0, ('name', 'ASC'))
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints.extend([
|
||||
('name_uniq', Unique(t, t.name, t.company, t.parent), 'cashbook.msg_category_name_unique'),
|
||||
('account_uniq', Unique(t, t.account, t.company), 'cashbook.msg_category_account_unique'),
|
||||
])
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company') or None
|
||||
|
||||
@staticmethod
|
||||
def default_left():
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def default_right():
|
||||
return 0
|
||||
|
||||
def get_rec_name(self, name):
|
||||
""" short + name
|
||||
"""
|
||||
l1 = []
|
||||
if self.account:
|
||||
if self.account.code:
|
||||
l1.append(self.account.code)
|
||||
l1.append(super(Category, self).get_rec_name(name))
|
||||
return ' '.join(l1)
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
""" search in account + name
|
||||
"""
|
||||
return ['OR',
|
||||
super(Category, cls).search_rec_name(name, clause),
|
||||
('account.rec_name',) + tuple(clause[1:]),
|
||||
]
|
||||
|
||||
@fields.depends('account')
|
||||
def on_change_with_account_code(self, name=None):
|
||||
""" get code of account
|
||||
"""
|
||||
if self.account:
|
||||
return self.account.code
|
||||
|
||||
@classmethod
|
||||
def search_account_code(cls, names, clause):
|
||||
""" search in code
|
||||
"""
|
||||
return [('account.code',) + tuple(clause[1:])]
|
||||
|
||||
# end Category
|
Loading…
Add table
Add a link
Reference in a new issue