In my project i have an entity with a binary attribute (shape). I want to raise a message (validationError) if the user uploads a file with the wrong extention for that shape attribute in the form in the form. How should i do it?
I have done this so far but is nor working
shape = fields.Binary(string='Shape', required=True, attachment=True)
shape_filename = fields.Char()
def _check_file_extension(self, name, ext):
if type(name) != bool:
if not str(name).endswith(ext):
return False
return True
return False
@api.onchange('shape_filename')
def _onchange_shape(self):
if self.id and not self._check_file_extension(self.shape_filename,
'.zip'):
raise ValidationError("Shape must be a .zip file ")
and in the view
<field name="shape" widget="download_link" filename="shape_filename" options="{'filename': 'shape_filename'}"/>
<field name="shape_filename" readonly="1" invisible="1" force_save="1"/>