Skip to Content
Menu
This question has been flagged
3 Replies
3110 Views

Hello everyone,
I created a new module 'my_module', I created a view 'cours_view.xml' and a model 'cours.py', in the model, I overloaded the unlink and create function, but when I delete a course on the web interface the unlink function that I declared in the model is not called the same for create. 

I spent the day on it, so please help me 🥸

below is the code of cours.py:

from odoo import models, fields, api
from odoo.exceptions import ValidationError

class MycustomemoduleCours(models.Model):
_name = 'mycustomemodule.cours'
_rec_name = 'title'
title = fields.Char()
description = fields.Text()


def unlink(self):
raise ValidationError("impossible")
print("*************************** test customize delete****************")
return super(MycustomemoduleCours, self).unlink()

@api.model
def create(self, vals):
print("***********create customize methodes")
return super(MycustomemoduleCours, self).create(vals)

Avatar
Discard
Author Best Answer

Thanks WALEED you for tested my code, I think the problems was internal to odoo, I have already update the modules from application

I solved the problem by re-installing odoo.

Note: I working on k8s cluster, so all modules odoo are not directly in 

/usr/lib/python3/dist-packages/odoo/addons/ but in /mnt/addons, so I think that's cause of no-synchronization.

Avatar
Discard
Best Answer

For more information you can visit this playlist, How each base methods you can override with example.

https://www.youtube.com/playlist?list=PLAR8TpPnVeTSsvwN1uWd8bcTbvCVAb8gq

For create you can try this discussion.

https://youtu.be/76LGYkRCSmI


For Unlink/Delete method you can try this discussion.

https://youtu.be/kqSM4P9QEBM

Thank You


Avatar
Discard
Best Answer

I have tested your code and its working and I got ValidationError message "impossible"

Try to restart the service and upgrade your module.

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 22
2342
2
Dec 22
1623
1
Oct 22
1014
2
May 24
3933
1
Apr 24
477