Skip to content

Commit 24f3d01

Browse files
committed
[IMP] server: 18.2+: hooks for doo.Command, odoo._, odoo._lt, odoo.SUPERUSER_ID
1 parent b045c9d commit 24f3d01

File tree

2 files changed

+152
-9
lines changed

2 files changed

+152
-9
lines changed

server/src/core/python_arch_builder_hooks.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::cell::RefCell;
44
use tracing::warn;
55
use crate::core::symbols::symbol::Symbol;
66
use crate::threads::SessionInfo;
7-
use crate::{Sy, S};
7+
use crate::{oyarn, Sy, S};
88
use crate::constants::OYarn;
99

1010
use super::odoo::SyncOdoo;
@@ -90,6 +90,13 @@ impl PythonArchBuilderHooks {
9090
session.sync_odoo.need_rebuild = true;
9191
}
9292
}
93+
} else if session.sync_odoo.full_version > S!("18.0.0") && name == "init" {
94+
if symbol.borrow().get_main_entry_tree(session) == (vec![Sy!("odoo"), Sy!("init")], vec![]) {
95+
symbol.borrow_mut().parent().unwrap().upgrade().unwrap().borrow_mut().add_new_variable(session, oyarn!("SUPERUSER_ID"), &symbol.borrow().range());
96+
symbol.borrow_mut().parent().unwrap().upgrade().unwrap().borrow_mut().add_new_variable(session, oyarn!("_"), &symbol.borrow().range());
97+
symbol.borrow_mut().parent().unwrap().upgrade().unwrap().borrow_mut().add_new_variable(session, oyarn!("_lt"), &symbol.borrow().range());
98+
symbol.borrow_mut().parent().unwrap().upgrade().unwrap().borrow_mut().add_new_variable(session, oyarn!("Command"), &symbol.borrow().range());
99+
}
93100
}
94101
}
95102
}

server/src/core/python_arch_eval_hooks.rs

