remove logging, add trytond.conf-settings
This commit is contained in:
parent
da7fc9cb65
commit
e96aa6fad7
3 changed files with 29 additions and 50 deletions
69
book.py
69
book.py
|
@ -9,18 +9,29 @@ from trytond.pyson import Eval, Or, Len, Bool, If
|
|||
from trytond.modules.cashbook.book import STATES2, DEPENDS2
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.report import Report
|
||||
from trytond.config import config
|
||||
from decimal import Decimal
|
||||
from datetime import timedelta, datetime
|
||||
from datetime import timedelta
|
||||
from sql import Literal
|
||||
from sql.functions import CurrentDate
|
||||
from sql.aggregate import Sum
|
||||
from sql.conditionals import Case, Coalesce
|
||||
from trytond.modules.cashbook.model import sub_ids_hierarchical,\
|
||||
CACHEKEY_CURRENCY, CACHEKEY_CASHBOOK, AnyInArray
|
||||
CACHEKEY_CURRENCY, AnyInArray
|
||||
from .asset import CACHEKEY_ASSETRATE
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# enable/disable caching of cachekey for 'currency.rate'
|
||||
if config.get('cashbook', 'cache_currency', default='yes').lower() in ['yes', '1', 'true']:
|
||||
ENA_CURRKEY = True
|
||||
else :
|
||||
ENA_CURRKEY = False
|
||||
|
||||
# enable/disable caching of cachekey for 'currency.rate'
|
||||
if config.get('cashbook', 'cache_asset', default='yes').lower() in ['yes', '1', 'true']:
|
||||
ENA_ASSETKEY = True
|
||||
else :
|
||||
ENA_ASSETKEY = False
|
||||
|
||||
|
||||
class Book(SymbolMixin, metaclass=PoolMeta):
|
||||
|
@ -276,12 +287,6 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
'yield_sales', 'yield_fee_12m', 'yield_dividend_12m',
|
||||
'yield_sales_12m']}
|
||||
|
||||
logger.warning('## get_yield_data-GO %(time)s %(ids)s %(name)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
'ids': str([x.id for x in cashbooks]),
|
||||
'name': names,
|
||||
})
|
||||
|
||||
def quantize_val(value, digits):
|
||||
""" quantize...
|
||||
"""
|
||||
|
@ -297,30 +302,23 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
query = [{
|
||||
'model': 'cashbook.line',
|
||||
'query': [('cashbook.parent', 'child_of', [x.id])],
|
||||
#'cachekey': CACHEKEY_CASHBOOK % x.id,
|
||||
}, {
|
||||
'model': 'currency.currency.rate',
|
||||
'query': [('currency.id', '=', x.currency.id)],
|
||||
'cachekey': CACHEKEY_CURRENCY % x.currency.id,
|
||||
'cachekey' if ENA_CURRKEY else 'disabled': CACHEKEY_CURRENCY % x.currency.id,
|
||||
}, {
|
||||
'model': 'investment.rate',
|
||||
'query': [('asset.id', '=', x.asset.id)],
|
||||
#'cachekey': CACHEKEY_ASSETRATE % x.asset.id,
|
||||
'cachekey' if ENA_ASSETKEY else 'disabled': CACHEKEY_ASSETRATE % x.asset.id,
|
||||
} if x.asset is not None else {}],
|
||||
addkeys = [query_date.isoformat()])
|
||||
for x in cashbooks
|
||||
}
|
||||
|
||||
logger.warning('## get_yield_data-KEYS %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
# read from cache
|
||||
(todo_cashbook, result) = MemCache.read_from_cache(
|
||||
cashbooks, cache_keys, names, result)
|
||||
if len(todo_cashbook) == 0:
|
||||
logger.warning('## get_yield_data-HIT %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return result
|
||||
|
||||
# results for 'total'
|
||||
|
@ -353,9 +351,6 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
|
||||
# store to cache
|
||||
MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook)
|
||||
logger.warning('## get_yield_data-END %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return {x:result[x] for x in names}
|
||||
|
||||
@classmethod
|
||||
|
@ -446,12 +441,6 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
'digits']
|
||||
}
|
||||
|
||||
logger.warning('## get_asset_quantity-GO %(time)s %(ids)s %(name)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
'ids': str([x.id for x in cashbooks]),
|
||||
'name': names,
|
||||
})
|
||||
|
||||
cache_keys = {
|
||||
x.id: MemCache.get_key_by_record(
|
||||
name = 'get_asset_quantity',
|
||||
|
@ -459,15 +448,14 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
query = [{
|
||||
'model': 'cashbook.line',
|
||||
'query': [('cashbook.parent', 'child_of', [x.id])],
|
||||
#'cachekey': CACHEKEY_CASHBOOK % x.id,
|
||||
}, {
|
||||
'model': 'currency.currency.rate',
|
||||
'query': [('currency.id', '=', x.currency.id)],
|
||||
'cachekey': CACHEKEY_CURRENCY % x.currency.id,
|
||||
'cachekey' if ENA_CURRKEY else 'disabled': CACHEKEY_CURRENCY % x.currency.id,
|
||||
}, {
|
||||
'model': 'investment.rate',
|
||||
'query': [('asset.id', '=', x.asset.id)],
|
||||
#'cachekey': CACHEKEY_ASSETRATE % x.asset.id,
|
||||
'cachekey' if ENA_ASSETKEY else 'disabled': CACHEKEY_ASSETRATE % x.asset.id,
|
||||
} if x.asset is not None else {}],
|
||||
addkeys=[
|
||||
str(company_currency),
|
||||
|
@ -477,15 +465,9 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
}
|
||||
|
||||
# read from cache
|
||||
logger.warning('## get_asset_quantity-KEYS %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
(todo_cashbook, result) = MemCache.read_from_cache(
|
||||
cashbooks, cache_keys, names, result)
|
||||
if len(todo_cashbook) == 0:
|
||||
logger.warning('## get_asset_quantity-HIT %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return result
|
||||
|
||||
def values_from_record(rdata):
|
||||
|
@ -546,10 +528,6 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
for name in values.keys():
|
||||
result[name][book_id] = values[name]
|
||||
|
||||
logger.warning('## get_asset_quantity-PART1 %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
|
||||
# add aggregated values of cashbooks without type
|
||||
aggr_names = ['current_value', 'current_value_ref',
|
||||
'diff_amount', 'diff_percent']
|
||||
|
@ -612,7 +590,7 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
result['digits'][book_id] = record[5]
|
||||
result[name][book_id] += value
|
||||
|
||||
# diff_prcent
|
||||
# diff_percent
|
||||
for id_book in ids_nonebtypes:
|
||||
c_val = result['current_value_ref'][id_book]
|
||||
p_amount = result['purchase_amount_ref'][id_book]
|
||||
|
@ -626,15 +604,8 @@ class Book(SymbolMixin, metaclass=PoolMeta):
|
|||
).quantize(Decimal(str(1/10 ** digits)))
|
||||
result['digits'][id_book] = None
|
||||
|
||||
logger.warning('## get_asset_quantity-PART2 %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
|
||||
# store to cache
|
||||
MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook)
|
||||
logger.warning('## get_asset_quantity-END %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return {x:result[x] for x in names}
|
||||
|
||||
@fields.depends('id')
|
||||
|
|
8
docs/settings.txt
Normal file
8
docs/settings.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
settings in tytond.conf
|
||||
|
||||
[cashbook]
|
||||
# Enables caching of the cache key for asset rates.
|
||||
# Reduces the time required to determine the cache
|
||||
# key for asset values.
|
||||
# default: yes
|
||||
cache_asset = yes
|
2
setup.py
2
setup.py
|
@ -99,7 +99,7 @@ setup(name='%s_%s' % (PREFIX, MODULE),
|
|||
package_data={
|
||||
'trytond.modules.%s' % MODULE: (info.get('xml', [])
|
||||
+ ['tryton.cfg', 'locale/*.po', 'tests/*.py',
|
||||
'view/*.xml',
|
||||
'view/*.xml', 'docs/*.txt',
|
||||
'versiondep.txt', 'README.rst']),
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue