跳至內容
選單
此問題已被標幟
3 回覆
4355 瀏覽次數

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
3735
2
12月 22
2813
1
10月 22
1889
2
5月 24
5106
1
4月 24
579