+144-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type PythonArchEvalHookFile = fn (odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryP
2929

3030
pub struct PythonArchEvalFileHook {
3131
pub odoo_entry: bool,
32+
pub min_version: String,
33+
pub max_version: String,
3234
pub file_tree: Vec<OYarn>,
3335
pub content_tree: Vec<OYarn>, //if set, will provide symbol in file content instead of the file symbol to func
3436
pub if_exist_only: bool,
@@ -37,6 +39,96 @@ pub struct PythonArchEvalFileHook {
3739

3840
static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {vec![
3941
PythonArchEvalFileHook {odoo_entry: true,
42+
min_version: S!("18.2.0"),
43+
max_version: S!("9999.0.0"),
44+
file_tree: vec![Sy!("odoo"), Sy!("init")],
45+
content_tree: vec![Sy!("SUPERUSER_ID")],
46+
if_exist_only: true,
47+
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
48+
let superuser_id = file_symbol.borrow().parent().unwrap().upgrade().unwrap().borrow().get_symbol(&(vec![], vec![Sy!("SUPERUSER_ID")]), u32::MAX);
49+
if superuser_id.len() == 1 {
50+
let superuser_id = superuser_id.last().unwrap();
51+
symbol.borrow_mut().set_evaluations(vec![Evaluation {
52+
symbol: EvaluationSymbol::new_with_symbol(
53+
Rc::downgrade(superuser_id),
54+
Some(true),
55+
HashMap::new(),
56+
None
57+
),
58+
value: None,
59+
range: None
60+
}]);
61+
}
62+
}},
63+
PythonArchEvalFileHook {odoo_entry: true,
64+
min_version: S!("18.2.0"),
65+
max_version: S!("9999.0.0"),
66+
file_tree: vec![Sy!("odoo"), Sy!("init")],
67+
content_tree: vec![Sy!("_")],
68+
if_exist_only: true,
69+
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
70+
let superuser_id = file_symbol.borrow().parent().unwrap().upgrade().unwrap().borrow().get_symbol(&(vec![], vec![Sy!("_")]), u32::MAX);
71+
if superuser_id.len() == 1 {
72+
let superuser_id = superuser_id.last().unwrap();
73+
symbol.borrow_mut().set_evaluations(vec![Evaluation {
74+
symbol: EvaluationSymbol::new_with_symbol(
75+
Rc::downgrade(superuser_id),
76+
Some(true),
77+
HashMap::new(),
78+
None
79+
),
80+
value: None,
81+
range: None
82+
}]);
83+
}
84+
}},
85+
PythonArchEvalFileHook {odoo_entry: true,
86+
min_version: S!("18.2.0"),
87+
max_version: S!("9999.0.0"),
88+
file_tree: vec![Sy!("odoo"), Sy!("init")],
89+
content_tree: vec![Sy!("_lt")],
90+
if_exist_only: true,
91+
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
92+
let superuser_id = file_symbol.borrow().parent().unwrap().upgrade().unwrap().borrow().get_symbol(&(vec![], vec![Sy!("_lt")]), u32::MAX);
93+
if superuser_id.len() == 1 {
94+
let superuser_id = superuser_id.last().unwrap();
95+
symbol.borrow_mut().set_evaluations(vec![Evaluation {
96+
symbol: EvaluationSymbol::new_with_symbol(
97+
Rc::downgrade(superuser_id),
98+
Some(true),
99+
HashMap::new(),
100+
None
101+
),
102+
value: None,
103+
range: None
104+
}]);
105+
}
106+
}},
107+
PythonArchEvalFileHook {odoo_entry: true,
108+
min_version: S!("18.2.0"),
109+
max_version: S!("9999.0.0"),
110+
file_tree: vec![Sy!("odoo"), Sy!("init")],
111+
content_tree: vec![Sy!("Command")],
112+
if_exist_only: true,
113+
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
114+
let superuser_id = file_symbol.borrow().parent().unwrap().upgrade().unwrap().borrow().get_symbol(&(vec![], vec![Sy!("Command")]), u32::MAX);
115+
if superuser_id.len() == 1 {
116+
let superuser_id = superuser_id.last().unwrap();
117+
symbol.borrow_mut().set_evaluations(vec![Evaluation {
118+
symbol: EvaluationSymbol::new_with_symbol(
119+
Rc::downgrade(superuser_id),
120+
Some(true),
121+
HashMap::new(),
122+
None
123+
),
124+
value: None,
125+
range: None
126+
}]);
127+
}
128+
}},
129+
PythonArchEvalFileHook {odoo_entry: true,
130+
min_version: S!("16.0.0"),
131+
max_version: S!("9999.0.0"),
40132
file_tree: vec![Sy!("odoo"), Sy!("models")],
41133
content_tree: vec![Sy!("BaseModel"), Sy!("env")],
42134
if_exist_only: true,
@@ -62,6 +154,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
62154
}
63155
}},
64156
PythonArchEvalFileHook {odoo_entry: true,
157+
min_version: S!("16.0.0"),
158+
max_version: S!("9999.0.0"),
65159
file_tree: vec![Sy!("odoo"), Sy!("models")],
66160
content_tree: vec![Sy!("BaseModel"), Sy!("ids")],
67161
if_exist_only: true,
@@ -81,6 +175,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
81175
id.set_evaluations(vec![Evaluation::eval_from_symbol(odoo, values, range.clone())]);
82176
}},*/
83177
PythonArchEvalFileHook {odoo_entry: true,
178+
min_version: S!("16.0.0"),
179+
max_version: S!("9999.0.0"),
84180
file_tree: vec![Sy!("odoo"), Sy!("api")],
85181
content_tree: vec![Sy!("Environment"), Sy!("registry")],
86182
if_exist_only: true,
@@ -101,6 +197,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
101197
}},
102198
/* As __get__ doesn't exists in each class, the validator will not trigger hooks for them at function level, so we put it at file level. */
103199
PythonArchEvalFileHook {odoo_entry: true,
200+
min_version: S!("16.0.0"),
201+
max_version: S!("9999.0.0"),
104202
file_tree: vec![Sy!("odoo"), Sy!("fields")],
105203
content_tree: vec![Sy!("Boolean")],
106204
if_exist_only: true,
@@ -109,6 +207,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
109207
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
110208
}},
111209
PythonArchEvalFileHook {odoo_entry: true,
210+
min_version: S!("16.0.0"),
211+
max_version: S!("9999.0.0"),
112212
file_tree: vec![Sy!("odoo"), Sy!("fields")],
113213
content_tree: vec![Sy!("Integer")],
114214
if_exist_only: true,
@@ -117,6 +217,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
117217
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
118218
}},
119219
PythonArchEvalFileHook {odoo_entry: true,
220+
min_version: S!("16.0.0"),
221+
max_version: S!("9999.0.0"),
120222
file_tree: vec![Sy!("odoo"), Sy!("fields")],
121223
content_tree: vec![Sy!("Float")],
122224
if_exist_only: true,
@@ -125,6 +227,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
125227
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
126228
}},
127229
PythonArchEvalFileHook {odoo_entry: true,
230+
min_version: S!("16.0.0"),
231+
max_version: S!("9999.0.0"),
128232
file_tree: vec![Sy!("odoo"), Sy!("fields")],
129233
content_tree: vec![Sy!("Monetary")],
130234
if_exist_only: true,
@@ -133,6 +237,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
133237
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
134238
}},
135239
PythonArchEvalFileHook {odoo_entry: true,
240+
min_version: S!("16.0.0"),
241+
max_version: S!("9999.0.0"),
136242
file_tree: vec![Sy!("odoo"), Sy!("fields")],
137243
content_tree: vec![Sy!("Char")],
138244
if_exist_only: true,
@@ -141,6 +247,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
141247
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
142248
}},
143249
PythonArchEvalFileHook {odoo_entry: true,
250+
min_version: S!("16.0.0"),
251+
max_version: S!("9999.0.0"),
144252
file_tree: vec![Sy!("odoo"), Sy!("fields")],
145253
content_tree: vec![Sy!("Text")],
146254
if_exist_only: true,
@@ -149,6 +257,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
149257
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
150258
}},
151259
PythonArchEvalFileHook {odoo_entry: true,
260+
min_version: S!("16.0.0"),
261+
max_version: S!("9999.0.0"),
152262
file_tree: vec![Sy!("odoo"), Sy!("fields")],
153263
content_tree: vec![Sy!("Html")],
154264
if_exist_only: true,
@@ -157,6 +267,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
157267
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
158268
}},
159269
PythonArchEvalFileHook {odoo_entry: true,
270+
min_version: S!("16.0.0"),
271+
max_version: S!("9999.0.0"),
160272
file_tree: vec![Sy!("odoo"), Sy!("fields")],
161273
content_tree: vec![Sy!("Date")],
162274
if_exist_only: true,
@@ -165,6 +277,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
165277
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
166278
}},
167279
PythonArchEvalFileHook {odoo_entry: true,
280+
min_version: S!("16.0.0"),
281+
max_version: S!("9999.0.0"),
168282
file_tree: vec![Sy!("odoo"), Sy!("fields")],
169283
content_tree: vec![Sy!("Datetime")],
170284
if_exist_only: true,
@@ -173,6 +287,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
173287
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
174288
}},
175289
PythonArchEvalFileHook {odoo_entry: true,
290+
min_version: S!("16.0.0"),
291+
max_version: S!("9999.0.0"),
176292
file_tree: vec![Sy!("odoo"), Sy!("fields")],
177293
content_tree: vec![Sy!("Binary")],
178294
if_exist_only: true,
@@ -181,6 +297,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
181297
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
182298
}},
183299
PythonArchEvalFileHook {odoo_entry: true,
300+
min_version: S!("16.0.0"),
301+
max_version: S!("9999.0.0"),
184302
file_tree: vec![Sy!("odoo"), Sy!("fields")],
185303
content_tree: vec![Sy!("Image")],
186304
if_exist_only: true,
@@ -189,6 +307,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
189307
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
190308
}},
191309
PythonArchEvalFileHook {odoo_entry: true,
310+
min_version: S!("16.0.0"),
311+
max_version: S!("9999.0.0"),
192312
file_tree: vec![Sy!("odoo"), Sy!("fields")],
193313
content_tree: vec![Sy!("Selection")],
194314
if_exist_only: true,
@@ -197,6 +317,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
197317
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
198318
}},
199319
PythonArchEvalFileHook {odoo_entry: true,
320+
min_version: S!("16.0.0"),
321+
max_version: S!("9999.0.0"),
200322
file_tree: vec![Sy!("odoo"), Sy!("fields")],
201323
content_tree: vec![Sy!("Reference")],
202324
if_exist_only: true,
@@ -205,6 +327,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
205327
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
206328
}},
207329
PythonArchEvalFileHook {odoo_entry: true,
330+
min_version: S!("16.0.0"),
331+
max_version: S!("9999.0.0"),
208332
file_tree: vec![Sy!("odoo"), Sy!("fields")],
209333
content_tree: vec![Sy!("Json")],
210334
if_exist_only: true,
@@ -213,6 +337,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
213337
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
214338
}},
215339
PythonArchEvalFileHook {odoo_entry: true,
340+
min_version: S!("16.0.0"),
341+
max_version: S!("9999.0.0"),
216342
file_tree: vec![Sy!("odoo"), Sy!("fields")],
217343
content_tree: vec![Sy!("Properties")],
218344
if_exist_only: true,
@@ -221,6 +347,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
221347
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
222348
}},
223349
PythonArchEvalFileHook {odoo_entry: true,
350+
min_version: S!("16.0.0"),
351+
max_version: S!("9999.0.0"),
224352
file_tree: vec![Sy!("odoo"), Sy!("fields")],
225353
content_tree: vec![Sy!("PropertiesDefinition")],
226354
if_exist_only: true,
@@ -229,6 +357,8 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
229357
PythonArchEvalHooks::_update_field_init(symbol.clone(), false);
230358
}},
231359
PythonArchEvalFileHook {odoo_entry: true,
360+
min_version: S!("16.0.0"),
361+
max_version: S!("9999.0.0"),
232362
file_tree: vec![Sy!("odoo"), Sy!("fields")],
233363
content_tree: vec![Sy!("Many2one")],
234364
if_exist_only: true,
@@ -237,13 +367,17 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
237367
PythonArchEvalHooks::_update_field_init(symbol.clone(), true);
238368
}},
239369
PythonArchEvalFileHook {odoo_entry: true,
370+
min_version: S!("16.0.0"),
371+
max_version: S!("9999.0.0"),
240372
file_tree: vec![Sy!("odoo"), Sy!("fields")],
241373
content_tree: vec![Sy!("One2many")],
242374
if_exist_only: true,
243375
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, _file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
244376
PythonArchEvalHooks::_update_field_init(symbol.clone(), true);
245377
}},
246378
PythonArchEvalFileHook {odoo_entry: true,
379+
min_version: S!("16.0.0"),
380+
max_version: S!("9999.0.0"),
247381
file_tree: vec![Sy!("odoo"), Sy!("fields")],
248382
content_tree: vec![Sy!("Many2many")],
249383
if_exist_only: true,
@@ -397,14 +531,16 @@ impl PythonArchEvalHooks {
397531
let odoo_tree = symbol.borrow().get_main_entry_tree(session);
398532
let name = symbol.borrow().name().clone();
399533
for hook in arch_eval_file_hooks.iter() {
400-
if name.eq(hook.file_tree.last().unwrap()) {
401-
if (hook.odoo_entry && session.sync_odoo.has_main_entry && odoo_tree.0 == hook.file_tree) || (!hook.odoo_entry && tree.0 == hook.file_tree) {
402-
if hook.content_tree.is_empty() {
403-
(hook.func)(session.sync_odoo, entry_point, symbol.clone(), symbol.clone());
404-
} else {
405-
let sub_symbol = symbol.borrow().get_symbol(&(vec![], hook.content_tree.clone()), u32::MAX);
406-
if !sub_symbol.is_empty() {
407-
(hook.func)(session.sync_odoo, entry_point, symbol.clone(), sub_symbol.last().unwrap().clone());
534+
if session.sync_odoo.full_version >= hook.min_version && session.sync_odoo.full_version <= hook.max_version {
535+
if name.eq(hook.file_tree.last().unwrap()) {
536+
if (hook.odoo_entry && session.sync_odoo.has_main_entry && odoo_tree.0 == hook.file_tree) || (!hook.odoo_entry && tree.0 == hook.file_tree) {
537+
if hook.content_tree.is_empty() {
538+
(hook.func)(session.sync_odoo, entry_point, symbol.clone(), symbol.clone());
539+
} else {
540+
let sub_symbol = symbol.borrow().get_symbol(&(vec![], hook.content_tree.clone()), u32::MAX);
541+
if !sub_symbol.is_empty() {
542+
(hook.func)(session.sync_odoo, entry_point, symbol.clone(), sub_symbol.last().unwrap().clone());
543+
}
408544
}
409545
}
410546
}

0 commit comments

Comments
 (0)