149 lines
5.2 KiB
Python
149 lines
5.2 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
|
|
if (x.current_value_ref is not None) and (x.feature == 'asset')])
|
|
amount = sum([x.balance_ref for x in books
|
|
if (x.balance_ref is not None) and (x.feature == 'asset')])
|
|
if amount != Decimal('0.0'):
|
|
return self.convert_to_evalcurrency(
|
|
books[0].company.currency,
|
|
Decimal('100.0') * value / amount - Decimal('100.0'),
|
|
)
|
|
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:
|
|
for book in books:
|
|
if book.feature == 'asset':
|
|
if book.current_value_ref is not None:
|
|
result += book.current_value_ref
|
|
else :
|
|
if book.balance_ref is not None:
|
|
result += book.balance_ref
|
|
return self.convert_to_evalcurrency(
|
|
books[0].company.currency, result)
|
|
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
|
|
if (x.current_value_ref is not None) and \
|
|
(x.balance_ref is not None) and \
|
|
(x.feature == 'asset')])
|
|
result = self.convert_to_evalcurrency(
|
|
books[0].company.currency, result)
|
|
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':
|
|
return self.convert_to_evalcurrency(
|
|
self.cashbook.currency,
|
|
self.cashbook.diff_amount)
|
|
else :
|
|
return Decimal('0.0')
|
|
|
|
def get_value_cashbooks_glvalue(self):
|
|
""" current value of cashbooks
|
|
"""
|
|
Currency = Pool().get('currency.currency')
|
|
|
|
if self.cashbook:
|
|
if self.cashbook.feature == 'asset':
|
|
return self.convert_to_evalcurrency(
|
|
self.cashbook.currency,
|
|
self.cashbook.current_value)
|
|
else :
|
|
return self.convert_to_evalcurrency(
|
|
self.cashbook.currency,
|
|
self.cashbook.balance_ref)
|
|
|
|
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
|
|
else :
|
|
return Decimal('0.0')
|
|
|
|
# end InvestmentLine
|