In my project i have an entity with a binary attribute (shape). I made an onchange method to raise a message (validationError) if the user uploads a file with the wrong extention, but i also want the method to clear the value of the binary field (cause the widget is still showing the name of the file I just upload), so the user must select a new one. I have tried with "self.shape_filename=False" but is not working. What should I do to clear the value of the binary field once Odoo raises the exception? This is my code:
@api.onchange('shape_filename')
def _onchange_shape(self):
if self.shape_filename and not self.shape_filename.endswith('.zip'):
self.shape=False
self.shape_filename=False
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"/>