Skip to content

Commit 1fe060c

Browse files
committed
[FIX] fix failure to detect models when CachedModel is missing
CachedModel is not required to define Odoo models, so we should not fail to detect models if CachedModel is not found in the Odoo source code. Treat `Model` and `TransientModel` similarly. only exit if `BaseModel` does not exist.
1 parent acfde92 commit 1fe060c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

server/src/core/python_odoo_builder.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -398,27 +398,22 @@ impl PythonOdooBuilder {
398398
let base_model_syms = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &base_model_tree, u32::MAX);
399399
let model_syms = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &model_tree, u32::MAX);
400400
let transient_syms = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &transient_tree, u32::MAX);
401-
if base_model_syms.is_empty() || model_syms.is_empty() || transient_syms.is_empty() {
402-
//one of them is not already loaded, but that's not really an issue, as now odoo step has been merged
403-
//with arch eval step, some files will be odooed before loading the orm fully. In this case we should
404-
//ignore this error. Moreover if a base is set on the class, it means that the base has been loaded, so
405-
//it is NOT a model.
406-
// session.send_notification(ShowMessage::METHOD, ShowMessageParams{
407-
// typ: MessageType::ERROR,
408-
// message: "Odoo base models are not found. OdooLS will be unable to generate valid diagnostics".to_string()
409-
// });
401+
if base_model_syms.is_empty() {
402+
// base_model_syms empty so sym cannot be a model, otherwise we would have found it earlier
410403
return false;
411404
}
412-
if Rc::ptr_eq(symbol, &base_model_syms[0]) ||
413-
Rc::ptr_eq(symbol, &model_syms[0]) ||
414-
Rc::ptr_eq(symbol, &transient_syms[0])
405+
// Check if the symbol is exactly BaseModel, Model or TransientModel
406+
// BaseModel, Model, or TransientModel are abstract base classes, we don't want to mark them as models
407+
if Rc::ptr_eq(symbol, &base_model_syms[0])
408+
|| model_syms.first().is_some_and(|first| Rc::ptr_eq(symbol, first))
409+
|| transient_syms.first().is_some_and(|first| Rc::ptr_eq(symbol, first))
415410
{
416411
return false;
417412
}
418413
if compare_semver(session.sync_odoo.full_version.as_str(), "19.1") >= Ordering::Equal{
419414
let cached_model_tree = (vec![Sy!("odoo"), Sy!("orm"), Sy!("models_cached")], vec![Sy!("CachedModel")]);
420-
let cached_model = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &cached_model_tree, u32::MAX);
421-
if cached_model.is_empty() || Rc::ptr_eq(symbol, &cached_model[0]){
415+
let cached_model_syms = session.sync_odoo.get_symbol(session.sync_odoo.config.odoo_path.as_ref().unwrap(), &cached_model_tree, u32::MAX);
416+
if cached_model_syms.first().is_some_and(|first| Rc::ptr_eq(symbol, first)){
422417
return false;
423418
}
424419

@@ -427,6 +422,7 @@ impl PythonOdooBuilder {
427422
return false;
428423
}
429424
sym.as_class_sym_mut()._model = Some(ModelData::new());
425+
// Check if we have a _register = False
430426
let register = sym.get_symbol(&(vec![], vec![Sy!("_register")]), u32::MAX);
431427
if let Some(register) = register.last() {
432428
let loc_register = register.borrow();

0 commit comments

Comments
 (0)