Browse Source

publish muk_web_client_refresh - 12.0

12.0
MuK IT GmbH 5 years ago
parent
commit
8a0271fe34
  1. 2
      muk_web_client_refresh/__manifest__.py
  2. 45
      muk_web_client_refresh/models/ir_actions.py

2
muk_web_client_refresh/__manifest__.py

@ -23,7 +23,7 @@
{ {
"name": "MuK Web Refresh", "name": "MuK Web Refresh",
"summary": """Web Client Refresh""", "summary": """Web Client Refresh""",
"version": "12.0.3.0.3",
"version": "12.0.3.0.4",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"website": "http://www.mukit.at", "website": "http://www.mukit.at",

45
muk_web_client_refresh/models/ir_actions.py

@ -26,9 +26,14 @@ from odoo import api, models, fields
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
REFRESH_BEAT = 55
class ServerActions(models.Model): class ServerActions(models.Model):
_inherit = 'ir.actions.server' _inherit = 'ir.actions.server'
_last_refresh_timestamp = defaultdict(lambda: None)
_in_memory_refresh = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
#---------------------------------------------------------- #----------------------------------------------------------
# Database # Database
@ -40,15 +45,39 @@ class ServerActions(models.Model):
#---------------------------------------------------------- #----------------------------------------------------------
# Functions # Functions
#---------------------------------------------------------- #----------------------------------------------------------
@api.model @api.model
def run_action_refresh_multi(self, action, eval_context={}): def run_action_refresh_multi(self, action, eval_context={}):
if not self.env.context.get('refresh_disable', False):
if not self.env.context.get('refresh_disable', False) and \
self.env.recompute and self.env.context.get('recompute', True):
cls = type(self)
dbname = self.env.cr.dbname
now_timestamp = datetime.now()
now_delta = now_timestamp - timedelta(seconds=REFRESH_BEAT)
old_timestamp = cls._last_refresh_timestamp[dbname]
record = eval_context.get('record', None) record = eval_context.get('record', None)
records = eval_context.get('records', None) records = eval_context.get('records', None)
self.env['bus.bus'].sendone('refresh', {
'uid': self.env.uid,
'model': action.model_name,
'ids': list(set().union(record and record.ids or [], records and records.ids or [])),
'create': record and record._log_access and record.exists() and record.create_date == record.write_date,
})
if record and record._log_access and record.create_date == record.write_date:
cls._in_memory_refresh[dbname][action.model_name][self.env.uid].add(True)
else:
cls._in_memory_refresh[dbname][action.model_name][self.env.uid].update(record and record.ids or [])
cls._in_memory_refresh[dbname][action.model_name][self.env.uid].update(records and records.ids or [])
if not old_timestamp or old_timestamp < now_delta:
cls._last_refresh_timestamp[dbname] = now_timestamp
for model, data in cls._in_memory_refresh[dbname].items():
for user, ids in data.items():
create = False
if True in ids:
ids.remove(True)
create = True
self.env['bus.bus'].sendone('refresh', {
'uid': user,
'model': model,
'ids': list(ids),
'create': create,
})
cls._in_memory_refresh = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
Loading…
Cancel
Save