Skip to content

Commit 2688306

Browse files
committed
[FIX] Do not load models if they are declared in a function
1 parent 3ee0af2 commit 2688306

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

server/src/core/diagnostic_codes_list.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ OLS03022, DiagnosticSetting::Error, "Inverse field is not a Many2one field",
172172
* -> current_model is not right
173173
*/
174174
OLS03023, DiagnosticSetting::Error, "Inverse field {0} is not pointing to the current model {1}, but rather to {2}",
175+
/**
176+
* Models declared in a function are not supported by OdooLS. This info is indicating that no features will be enabled for this model.
177+
*/
178+
OLS03024, DiagnosticSetting::Info, "Models declared in a function are not supported by OdooLS. OdooLS will use it as a normal class for the rest of the function only",
175179
/**
176180
* Form is no longer available on odoo.tests.common, thus it should not be imported from there.
177181
*/

server/src/core/python_arch_eval.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,17 @@ impl PythonArchEval {
711711
self.visit_sub_stmts(session, &class_stmt.body);
712712
self.sym_stack.pop();
713713
if !self.sym_stack[0].borrow().is_external() && self.sym_stack[0].borrow().get_entry().is_some_and(|e| e.borrow().typ == EntryPointType::MAIN) {
714-
let odoo_builder_diags = PythonOdooBuilder::new(class_sym_rc).load(session);
715-
self.diagnostics.extend(odoo_builder_diags);
714+
if class_sym_rc.borrow().get_in_parents(&vec![SymType::FUNCTION], true).is_some() {
715+
if let Some(diagnostic) = create_diagnostic(&session, DiagnosticCode::OLS03024, &[]) {
716+
self.diagnostics.push(Diagnostic {
717+
range: FileMgr::textRange_to_temporary_Range(&class_stmt.name.range),
718+
..diagnostic
719+
});
720+
}
721+
} else {
722+
let odoo_builder_diags = PythonOdooBuilder::new(class_sym_rc).load(session);
723+
self.diagnostics.extend(odoo_builder_diags);
724+
}
716725
}
717726
session.current_noqa = old_noqa;
718727
}

0 commit comments

Comments
 (0)