2022-10-28 11:27:33 +00:00
|
|
|
# -*- 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, Check
|
|
|
|
from trytond.pyson import Eval, Or, Bool, Id, Len
|
|
|
|
from trytond.transaction import Transaction
|
2022-10-29 21:05:27 +00:00
|
|
|
from trytond.i18n import gettext
|
|
|
|
from trytond.exceptions import UserError
|
2022-10-28 11:27:33 +00:00
|
|
|
from .colors import sel_color as sel_bgcolor
|
|
|
|
|
|
|
|
|
|
|
|
sel_etype = [
|
2022-10-29 21:05:27 +00:00
|
|
|
('cashbooks', 'Cashbooks'),
|
|
|
|
('types', 'Types of Cashbooks'),
|
|
|
|
('currencies', 'Currencys'),
|
|
|
|
#('category', 'Category'),
|
2022-10-28 11:27:33 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
sel_chart = [
|
|
|
|
('vbar', 'Vertical Bars'),
|
|
|
|
('hbar', 'Horizontal Bars'),
|
|
|
|
('pie', 'Pie'),
|
|
|
|
('line', 'Line'),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
sel_maincolor = [
|
|
|
|
('default', 'Default'),
|
|
|
|
('red', 'Red'),
|
|
|
|
('green', 'Green'),
|
|
|
|
('grey', 'Grey'),
|
|
|
|
('black', 'Black'),
|
|
|
|
('darkcyan', 'Dark Cyan'),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Evaluation(ModelSQL, ModelView):
|
|
|
|
'Evaluation'
|
|
|
|
__name__ = 'cashbook_report.evaluation'
|
|
|
|
|
|
|
|
company = fields.Many2One(string='Company', model_name='company.company',
|
|
|
|
required=True, ondelete="RESTRICT")
|
|
|
|
name = fields.Char(string='Name', required=True)
|
|
|
|
dtype = fields.Selection(string='Data type', required=True,
|
|
|
|
sort=False, selection=sel_etype,
|
|
|
|
help='Type of data displayed')
|
|
|
|
chart = fields.Selection(string='Chart type', required=True,
|
|
|
|
sort=False, selection=sel_chart,
|
|
|
|
help='Type of graphical presentation.')
|
|
|
|
legend = fields.Boolean(string='Legend')
|
|
|
|
maincolor = fields.Selection(string='Color scheme', required=True,
|
|
|
|
help='The color scheme determines the hue of all components of the chart.',
|
|
|
|
selection=sel_maincolor, sort=False)
|
|
|
|
bgcolor = fields.Selection(string='Background Color', required=True,
|
|
|
|
help='Background color of the chart area.', sort=False,
|
|
|
|
selection=sel_bgcolor)
|
2022-10-28 17:31:37 +00:00
|
|
|
posted = fields.Boolean(string='Posted', help='Posted amounts only.')
|
2022-10-29 21:05:27 +00:00
|
|
|
|
|
|
|
cashbooks = fields.Many2Many(string='Cashbooks',
|
2022-10-28 17:31:37 +00:00
|
|
|
relation_name='cashbook_report.eval_book',
|
2022-10-29 21:05:27 +00:00
|
|
|
origin='evaluation', target='cashbook',
|
|
|
|
states={
|
|
|
|
'invisible': Eval('dtype', '') != 'cashbooks',
|
|
|
|
}, depends=['dtype'])
|
|
|
|
types = fields.Many2Many(string='Types',
|
|
|
|
relation_name='cashbook_report.eval_type',
|
|
|
|
origin='evaluation', target='dtype',
|
|
|
|
states={
|
|
|
|
'invisible': Eval('dtype', '') != 'types',
|
|
|
|
}, depends=['dtype'])
|
|
|
|
currencies = fields.Many2Many(string='Currencies',
|
|
|
|
relation_name='cashbook_report.eval_currency',
|
|
|
|
origin='evaluation', target='currency',
|
2022-10-30 21:35:24 +00:00
|
|
|
filter=[('cashbook_hasbookings', '=', True)],
|
2022-10-29 21:05:27 +00:00
|
|
|
states={
|
|
|
|
'invisible': Eval('dtype', '') != 'currencies',
|
|
|
|
}, depends=['dtype'])
|
|
|
|
|
2022-10-30 21:35:24 +00:00
|
|
|
currency_values = fields.One2Many(string='Currency Values',
|
|
|
|
field='evaluation', readonly=True,
|
|
|
|
model_name='cashbook_report.eval_currency')
|
2022-10-28 11:27:33 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def default_company():
|
|
|
|
return Transaction().context.get('company') or None
|
|
|
|
|
2022-10-28 17:31:37 +00:00
|
|
|
@classmethod
|
|
|
|
def default_posted(cls):
|
|
|
|
""" default: False
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2022-10-28 11:27:33 +00:00
|
|
|
@classmethod
|
|
|
|
def default_bgcolor(cls):
|
|
|
|
""" default: Yellow 5
|
|
|
|
"""
|
|
|
|
return '#ffffc0'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def default_maincolor(cls):
|
|
|
|
""" default: 'default'
|
|
|
|
"""
|
|
|
|
return 'default'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def default_legend(cls):
|
|
|
|
""" default True
|
|
|
|
"""
|
|
|
|
return True
|
|
|
|
|
|
|
|
@classmethod
|
2022-10-28 17:31:37 +00:00
|
|
|
def default_dtype(cls):
|
2022-10-28 11:27:33 +00:00
|
|
|
""" default 'book'
|
|
|
|
"""
|
2022-10-29 21:05:27 +00:00
|
|
|
return 'cashbooks'
|
2022-10-28 11:27:33 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def default_chart(cls):
|
2022-10-28 17:31:37 +00:00
|
|
|
""" default 'pie'
|
2022-10-28 11:27:33 +00:00
|
|
|
"""
|
|
|
|
return 'pie'
|
|
|
|
|
2022-10-29 21:05:27 +00:00
|
|
|
@classmethod
|
|
|
|
def write(cls, *args):
|
|
|
|
""" unlink records if dtype changes
|
|
|
|
"""
|
|
|
|
to_write = []
|
|
|
|
actions = iter(args)
|
|
|
|
for evaluations, values in zip(actions, actions):
|
|
|
|
if 'dtype' in values.keys():
|
|
|
|
for evaluation in evaluations:
|
|
|
|
if evaluation.dtype == values['dtype']:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if (values['dtype'] != 'cashbooks') and \
|
|
|
|
(len(evaluation.cashbooks) > 0):
|
|
|
|
to_write.extend([
|
|
|
|
[evaluation],
|
|
|
|
{
|
|
|
|
'cashbooks': [
|
|
|
|
('remove', [x.id for x in evaluation.cashbooks])
|
|
|
|
],
|
|
|
|
}])
|
|
|
|
|
|
|
|
if (values['dtype'] != 'types') and (len(evaluation.types) > 0):
|
|
|
|
to_write.extend([
|
|
|
|
[evaluation],
|
|
|
|
{
|
|
|
|
'types': [
|
|
|
|
('remove', [x.id for x in evaluation.types])
|
|
|
|
],
|
|
|
|
}])
|
|
|
|
|
|
|
|
if (values['dtype'] != 'currencies') and (len(evaluation.currencies) > 0):
|
|
|
|
to_write.extend([
|
|
|
|
[evaluation],
|
|
|
|
{
|
|
|
|
'currencies': [
|
|
|
|
('remove', [x.id for x in evaluation.currencies])
|
|
|
|
],
|
|
|
|
}])
|
|
|
|
|
|
|
|
args = list(args)
|
|
|
|
args.extend(to_write)
|
|
|
|
super(Evaluation, cls).write(*args)
|
|
|
|
|
2022-10-28 11:27:33 +00:00
|
|
|
# end Evaluation
|
2022-10-28 17:31:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EvaluationCashbookRel(ModelSQL):
|
|
|
|
'Evaluation Cashbook Relation'
|
|
|
|
__name__ = 'cashbook_report.eval_book'
|
|
|
|
|
|
|
|
evaluation = fields.Many2One(string='Evaluation', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='cashbook_report.evaluation')
|
|
|
|
cashbook = fields.Many2One(string='Cashbook', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='cashbook.book')
|
|
|
|
|
2022-10-29 21:05:27 +00:00
|
|
|
@classmethod
|
|
|
|
def validate(cls, records):
|
|
|
|
""" check parent record
|
|
|
|
"""
|
|
|
|
super(EvaluationCashbookRel, cls).validate(records)
|
|
|
|
|
|
|
|
for record in records:
|
|
|
|
if record.evaluation.dtype != 'cashbooks':
|
|
|
|
raise UserError(gettext(
|
|
|
|
'cashbook_report.msg_invalid_dtype',
|
|
|
|
dtype = gettext('cashbook_report.msg_dtype_cashbook'),
|
|
|
|
))
|
|
|
|
|
2022-10-28 17:31:37 +00:00
|
|
|
# end EvaluationCashbookRel
|
2022-10-29 21:05:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EvaluationTypeRel(ModelSQL):
|
|
|
|
'Evaluation Type Relation'
|
|
|
|
__name__ = 'cashbook_report.eval_type'
|
|
|
|
|
|
|
|
evaluation = fields.Many2One(string='Evaluation', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='cashbook_report.evaluation')
|
|
|
|
dtype = fields.Many2One(string='Type', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='cashbook.type')
|
|
|
|
|
|
|
|
# end EvaluationTypeRel
|
|
|
|
|
|
|
|
|
|
|
|
class EvaluationCurrencyRel(ModelSQL):
|
|
|
|
'Evaluation Currency Relation'
|
|
|
|
__name__ = 'cashbook_report.eval_currency'
|
|
|
|
|
|
|
|
evaluation = fields.Many2One(string='Evaluation', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='cashbook_report.evaluation')
|
|
|
|
currency = fields.Many2One(string='Currency', required=True,
|
|
|
|
select=True, ondelete='CASCADE',
|
|
|
|
model_name='currency.currency')
|
|
|
|
|
|
|
|
# end EvaluationCurrencyRel
|