跳至内容
菜单
此问题已终结
3 回复
4349 查看

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)

形象
丢弃
编写者 最佳答案

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.

形象
丢弃
最佳答案

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


形象
丢弃
最佳答案

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

Try to restart the service and upgrade your module.

形象
丢弃
相关帖文 回复 查看 活动
1
1月 22
3728
2
12月 22
2811
1
10月 22
1886
2
5月 24
5101
1
4月 24
579