Skip to content

Commit 8891fb0

Browse files
committed
wip
1 parent 37aeca0 commit 8891fb0

File tree

7 files changed

+67
-37
lines changed

7 files changed

+67
-37
lines changed

server/error_code.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,5 @@ This attribute is not valid in a menuitem node
318318
"Data file should be an XML or a CSV file"
319319

320320
### OLS30446
321-
"XML ID already exists in module"
322-
You have duplicated XML ID in the same module
323-
324-
### OLS30447
325321
"XML ID should not contain more than one dot"
326322
An XML_ID should be in the format 'xml_id' or 'module.xml_id', but can't contains more dots

server/src/core/python_arch_builder_hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static arch_class_hooks: Lazy<Vec<PythonArchClassHook>> = Lazy::new(|| {vec![
108108
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_selection")], vec![Sy!("Selection")])),
109109
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_reference")], vec![Sy!("Reference")])),
110110
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_relational")], vec![Sy!("Many2one")])),
111-
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_relational")], vec![Sy!("Many2oneReference")])),
111+
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_reference")], vec![Sy!("Many2oneReference")])),
112112
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_misc")], vec![Sy!("Json")])),
113113
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_properties")], vec![Sy!("Properties")])),
114114
(Sy!("18.1"), Sy!("999.0"), (vec![Sy!("odoo"), Sy!("orm"), Sy!("fields_properties")], vec![Sy!("PropertiesDefinition")])),

server/src/core/python_arch_eval_hooks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,8 @@ impl PythonArchEvalHooks {
11141114
};
11151115
//TODO => csv xml_id
11161116
//TODO check module dependencies
1117-
//TODO in xml, ref can omit the 'module.' before the xml_id
1118-
//TODO implement base.module_'nameofmodule'
1117+
//TODO in xml ONLY, ref can omit the 'module.' before the xml_id
1118+
//TODO implement base.model_'nameofmodel' - to test
11191119
return None; //TODO implement returned value
11201120
}
11211121

server/src/core/python_odoo_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ impl PythonOdooBuilder {
4949
Some(model) => model.borrow_mut().add_symbol(session, sym.clone()),
5050
None => {
5151
let model = Model::new(model_name.clone(), sym.clone());
52-
sym.borrow().find_module().map(|module| {
52+
session.sync_odoo.modules.get("base").map(|module| {
5353
let xml_id_model_name = oyarn!("model_{}", model_name.replace(".", "_").as_str());
54-
module.borrow_mut().as_module_package_mut().xml_ids.insert(xml_id_model_name, Rc::downgrade(&sym));
54+
module.upgrade().unwrap().borrow_mut().as_module_package_mut().xml_ids.insert(xml_id_model_name, vec![Rc::downgrade(&sym)]);
5555
});
5656
session.sync_odoo.models.insert(model_name.clone(), Rc::new(RefCell::new(model)));
5757
}

server/src/core/symbols/module_symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct ModuleSymbol {
4141
all_depends: HashSet<OYarn>, //computed all depends to avoid too many recomputations
4242
data: Vec<(String, TextRange)>, // TODO
4343
pub module_symbols: HashMap<OYarn, Rc<RefCell<Symbol>>>,
44-
pub xml_ids: HashMap<OYarn, Weak<RefCell<Symbol>>>,
44+
pub xml_ids: HashMap<OYarn, Vec<Weak<RefCell<Symbol>>>>,
4545
pub arch_status: BuildStatus,
4646
pub arch_eval_status: BuildStatus,
4747
pub odoo_status: BuildStatus,

server/src/core/symbols/symbol.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,23 +2477,46 @@ impl Symbol {
24772477

24782478
pub fn is_field_class(&self, session: &mut SessionInfo) -> bool {
24792479
let tree = flatten_tree(&self.get_main_entry_tree(session));
2480-
if tree.len() == 3 && tree[0] == "odoo" && tree[1] == "fields" {
2481-
if matches!(tree[2].as_str(), "Boolean" | "Integer" | "Float" | "Monetary" | "Char" | "Text" | "Html" | "Date" | "Datetime" |
2482-
"Binary" | "Image" | "Selection" | "Reference" | "Json" | "Properties" | "PropertiesDefinition" | "Id" | "Many2one" | "One2many" | "Many2many" | "Many2oneReference") {
2483-
return true;
2480+
if session.sync_odoo.full_version <= S!("18.0") {
2481+
if tree.len() == 3 && tree[0] == "odoo" && tree[1] == "fields" {
2482+
if matches!(tree[2].as_str(), "Boolean" | "Integer" | "Float" | "Monetary" | "Char" | "Text" | "Html" | "Date" | "Datetime" |
2483+
"Binary" | "Image" | "Selection" | "Reference" | "Json" | "Properties" | "PropertiesDefinition" | "Id" | "Many2one" | "One2many" | "Many2many" | "Many2oneReference") {
2484+
return true;
2485+
}
2486+
}
2487+
} else {
2488+
if tree.len() == 4 && tree[0] == "odoo" && tree[1] == "orm" {
2489+
return tree[2] == "fields_misc" && tree[3] == "Boolean" ||
2490+
tree[2] == "fields_numeric" && tree[3] == "Integer" ||
2491+
tree[2] == "fields_numeric" && tree[3] == "Float" ||
2492+
tree[2] == "fields_numeric" && tree[3] == "Monetary" ||
2493+
tree[2] == "fields_textual" && tree[3] == "Char" ||
2494+
tree[2] == "fields_textual" && tree[3] == "Text" ||
2495+
tree[2] == "fields_textual" && tree[3] == "Html" ||
2496+
tree[2] == "fields_temporal" && tree[3] == "Date" ||
2497+
tree[2] == "fields_temporal" && tree[3] == "Datetime" ||
2498+
tree[2] == "fields_binary" && tree[3] == "Binary" ||
2499+
tree[2] == "fields_binary" && tree[3] == "Image" ||
2500+
tree[2] == "fields_selection" && tree[3] == "Selection" ||
2501+
tree[2] == "fields_reference" && tree[3] == "Reference" ||
2502+
tree[2] == "fields_relational" && tree[3] == "Many2one" ||
2503+
tree[2] == "fields_reference" && tree[3] == "Many2oneReference" ||
2504+
tree[2] == "fields_misc" && tree[3] == "Json" ||
2505+
tree[2] == "fields_properties" && tree[3] == "Properties" ||
2506+
tree[2] == "fields_properties" && tree[3] == "PropertiesDefinition" ||
2507+
tree[2] == "fields_relational" && tree[3] == "One2many" ||
2508+
tree[2] == "fields_relational" && tree[3] == "Many2many" ||
2509+
tree[2] == "fields_misc" && tree[3] == "Id";
24842510
}
24852511
}
24862512
false
24872513
}
24882514

24892515
pub fn is_specific_field_class(&self, session: &mut SessionInfo, field_names: &[&str]) -> bool {
24902516
let tree = flatten_tree(&self.get_main_entry_tree(session));
2491-
if tree.len() == 3 && tree[0] == "odoo" && tree[1] == "fields" {
2492-
if field_names.contains(&tree[2].as_str()) {
2493-
return true;
2494-
}
2495-
}
2496-
false
2517+
return self.is_field(session) && field_names.iter().any(|&name| {
2518+
tree.last().unwrap() == name
2519+
})
24972520
}
24982521

24992522
pub fn is_specific_field(&self, session: &mut SessionInfo, field_names: &[&str]) -> bool {

server/src/core/xml_arch_builder.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl XmlArchBuilder {
6363
end: Position::new(node.range().end as u32, 0),
6464
},
6565
Some(DiagnosticSeverity::ERROR),
66-
Some(lsp_types::NumberOrString::String(S!("OLS30445"))),
66+
Some(lsp_types::NumberOrString::String(S!("OLS30446"))),
6767
Some(EXTENSION_NAME.to_string()),
6868
format!("Invalid XML ID '{}'. It should not contain more than one dot", id),
6969
None,
@@ -72,23 +72,34 @@ impl XmlArchBuilder {
7272
return;
7373
}
7474
let id = id_split.last().unwrap().to_string();
75-
let already_exists = module.borrow().as_module_package().xml_ids.contains_key(&Sy!(id.clone()));
76-
if already_exists {
77-
diagnostics.push(Diagnostic::new(
78-
Range {
79-
start: Position::new(node.range().start as u32, 0),
80-
end: Position::new(node.range().end as u32, 0),
81-
},
82-
Some(DiagnosticSeverity::ERROR),
83-
Some(lsp_types::NumberOrString::String(S!("OLS30446"))),
84-
Some(EXTENSION_NAME.to_string()),
85-
format!("XML ID '{}' already exists in module '{}'.", id, module.borrow().as_module_package().name),
86-
None,
87-
None
88-
));
89-
return;
75+
let mut xml_module = module.clone();
76+
if id_split.len() == 2 {
77+
let module_name = id_split.first().unwrap().to_string();
78+
if let Some(m) = session.sync_odoo.modules.get(&module_name) {
79+
xml_module = m.upgrade().unwrap();
80+
}
81+
}
82+
let xml_module_bw = xml_module.borrow();
83+
let already_existing = xml_module_bw.as_module_package().xml_ids.get(&Sy!(id.clone())).cloned();
84+
drop(xml_module_bw);
85+
let mut found_one = false;
86+
if let Some(existing) = already_existing {
87+
//Check that it exists a main xml_id
88+
for s in existing.iter() {
89+
if let Some(s) = s.upgrade() {
90+
if Rc::ptr_eq(&s, &xml_module) {
91+
found_one = true;
92+
break;
93+
}
94+
}
95+
}
96+
} else {
97+
xml_module.borrow_mut().as_module_package_mut().xml_ids.insert(Sy!(id.clone()), vec![]);
98+
}
99+
if !found_one && !Rc::ptr_eq(&xml_module, &module) {
100+
// no diagnostic to create.
90101
}
91-
module.borrow_mut().as_module_package_mut().xml_ids.insert(Sy!(id), Rc::downgrade(&self.xml_symbol));
102+
xml_module.borrow_mut().as_module_package_mut().xml_ids.get_mut(&Sy!(id)).unwrap().push(Rc::downgrade(&self.xml_symbol));
92103
}
93104
}
94105
}

0 commit comments

Comments
 (0)