为什么有些规则似乎随机起作用?如何调试当前满足哪些规则?
Why do some rules seem to work randomly? How to debug which rules are currently satisfied?
我遇到了一些 rules 的问题。有些规则今天有效,但第二天就失效了。
我考虑到规则不会影响管理员用户。
我想知道是否可以在 ir.rule
模型中打印记录器消息以检查当前满足哪些规则域。我正在看模型方法,但我不确定在哪里写它。
好吧,我必须在加载每个视图时在记录器中写入计算域:
def clear_cache(self, cr, uid):
_logger.warning('-- CACHE CLEARED')
self._compute_domain.clear_cache(self)
def domain_get(self, cr, uid, model_name, mode='read', context=None):
dom = self._compute_domain(cr, uid, model_name, mode)
if dom:
# _where_calc is called as superuser. This means that rules can
# involve objects on which the real uid has no acces rights.
# This means also there is no implicit restriction (e.g. an object
# references another object the user can't see).
_logger.warning('>> MODEL NAME: {}'.format(model_name))
_logger.warning('>> COMPUTED DOMAIN: {}'.format(dom))
query = self.pool[model_name]._where_calc(cr, SUPERUSER_ID, dom, active_test=False)
return query.where_clause, query.where_clause_params, query.tables
return [], [], ['"' + self.pool[model_name]._table + '"']
我意识到只有当它们不在缓存中时才会计算它们。当我更新模块时,缓存被清除。但我还是不知道为什么有时候规则不怎么管用。
我遇到了一些 rules 的问题。有些规则今天有效,但第二天就失效了。
我考虑到规则不会影响管理员用户。
我想知道是否可以在 ir.rule
模型中打印记录器消息以检查当前满足哪些规则域。我正在看模型方法,但我不确定在哪里写它。
好吧,我必须在加载每个视图时在记录器中写入计算域:
def clear_cache(self, cr, uid):
_logger.warning('-- CACHE CLEARED')
self._compute_domain.clear_cache(self)
def domain_get(self, cr, uid, model_name, mode='read', context=None):
dom = self._compute_domain(cr, uid, model_name, mode)
if dom:
# _where_calc is called as superuser. This means that rules can
# involve objects on which the real uid has no acces rights.
# This means also there is no implicit restriction (e.g. an object
# references another object the user can't see).
_logger.warning('>> MODEL NAME: {}'.format(model_name))
_logger.warning('>> COMPUTED DOMAIN: {}'.format(dom))
query = self.pool[model_name]._where_calc(cr, SUPERUSER_ID, dom, active_test=False)
return query.where_clause, query.where_clause_params, query.tables
return [], [], ['"' + self.pool[model_name]._table + '"']
我意识到只有当它们不在缓存中时才会计算它们。当我更新模块时,缓存被清除。但我还是不知道为什么有时候规则不怎么管用。