Skip to Content
Menu
This question has been flagged
3 Replies
4360 Rodiniai

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)

Portretas
Atmesti
Autorius 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.

Portretas
Atmesti
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


Portretas
Atmesti
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.

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
saus. 22
3735
2
gruod. 22
2813
1
spal. 22
1889
2
geg. 24
5108
1
bal. 24
579