book, line, category, types: berechtigung für company-user + test,

book: währung neu,
line: buchungstyp, betrag, credit, debit, währung, sortierung
This commit is contained in:
Frederik Jaeckel 2022-08-10 16:30:08 +02:00
parent 1a85b8e80e
commit d57d76ba3b
20 changed files with 620 additions and 115 deletions

29
book.py
View file

@ -4,10 +4,11 @@
# full copyright notices and license terms.
from trytond.model import Workflow, ModelView, ModelSQL, fields, Check
from trytond.pyson import Eval
from trytond.pyson import Eval, Or, Bool
from trytond.exceptions import UserError
from trytond.i18n import gettext
from trytond.transaction import Transaction
from trytond.pool import Pool
STATES = {
@ -26,6 +27,8 @@ class Book(Workflow, ModelSQL, ModelView):
'Cashbook'
__name__ = 'cashbook.book'
company = fields.Many2One(string='Company', model_name='company.company',
required=True, ondelete="RESTRICT")
name = fields.Char(string='Name', required=True,
states=STATES, depends=DEPENDS)
btype = fields.Many2One(string='Type', required=True,
@ -45,6 +48,14 @@ class Book(Workflow, ModelSQL, ModelView):
account = fields.Many2One(string='Account', select=True,
model_name='account.account', ondelete='RESTRICT',
states=STATES, depends=DEPENDS)
currency = fields.Many2One(string='Currency', required=True,
model_name='currency.currency',
states={
'readonly': Or(
STATES['readonly'],
Bool(Eval('lines', [])),
),
}, depends=DEPENDS+['lines'])
state = fields.Selection(string='State', required=True,
readonly=True, selection=sel_state_book)
state_string = state.translated('state')
@ -79,6 +90,22 @@ class Book(Workflow, ModelSQL, ModelView):
},
})
@classmethod
def default_currency(cls):
""" currency of company
"""
Company = Pool().get('company.company')
company = cls.default_company()
if company:
company = Company(company)
if company.currency:
return company.currency.id
@staticmethod
def default_company():
return Transaction().context.get('company') or None
@classmethod
def default_state(cls):
return 'open'