تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
15713 أدوات العرض

Hello,

v13

I am overriding create and write methods. I need show message popup if some condition occure, but I don't want to stop running create/write functions. I mean I want to be possible to save obejcts even if popup was shown.

Raising Warnings or Errors not work

Returns action with wizard also look like bad idea.

What to do?

===============================================================

Edit for Hilar's answer

===============================================================

For example the problem is if I have:

def write(self, vals):
    return {'warning': { 'title': "bla bla", 'message': "bla bla" }}
    print("THIS WILL NEVER BE PRINTED. BECAUSE I HAVE 'RETURN' STATEMENT BEFORE IT"
    return super(Vehicle, self).write(vals)
or
def write(self, vals):
    raise UserError(_("bla bla"))
    print("THIS WILL NEVER BE PRINTED. BECAUSE I HAVE 'RAISE' STATEMENT BEFORE IT"
    return super(Vehicle, self).write(vals)
Object will never be saved
الصورة الرمزية
إهمال
أفضل إجابة

You can return

return {'warning': {
'title': 'Warning',
'message': ("Message"),
}}

Or raise Usererror
raise UserError("Message")

With these functions you can continue workflow.
الصورة الرمزية
إهمال
الكاتب

I edited question

Instead of exceptions, we have an ODOO notification management system that can be achieved through client actions. eg:

title = _("Connection Test Succeeded!")

message = _("Everything seems properly set up!")

return {

'type': 'ir.actions.client',

'tag': 'display_notification',

'params': {

'title': title,

'message': message,

'sticky': False,

}

}

If you need to notify before saving the record to users, then you must do the logic before write() funciton

I can give you more hint, check the stock transfer workflow. ODOO asking "You have not recorded done quantities yet, by clicking on apply Odoo will process all the quantities. " With a wizard.

الكاتب

It doesn't matter what I will return, action either too. I wrote it in post. "Stock transfer" use xml files. I don't do that in my case.

I have checked both and they will block execution of following code

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 23
3990
0
أغسطس 19
7479
0
نوفمبر 17
4596
0
مارس 15
5536
2
ديسمبر 23
7066