Why can't I get uid and domain_force in the tree field attribute, why can I write python

1. Why can't I get the uid in the tree field attribute 

According to the code analyzed before. Know that the field attribute will be parsed in load_view

def transfer_node_to_modifiers(node, modifiers, context=None, in_tree_view=False): 
if node.get('attrs'): 
    #If you want, add more conditions here 
    if ', uid' in node.get('attrs'): 
#这里的uid 是自己加的。这样才可以处理
     user_id = str(context.get('uid', 1)) 
     user_id = ', ' + user_id 
     attrs = node.get('attrs') 
     attrs = attrs.replace(', uid', user_id) 
     node.set('attrs', attrs) 
    modifiers.update(eval(node.get('attrs'))) 

if node.get('states'): 
    if 'invisible' in modifiers and isinstance(modifiers['invisible'], list): 
     # TODO combine with AND or OR, use implicit AND for now. 
     modifiers['invisible'].append(('state', 'not in', node.get('states').split(','))) 
    else: 
     modifiers['invisible'] = [('state', 'not in', node.get('states').split(','))] 

for a in ('invisible', 'readonly', 'required'): 
    if node.get(a): 
     v = bool(eval(node.get(a), {'context': context or {}})) 
     if in_tree_view and a == 'invisible': 
      # Invisible in a tree view has a specific meaning, make it a 
      # new key in the modifiers attribute. 
      modifiers['tree_invisible'] = v 
     elif v or (a not in modifiers or not isinstance(modifiers[a], list)): 
      # Don't set the attribute to False if a dynamic value was 
      # provided (i.e. a domain from attrs or states). 
      modifiers[a] = v 

Because uid is not processed at all in attrs

2. Why user can be used in domain_force but not written in domain

Because domain_force is a field in the rule.

    def _eval_context(self):
        """Returns a dictionary to use as evaluation context for
           ir.rule domains."""
        # use an empty context for 'user' to make the domain evaluation
        # independent from the context
        return {'user': self.env.user.with_context({}), 'time': time}
eval_context 就是 {'user':obj} ,作为参数传入,肯定就可以用user了
dom = safe_eval(rule.domain_force, eval_context) if rule.domain_force else []
dom = expression.normalize_domain(dom)

And domain uses self.env.context only uid as parameter

Can you use any attributes. It mainly depends on what parameters are given after eval

Guess you like

Origin blog.csdn.net/sr50611/article/details/101751643