Skip to Content
Menú
This question has been flagged
1 Respondre
3856 Vistes

I want to store only one record in a table and I have to show an error message when clicked on create button in tree view , if tried to enter another record . How to over ride the create button and display custom error message.

Avatar
Descartar
Best Answer

Hi,

You can try like this,

@api.model
def create(self, vals):
existing_records = self.search([])
if len(existing_records) >1:
raise ValidationError(_("Cannot Create More Than 1 Record"))
res = super(ClassName, self).create(vals)
return res

Thanks

Avatar
Descartar

Hi Niyas, how to add a new button after the create button in Odoo16?

Related Posts Respostes Vistes Activitat
3
de jul. 24
2734
2
de juny 22
2888
0
de jul. 17
4493
0
de juny 15
3952
0
de març 15
4088