book: add caching for line
This commit is contained in:
parent
624a5bff55
commit
39309783b6
5 changed files with 51 additions and 10 deletions
23
line.py
23
line.py
|
@ -16,6 +16,7 @@ from sql.functions import DatePart
|
|||
from sql.conditionals import Case
|
||||
from .book import sel_state_book
|
||||
from .mixin import SecondCurrencyMixin, MemCacheIndexMx
|
||||
from .model import CACHEKEY_CASHBOOK
|
||||
|
||||
|
||||
sel_payee = [
|
||||
|
@ -983,6 +984,8 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
def create(cls, vlist):
|
||||
""" add debit/credit
|
||||
"""
|
||||
MemCache = Pool().get('cashbook.memcache')
|
||||
|
||||
vlist = [x.copy() for x in vlist]
|
||||
for values in vlist:
|
||||
values.update(cls.add_values_from_splitlines(values))
|
||||
|
@ -1003,13 +1006,20 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
'descr': values.get('description', '-'),
|
||||
},
|
||||
))
|
||||
return super(Line, cls).create(vlist)
|
||||
records = super(Line, cls).create(vlist)
|
||||
|
||||
for record in records:
|
||||
for x in record.cashbook.get_cachekeys_by_hierarchy():
|
||||
MemCache.record_update(x, record)
|
||||
return records
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
""" deny update if cashbook.line!='open',
|
||||
add or update debit/credit
|
||||
"""
|
||||
MemCache = Pool().get('cashbook.memcache')
|
||||
|
||||
actions = iter(args)
|
||||
to_write = []
|
||||
for lines, values in zip(actions, actions):
|
||||
|
@ -1056,11 +1066,22 @@ class Line(SecondCurrencyMixin, MemCacheIndexMx, Workflow, ModelSQL, ModelView):
|
|||
|
||||
super(Line, cls).write(*to_write)
|
||||
|
||||
actions = iter(to_write)
|
||||
for records, values in zip(actions, actions):
|
||||
for record in records:
|
||||
for x in record.cashbook.get_cachekeys_by_hierarchy():
|
||||
MemCache.record_update(x, record)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
""" deny delete if book is not 'open' or wf is not 'edit'
|
||||
"""
|
||||
MemCache = Pool().get('cashbook.memcache')
|
||||
|
||||
cls.check_permission_delete(lines)
|
||||
for line in lines:
|
||||
for x in line.cashbook.get_cachekeys_by_hierarchy():
|
||||
MemCache.record_update(x, None)
|
||||
super(Line, cls).delete(lines)
|
||||
|
||||
# end Line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue