Skip to content

Commit 28cb327

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] server: add model dependency on relational fields
1 parent 6a6b654 commit 28cb327

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

server/src/core/python_arch_eval_hooks.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,15 @@ impl PythonArchEvalHooks {
717717
} else {
718718
None
719719
};
720-
if let Some(scope) = scope {
721-
let mut f = scope.borrow_mut();
722-
f.add_model_dependencies(model);
720+
if let Some(scope) = scope
721+
.and_then(|s| s.borrow().get_file())
722+
.and_then(|w| w.upgrade()) {
723+
let env_files = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &(vec![Sy!("odoo"), Sy!("api")], vec![]), u32::MAX);
724+
let env_file = env_files.last().unwrap();
725+
if !Rc::ptr_eq(env_file, &scope) {
726+
let mut f = scope.borrow_mut();
727+
f.add_model_dependencies(model);
728+
}
723729
}
724730
let model = model.clone();
725731
let model = model.borrow();
@@ -876,10 +882,17 @@ impl PythonArchEvalHooks {
876882
None
877883
}
878884

879-
fn eval_relational_with_comodel(session: &mut SessionInfo, comodel: &ContextValue, context: &Context) -> Option<EvaluationSymbolPtr>{
885+
fn eval_relational_with_comodel(session: &mut SessionInfo, comodel: &ContextValue, context: &Context, scope: Option<Rc<RefCell<Symbol>>>) -> Option<EvaluationSymbolPtr>{
880886
let comodel = oyarn!("{}", comodel.as_string());
881887
let comodel_sym = session.sync_odoo.models.get(&comodel).cloned();
882888
if let Some(comodel_sym) = comodel_sym {
889+
// Add dependency
890+
if let Some(scope) = scope
891+
.and_then(|s| s.borrow().get_file())
892+
.and_then(|w| w.upgrade()) {
893+
let mut f = scope.borrow_mut();
894+
f.add_model_dependencies(&comodel_sym);
895+
}
883896
let module = context.get(&S!("module"));
884897
let mut from_module = None;
885898
if let Some(ContextValue::MODULE(m)) = module {
@@ -895,13 +908,13 @@ impl PythonArchEvalHooks {
895908
Some(EvaluationSymbolPtr::WEAK(EvaluationSymbolWeak{weak: Weak::new(), context: HashMap::new(), instance: Some(true), is_super: false}))
896909
}
897910

898-
fn eval_relational(session: &mut SessionInfo, _evaluation_sym: &EvaluationSymbol, context: &mut Option<Context>, _diagnostics: &mut Vec<Diagnostic>, _scope: Option<Rc<RefCell<Symbol>>>) -> Option<EvaluationSymbolPtr>
911+
fn eval_relational(session: &mut SessionInfo, _evaluation_sym: &EvaluationSymbol, context: &mut Option<Context>, _diagnostics: &mut Vec<Diagnostic>, scope: Option<Rc<RefCell<Symbol>>>) -> Option<EvaluationSymbolPtr>
899912
{
900913
let Some(context) = context else {
901914
return None;
902915
};
903916
if let Some(comodel) = context.get(&S!("comodel_name")) {
904-
return PythonArchEvalHooks::eval_relational_with_comodel(session, comodel, context);
917+
return PythonArchEvalHooks::eval_relational_with_comodel(session, comodel, context, scope);
905918
}
906919
if let Some(related_field) = context.get(&S!("related")) {
907920
return PythonArchEvalHooks::eval_relational_with_related(session, related_field, context);

0 commit comments

Comments
 (0)