remove logging, add config-settings for caching, add docs
This commit is contained in:
parent
03324d5944
commit
78f160bf0b
6 changed files with 47 additions and 96 deletions
41
book.py
41
book.py
|
@ -10,15 +10,20 @@ from trytond.i18n import gettext
|
|||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool
|
||||
from trytond.report import Report
|
||||
from trytond.config import config
|
||||
from decimal import Decimal
|
||||
from datetime import date, datetime
|
||||
from datetime import date
|
||||
from sql.aggregate import Sum
|
||||
from sql.conditionals import Case
|
||||
from .model import order_name_hierarchical, sub_ids_hierarchical, \
|
||||
AnyInArray, CACHEKEY_CURRENCY, CACHEKEY_CASHBOOK
|
||||
AnyInArray, CACHEKEY_CURRENCY
|
||||
|
||||
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
|
||||
|
||||
|
||||
STATES = {
|
||||
|
@ -265,16 +270,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
}
|
||||
return recname
|
||||
|
||||
# ~ def get_cachekeys_by_hierarchy(self):
|
||||
# ~ """ generate keys for all cashbooks above us
|
||||
# ~ """
|
||||
# ~ CBook = Pool().get('cashbook.book')
|
||||
|
||||
# ~ return [CACHEKEY_CASHBOOK % x.id
|
||||
# ~ for x in CBook.search([
|
||||
# ~ ('parent', 'parent_of', [self.id]),
|
||||
# ~ ], order=[('id', 'ASC')])]
|
||||
|
||||
@classmethod
|
||||
def get_balance_of_cashbook_sql(cls):
|
||||
""" sql for balance of a single cashbook
|
||||
|
@ -365,12 +360,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
cursor = Transaction().connection.cursor()
|
||||
context = Transaction().context
|
||||
|
||||
logger.warning('## get_balance_cashbook-GO %(time)s %(ids)s %(name)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
'ids': str([x.id for x in cashbooks]),
|
||||
'name': names,
|
||||
})
|
||||
|
||||
result = {
|
||||
x:{y.id: Decimal('0.0') for y in cashbooks}
|
||||
for x in ['balance', 'balance_all', 'balance_ref']}
|
||||
|
@ -390,26 +379,19 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
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,
|
||||
}, ],
|
||||
addkeys = [query_date.isoformat()])
|
||||
for x in cashbooks
|
||||
}
|
||||
|
||||
# read from cache
|
||||
logger.warning('## get_balance_cashbook-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_balance_cashbook-HIT %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return result
|
||||
|
||||
# query balances of cashbooks and sub-cashbooks
|
||||
|
@ -446,9 +428,6 @@ class Book(tree(separator='/'), Workflow, ModelSQL, ModelView):
|
|||
record[2], record[5], record[3])
|
||||
|
||||
MemCache.store_result(cashbooks, cache_keys, result, todo_cashbook)
|
||||
logger.warning('## get_balance_cashbook-END %(time)s' % {
|
||||
'time': datetime.now().isoformat(),
|
||||
})
|
||||
return result
|
||||
|
||||
@fields.depends('btype')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue