Skip to content

Commit 4d7516d

Browse files
committed
[IMP] server: hook for 'global' field on IrRule
1 parent 10ffe5f commit 4d7516d

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

server/src/core/evaluation.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,4 +1706,11 @@ impl EvaluationSymbolPtr {
17061706
_ => panic!("Not an EvaluationSymbolWeak")
17071707
}
17081708
}
1709+
1710+
pub(crate) fn as_mut_weak(&mut self) -> &mut EvaluationSymbolWeak {
1711+
match self {
1712+
EvaluationSymbolPtr::WEAK(w) => w,
1713+
_ => panic!("Not an EvaluationSymbolWeak")
1714+
}
1715+
}
17091716
}

server/src/core/python_arch_builder_hooks.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ static arch_class_hooks: Lazy<Vec<PythonArchClassHook>> = Lazy::new(|| {vec![
7272
let _ = symbol.borrow_mut().add_new_variable(session, Sy!("registry"), &range);
7373
}
7474
},
75+
PythonArchClassHook {
76+
odoo_entry: true,
77+
trees: vec![
78+
(Sy!("15.0"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("addons"), Sy!("base"), Sy!("models"), Sy!("ir_rule")], vec![Sy!("IrRule")])),
79+
],
80+
func: |session: &mut SessionInfo, entry_point: &Rc<RefCell<EntryPoint>>, symbol: Rc<RefCell<Symbol>>| {
81+
let mut range = symbol.borrow().range().clone();
82+
// ----------- env.cr ------------
83+
symbol.borrow_mut().add_new_variable(session, Sy!("global"), &range);
84+
}
85+
},
7586
PythonArchClassHook {
7687
odoo_entry: true,
7788
trees: vec![

server/src/core/python_arch_eval_hooks.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,21 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
293293
eval_1.borrow_mut().set_evaluations(vec![Evaluation::eval_from_symbol(&Rc::downgrade(&symbol), Some(false))]);
294294
}
295295
}},
296+
PythonArchEvalFileHook {odoo_entry: true,
297+
trees: vec![(Sy!("15.0"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("addons"), Sy!("base"), Sy!("models"), Sy!("ir_rule")], vec![Sy!("IrRule"), Sy!("global")]))],
298+
if_exist_only: true,
299+
func: |odoo: &mut SyncOdoo, entry: &Rc<RefCell<EntryPoint>>, _file_symbol: Rc<RefCell<Symbol>>, symbol: Rc<RefCell<Symbol>>| {
300+
let mut boolean_field = odoo.get_symbol(_file_symbol.borrow().paths()[0].as_str(), &(vec![Sy!("odoo")], vec![Sy!("fields"), Sy!("Boolean")]), u32::MAX);
301+
if compare_semver(odoo.full_version.as_str(), "18.1") >= Ordering::Equal {
302+
boolean_field = odoo.get_symbol(_file_symbol.borrow().paths()[0].as_str(), &(vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_misc")], vec![Sy!("Boolean")]), u32::MAX); ;
303+
}
304+
if let Some(boolean) = boolean_field.first() {
305+
let mut eval = Evaluation::eval_from_symbol(&Rc::downgrade(&boolean), Some(true));
306+
let weak = eval.symbol.get_mut_symbol_ptr().as_mut_weak();
307+
weak.context.insert(Sy!("compute"), ContextValue::STRING(S!("_compute_global")));
308+
symbol.borrow_mut().set_evaluations(vec![eval]);
309+
}
310+
}},
296311
]});
297312

298313
type PythonArchEvalHookFunc = fn (odoo: &mut SyncOdoo, entry_point: &Rc<RefCell<EntryPoint>>, symbol: Rc<RefCell<Symbol>>);

0 commit comments

Comments
 (0)