@@ -56,17 +56,21 @@ def _validate_dotted_path(self):
5656 return True # Not a dotted path or empty, considered valid
5757
5858 # Get the model from the parent report form
59+ if (
60+ not self .report_form_id
61+ or not self .report_form_id .model_id
62+ or not self .report_form_id .model_id .model
63+ ):
64+ return True # Model not available yet, skip validation during creation
5965 model_name = self .report_form_id .model_id .model
60- if not model_name :
61- return False
66+ if not model_name or model_name not in self . env :
67+ return True # Model not set or not in registry, skip validation
6268
6369 # Split the dotted path
6470 path_parts = self .odoo_field_value .split ("." )
6571
6672 # Start with the base model
6773 current_model = self .env [model_name ]
68- if not current_model :
69- return False
7074
7175 # Traverse the path
7276 for i , field_name in enumerate (path_parts ):
@@ -78,9 +82,9 @@ def _validate_dotted_path(self):
7882 if field .type not in ["many2one" , "one2many" , "many2many" ]:
7983 return False # Can't traverse further on non-relation field
8084 # Move to the related model
85+ if not field .comodel_name or field .comodel_name not in self .env :
86+ return False # comodel not found
8187 current_model = self .env [field .comodel_name ]
82- if not current_model :
83- return False
8488
8589 return True
8690
@@ -94,18 +98,19 @@ def action_validate_field(self):
9498 "tag" : "display_notification" ,
9599 "params" : {
96100 "title" : "Success" ,
97- "message" : f'The dotted path "{ self .odoo_field_value } " is valid.' ,
101+ "message" : self .env ._ ('The dotted path "%(path)s" is valid.' )
102+ % {"path" : self .odoo_field_value },
98103 "type" : "success" ,
99104 "sticky" : False ,
100105 },
101106 }
102107 else :
103108 message = self .env ._ (
104- 'The dotted path "{ path} " is invalid for model "{ model} ".'
105- ). format (
106- path = self .odoo_field_value ,
107- model = self .report_form_id .model_id .name ,
108- )
109+ 'The dotted path "%( path)s " is invalid for model "%( model)s ".'
110+ ) % {
111+ " path" : self .odoo_field_value ,
112+ " model" : self .report_form_id .model_id .name ,
113+ }
109114 return {
110115 "type" : "ir.actions.client" ,
111116 "tag" : "display_notification" ,
@@ -120,11 +125,20 @@ def action_validate_field(self):
120125 @api .constrains ("odoo_field_evaluation" , "odoo_field_value" , "report_form_id" )
121126 def _check_dotted_path (self ):
122127 for record in self :
128+ # Skip validation if model is not available (during creation/updates)
129+ if (
130+ not record .report_form_id
131+ or not record .report_form_id .model_id
132+ or not record .report_form_id .model_id .model
133+ ):
134+ continue # Skip validation when model is not yet available
123135 if not record ._validate_dotted_path ():
124- message = self .env ._ (
125- "The dotted path '{path}' is not valid for model '{model}'."
126- ).format (
127- path = record .odoo_field_value ,
128- model = record .report_form_id .model_id .name ,
136+ model_name = (
137+ record .report_form_id .model_id .name
138+ if record .report_form_id .model_id
139+ else "Unknown"
129140 )
141+ message = self .env ._ (
142+ "The dotted path '%(path)s' is not valid for model '%(model)s'."
143+ ) % {"path" : record .odoo_field_value , "model" : model_name }
130144 raise ValidationError (message )
0 commit comments