cashbook_report/investment.py

131 lines
4.4 KiB
Python

# -*- 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([
('cashbooks_gldiff', gettext('cashbook_report.msg_dtype_cashbook_gldiff')),
('cashbooks_glperc', gettext('cashbook_report.msg_dtype_cashbook_glperc')),
('cashbooks_glvalue', gettext('cashbook_report.msg_dtype_cashbooks_glvalue')),
('category_gldiff', gettext('cashbook_report.msg_dtype_category_gldiff')),
('category_glvalue', gettext('cashbook_report.msg_dtype_category_glvalue')),
('category_glperc', gettext('cashbook_report.msg_dtype_category_glperc')),
])
return result
# end InvestmentEvaluation
class InvestmentLine(metaclass=PoolMeta):
__name__ = 'cashbook_report.eval_line'
def get_value_category_glperc(self):
""" get percentual difference of bookings in categories
converted to currency of evaluation
"""
Book = Pool().get('cashbook.book')
if self.category is None:
return None
books = Book.search([
('state', '=', 'open'),
('categories.id', '=', self.category.id),
])
value = Decimal('0.0')
amount = Decimal('0.0')
if len(books) > 0:
value = sum([x.current_value_ref for x in books])
amount = sum([x.balance_ref for x in books])
if amount != Decimal('0.0'):
return (
Decimal('100.0') * value / amount - Decimal('100.0')
).quantize(Decimal(str(1 / 10 ** self.currency_digits)))
return Decimal('0.0')
def get_value_category_glvalue(self):
""" get current value of bookings in categories
converted to currency of evaluation
"""
Book = Pool().get('cashbook.book')
if self.category is None:
return None
books = Book.search([
('state', '=', 'open'),
('categories.id', '=', self.category.id),
])
result = Decimal('0.0')
if len(books) > 0:
result = sum([x.current_value_ref for x in books])
return result
def get_value_category_gldiff(self):
""" get difference amount of bookings in categories
converted to currency of evaluation
"""
Book = Pool().get('cashbook.book')
if self.category is None:
return None
books = Book.search([
('state', '=', 'open'),
('categories.id', '=', self.category.id),
])
result = Decimal('0.0')
if len(books) > 0:
result = sum([x.current_value_ref - x.balance_ref for x in books])
return result
def get_value_cashbooks_gldiff(self):
""" amount of profit/loss of cashbooks
"""
Currency = Pool().get('currency.currency')
if self.cashbook:
if self.cashbook.feature == 'asset':
exp = Decimal(Decimal(1) / 10 ** self.currency_digits)
return Currency.compute(
self.cashbook.currency,
self.cashbook.diff_amount,
self.eval_currency,
).quantize(exp)
def get_value_cashbooks_glvalue(self):
""" current value of cashbooks
"""
Currency = Pool().get('currency.currency')
if self.cashbook:
if self.cashbook.feature == 'asset':
exp = Decimal(Decimal(1) / 10 ** self.currency_digits)
return Currency.compute(
self.cashbook.currency,
self.cashbook.current_value,
self.eval_currency,
).quantize(exp)
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
# end InvestmentLine