1
1
"""
2
- This file contains tools for making views compatible with Odoo 17. Two main changes are
3
- performed here:
2
+ This file contains tools for making views compatible with Odoo 17.
3
+
4
+ Two main changes are performed here:
4
5
1. Convert `attrs` attributes of view elements from domains into Python expressions.
5
6
2. Remove `states` attribute, merge its logic into `invisible` attribute.
6
7
@@ -43,7 +44,9 @@ def migrate(cr, version):
43
44
44
45
def adapt_view (cr , view_xmlid ):
45
46
"""
46
- Example usage of the utilities in this script.
47
+ Adapt one view.
48
+
49
+ Example usage of the utilities in this file.
47
50
48
51
We use `util.edit_view` because it handles the propagation of the changes to all
49
52
languages while updating the whole arch. Alternatively you could just update specific
@@ -55,7 +58,6 @@ def adapt_view(cr, view_xmlid):
55
58
IrUiView = util.env(cr)["ir.ui.view"].with_context(lang=lang)
56
59
```
57
60
"""
58
-
59
61
vid = util .ref (view_xmlid )
60
62
IrUiView = util .env (cr )["ir.ui.view" ]
61
63
view = IrUiView .browse (vid )
@@ -90,9 +92,7 @@ class InvalidDomainError(Exception):
90
92
91
93
92
94
class Ast2StrVisitor (ast ._Unparser ):
93
- """
94
- Extend standard unparser to allow specific names to be replaced.
95
- """
95
+ """Extend standard unparser to allow specific names to be replaced."""
96
96
97
97
def __init__ (self , replace_names = None ):
98
98
self ._replace_names = replace_names if replace_names else DEFAULT_CONTEXT_REPLACE
@@ -104,7 +104,9 @@ def visit_Name(self, node):
104
104
105
105
def mod2bool_str (s ):
106
106
"""
107
- Convert yes/no/true/false/on/off into True/False strings. Otherwise returns the input unchanged.
107
+ Convert yes/no/true/false/on/off into True/False strings.
108
+
109
+ Otherwise returns the input unchanged.
108
110
The checked values would raise an error instead if used in a Python expression.
109
111
Note that 0 and 1 are left unchanged since they have the same True/False meaning in Python.
110
112
"""
@@ -117,7 +119,7 @@ def mod2bool_str(s):
117
119
118
120
119
121
def _clean_bool (s ):
120
- """Minimal simplification of trivial boolean expressions"""
122
+ """Minimal simplification of trivial boolean expressions. """
121
123
return {
122
124
"(1)" : "1" ,
123
125
"(0)" : "0" ,
@@ -130,7 +132,9 @@ def _clean_bool(s):
130
132
131
133
def target_elem_and_view_type (elem , comb_arch ):
132
134
"""
133
- Find the target of an element. If there is no `comb_arch` or the element doesn't look like
135
+ Find the target of an element.
136
+
137
+ If there is no `comb_arch` or the element doesn't look like
134
138
targeting anything (no position attributes) assume the input `elem` is the target and return it.
135
139
Along with the target we also return the view type of the elem, plus the field path from the
136
140
arch root.
@@ -400,7 +404,8 @@ def fix_attrs(cr, model, arch, comb_arch):
400
404
401
405
def check_true_false (lv , ov , rv_ast ):
402
406
"""
403
- Returns True/False if the leaf (lp, op, rp) is something that can be considered as a True/False leaf.
407
+ Return True/False if the leaf (lp, op, rp) is something that can be considered as a True/False leaf.
408
+
404
409
Otherwise returns None.
405
410
"""
406
411
ov = {"=" : "==" , "<>" : "!=" }.get (ov , ov )
@@ -432,7 +437,9 @@ def ast_term2domain_term(term):
432
437
433
438
def convert_attrs_val (cr , model , field_path , val ):
434
439
"""
435
- Convert an `attrs` value into a python formula. We need to use the AST representation because
440
+ Convert an `attrs` value into a python formula.
441
+
442
+ We need to use the AST representation because
436
443
values representing domains could be:
437
444
* an if, or boolean, expression returning alternative domains
438
445
* a string constant with the domain
@@ -516,6 +523,7 @@ def target_field_type(cr, model, path):
516
523
def convert_domain_leaf (cr , model , field_path , leaf ):
517
524
"""
518
525
Convert a domain leaf (tuple) into a python expression.
526
+
519
527
It always return the expression surrounded by parenthesis such that it's safe to use it as a sub-expression.
520
528
"""
521
529
if isinstance (leaf , bool ):
0 commit comments