2023-02-02 22:35:58 +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.pool import PoolMeta, Pool
|
|
|
|
from trytond.i18n import gettext
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
|
|
|
|
class InvestmentEvaluation(metaclass=PoolMeta):
|
|
|
|
__name__ = 'cashbook_report.evaluation'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_sel_etype(cls):
|
|
|
|
""" get list of evaluation-types
|
|
|
|
"""
|
|
|
|
result = super(InvestmentEvaluation, cls).get_sel_etype()
|
|
|
|
result.extend([
|
2023-06-16 12:15:57 +00:00
|
|
|
('cashbooks_gldiff', gettext(
|
2024-01-13 14:08:20 +00:00
|
|
|
'cashbook_report.msg_dtype_cashbooks_gldiff')),
|
2023-06-16 12:15:57 +00:00
|
|
|
('cashbooks_glperc', gettext(
|
2024-01-13 14:08:20 +00:00
|
|
|
'cashbook_report.msg_dtype_cashbooks_glperc')),
|
2023-06-16 12:15:57 +00:00
|
|
|
('cashbooks_glvalue', gettext(
|
|
|
|
'cashbook_report.msg_dtype_cashbooks_glvalue')),
|
|
|
|
('cashbooks_glyield', gettext(
|
|
|
|
'cashbook_report.msg_dtype_cashbooks_glyield')),
|
2024-01-13 14:08:20 +00:00
|
|
|
('categories_gldiff', gettext(
|
|
|
|
'cashbook_report.msg_dtype_categories_gldiff')),
|
|
|
|
('categories_glvalue', gettext(
|
|
|
|
'cashbook_report.msg_dtype_categories_glvalue')),
|
|
|
|
('categories_glperc', gettext(
|
|
|
|
'cashbook_report.msg_dtype_categories_glperc')),
|
|
|
|
('categories_glyield', gettext(
|
|
|
|
'cashbook_report.msg_dtype_categories_glyield')),
|
2023-06-16 12:15:57 +00:00
|
|
|
('types_gldiff', gettext(
|
|
|
|
'cashbook_report.msg_dtype_types_gldiff')),
|
|
|
|
('types_glvalue', gettext(
|
|
|
|
'cashbook_report.msg_dtype_types_glvalue')),
|
|
|
|
('types_glperc', gettext(
|
|
|
|
'cashbook_report.msg_dtype_types_glperc')),
|
|
|
|
('types_glyield', gettext(
|
|
|
|
'cashbook_report.msg_dtype_types_glyield')),
|
2023-02-02 22:35:58 +00:00
|
|
|
])
|
|
|
|
return result
|
|
|
|
|
|
|
|
# end InvestmentEvaluation
|
|
|
|
|
|
|
|
|
|
|
|
class InvestmentLine(metaclass=PoolMeta):
|
|
|
|
__name__ = 'cashbook_report.eval_line'
|
|
|
|
|
2023-02-06 19:22:07 +00:00
|
|
|
def get_percent_by_query(self, query):
|
|
|
|
""" get percentual difference of bookings in categories
|
|
|
|
converted to currency of evaluation
|
|
|
|
"""
|
|
|
|
Book = Pool().get('cashbook.book')
|
|
|
|
|
|
|
|
query2 = [('state', '=', 'open')]
|
|
|
|
query2.extend(query)
|
|
|
|
books = Book.search(query2)
|
|
|
|
|
2023-02-05 13:39:00 +00:00
|
|
|
value = Decimal('0.0')
|
|
|
|
amount = Decimal('0.0')
|
|
|
|
|
|
|
|
if len(books) > 0:
|
2023-06-16 12:15:57 +00:00
|
|
|
value = sum([
|
|
|
|
x.current_value_ref for x in books
|
|
|
|
if (x.current_value_ref is not None)
|
|
|
|
and (x.feature == 'asset')])
|
|
|
|
amount = sum([
|
|
|
|
x.balance_ref for x in books
|
2023-02-05 17:16:49 +00:00
|
|
|
if (x.balance_ref is not None) and (x.feature == 'asset')])
|
|
|
|
if amount != Decimal('0.0'):
|
|
|
|
return self.convert_to_evalcurrency(
|
2023-12-03 16:56:46 +00:00
|
|
|
books[0].company.currency,
|
|
|
|
Decimal('100.0') * value / amount - Decimal('100.0'))
|
2023-02-05 13:39:00 +00:00
|
|
|
return Decimal('0.0')
|
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
def get_difference_by_query(self, query):
|
|
|
|
""" get difference amount of bookings in categories
|
|
|
|
converted to currency of evaluation
|
2023-02-05 13:39:00 +00:00
|
|
|
"""
|
2023-03-10 15:45:50 +00:00
|
|
|
Book = Pool().get('cashbook.book')
|
2023-02-06 19:22:07 +00:00
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
query2 = [('state', '=', 'open')]
|
|
|
|
query2.extend(query)
|
|
|
|
books = Book.search(query2)
|
2023-02-05 13:39:00 +00:00
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
result = Decimal('0.0')
|
|
|
|
if len(books) > 0:
|
2023-06-16 12:15:57 +00:00
|
|
|
result = sum([
|
|
|
|
x.current_value_ref - x.balance_ref for x in books
|
|
|
|
if (x.current_value_ref is not None) and
|
|
|
|
(x.balance_ref is not None) and
|
|
|
|
(x.feature == 'asset')])
|
2023-03-10 15:45:50 +00:00
|
|
|
result = self.convert_to_evalcurrency(
|
|
|
|
books[0].company.currency, result)
|
|
|
|
return result
|
2023-02-06 19:22:07 +00:00
|
|
|
|
|
|
|
def get_currentvalue_by_query(self, query):
|
|
|
|
""" get current value of bookings in categories
|
|
|
|
converted to currency of evaluation
|
|
|
|
"""
|
|
|
|
Book = Pool().get('cashbook.book')
|
|
|
|
|
|
|
|
query2 = [('state', '=', 'open')]
|
|
|
|
query2.extend(query)
|
|
|
|
books = Book.search(query2)
|
|
|
|
|
2023-02-05 13:39:00 +00:00
|
|
|
result = Decimal('0.0')
|
|
|
|
if len(books) > 0:
|
2023-02-05 17:16:49 +00:00
|
|
|
for book in books:
|
2023-03-10 15:45:50 +00:00
|
|
|
if (book.feature == 'asset') or \
|
2023-06-16 12:15:57 +00:00
|
|
|
((book.feature is None) and
|
|
|
|
(book.current_value_ref is not None)):
|
2023-02-05 17:16:49 +00:00
|
|
|
if book.current_value_ref is not None:
|
|
|
|
result += book.current_value_ref
|
2023-06-16 12:15:57 +00:00
|
|
|
else:
|
2023-02-05 17:16:49 +00:00
|
|
|
if book.balance_ref is not None:
|
|
|
|
result += book.balance_ref
|
|
|
|
return self.convert_to_evalcurrency(
|
|
|
|
books[0].company.currency, result)
|
2023-02-05 13:39:00 +00:00
|
|
|
return result
|
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
def get_totalyield_by_query(self, query):
|
|
|
|
""" get total yield of cashbookings
|
|
|
|
converted to currency of evaluation
|
2023-02-05 13:39:00 +00:00
|
|
|
"""
|
2023-03-10 15:45:50 +00:00
|
|
|
Book = Pool().get('cashbook.book')
|
|
|
|
|
|
|
|
query2 = [('state', '=', 'open')]
|
|
|
|
query2.extend(query)
|
|
|
|
books = Book.search(query2)
|
|
|
|
|
|
|
|
result = Decimal('0.0')
|
|
|
|
if len(books) > 0:
|
|
|
|
for book in books:
|
2023-06-16 12:15:57 +00:00
|
|
|
if (book.feature == 'asset') and \
|
|
|
|
(book.yield_balance is not None):
|
2023-03-10 15:45:50 +00:00
|
|
|
result += self.convert_to_evalcurrency(
|
|
|
|
books[0].currency, book.yield_balance)
|
|
|
|
return result
|
|
|
|
|
2024-01-13 14:08:20 +00:00
|
|
|
def get_value_categories_glperc(self):
|
2023-03-10 15:45:50 +00:00
|
|
|
""" get percent of profit/loss by category
|
|
|
|
"""
|
|
|
|
if self.category is None:
|
2023-02-06 19:22:07 +00:00
|
|
|
return None
|
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
return self.get_percent_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('categories.id', '=', self.category.id)])
|
2023-02-05 13:39:00 +00:00
|
|
|
|
2024-01-13 14:08:20 +00:00
|
|
|
def get_value_categories_gldiff(self):
|
2023-02-06 19:22:07 +00:00
|
|
|
""" get difference amount by category
|
|
|
|
"""
|
2023-02-05 13:39:00 +00:00
|
|
|
if self.category is None:
|
|
|
|
return None
|
|
|
|
|
2023-02-06 19:22:07 +00:00
|
|
|
return self.get_difference_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('categories.id', '=', self.category.id)])
|
2023-02-06 19:22:07 +00:00
|
|
|
|
2024-01-13 14:08:20 +00:00
|
|
|
def get_value_categories_glvalue(self):
|
2023-03-10 15:45:50 +00:00
|
|
|
""" get current value by category
|
2023-02-06 19:22:07 +00:00
|
|
|
"""
|
2023-03-10 15:45:50 +00:00
|
|
|
if self.category is None:
|
|
|
|
return None
|
2023-02-06 19:22:07 +00:00
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
return self.get_currentvalue_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('categories.id', '=', self.category.id)])
|
2023-02-06 19:22:07 +00:00
|
|
|
|
2024-01-13 14:08:20 +00:00
|
|
|
def get_value_categories_glyield(self):
|
2023-03-10 15:45:50 +00:00
|
|
|
""" get total yield by type
|
|
|
|
"""
|
|
|
|
if self.category is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self.get_totalyield_by_query([
|
|
|
|
('categories.id', '=', self.category.id),
|
|
|
|
])
|
|
|
|
|
|
|
|
def get_value_types_glperc(self):
|
|
|
|
""" get percent of profit/loss by type
|
|
|
|
"""
|
|
|
|
if self.dtype is None:
|
|
|
|
return None
|
|
|
|
|
2023-12-03 16:56:46 +00:00
|
|
|
return self.get_percent_by_query([('btype.id', '=', self.dtype.id)])
|
2023-03-10 15:45:50 +00:00
|
|
|
|
|
|
|
def get_value_types_gldiff(self):
|
|
|
|
""" get difference amount by type
|
|
|
|
"""
|
|
|
|
if self.dtype is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self.get_difference_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('btype.id', '=', self.dtype.id)])
|
2023-03-10 15:45:50 +00:00
|
|
|
|
|
|
|
def get_value_types_glvalue(self):
|
|
|
|
""" get current value by type
|
|
|
|
"""
|
|
|
|
if self.dtype is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self.get_currentvalue_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('btype.id', '=', self.dtype.id)])
|
2023-03-10 15:45:50 +00:00
|
|
|
|
|
|
|
def get_value_types_glyield(self):
|
|
|
|
""" get total yield by type
|
|
|
|
"""
|
|
|
|
if self.dtype is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self.get_totalyield_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('btype.id', '=', self.dtype.id)])
|
2023-03-10 15:45:50 +00:00
|
|
|
|
|
|
|
def get_value_cashbooks_glperc(self):
|
|
|
|
""" percent of profit/loss of cashbooks
|
|
|
|
"""
|
|
|
|
if self.cashbook:
|
|
|
|
if self.cashbook.feature == 'asset':
|
|
|
|
return self.cashbook.diff_percent
|
2023-06-16 12:15:57 +00:00
|
|
|
else:
|
2023-03-10 15:45:50 +00:00
|
|
|
return Decimal('0.0')
|
2023-02-05 13:39:00 +00:00
|
|
|
|
2023-02-02 22:35:58 +00:00
|
|
|
def get_value_cashbooks_gldiff(self):
|
|
|
|
""" amount of profit/loss of cashbooks
|
|
|
|
"""
|
|
|
|
if self.cashbook:
|
|
|
|
if self.cashbook.feature == 'asset':
|
2023-02-05 17:16:49 +00:00
|
|
|
return self.convert_to_evalcurrency(
|
2023-02-02 22:35:58 +00:00
|
|
|
self.cashbook.currency,
|
2023-02-05 17:16:49 +00:00
|
|
|
self.cashbook.diff_amount)
|
2023-06-16 12:15:57 +00:00
|
|
|
else:
|
2023-02-06 08:32:01 +00:00
|
|
|
return Decimal('0.0')
|
2023-02-02 22:35:58 +00:00
|
|
|
|
|
|
|
def get_value_cashbooks_glvalue(self):
|
|
|
|
""" current value of cashbooks
|
|
|
|
"""
|
|
|
|
if self.cashbook:
|
2023-03-10 15:45:50 +00:00
|
|
|
if (self.cashbook.feature == 'asset') or \
|
2023-06-16 12:15:57 +00:00
|
|
|
((self.cashbook.feature is None) and
|
|
|
|
(self.cashbook.current_value is not None)):
|
2023-02-05 17:16:49 +00:00
|
|
|
return self.convert_to_evalcurrency(
|
2023-02-02 22:35:58 +00:00
|
|
|
self.cashbook.currency,
|
2023-02-05 17:16:49 +00:00
|
|
|
self.cashbook.current_value)
|
2023-06-16 12:15:57 +00:00
|
|
|
else:
|
2023-02-06 08:32:01 +00:00
|
|
|
return self.convert_to_evalcurrency(
|
|
|
|
self.cashbook.currency,
|
2023-03-10 15:45:50 +00:00
|
|
|
self.cashbook.balance)
|
2023-02-02 22:35:58 +00:00
|
|
|
|
2023-03-10 15:45:50 +00:00
|
|
|
def get_value_cashbooks_glyield(self):
|
|
|
|
""" total yield of investment
|
2023-02-02 22:35:58 +00:00
|
|
|
"""
|
|
|
|
if self.cashbook:
|
2023-03-10 15:45:50 +00:00
|
|
|
return self.get_totalyield_by_query([
|
2023-12-03 16:56:46 +00:00
|
|
|
('id', '=', self.cashbook.id)])
|
2023-02-02 22:35:58 +00:00
|
|
|
|
|
|
|
# end InvestmentLine
|