Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
15726 Vues

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
Avatar
Ignorer
Meilleure réponse

You can return

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

Or raise Usererror
raise UserError("Message")

With these functions you can continue workflow.
Avatar
Ignorer
Auteur

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.

Auteur

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

Publications associées Réponses Vues Activité
1
mars 23
4002
0
août 19
7492
0
nov. 17
4596
0
mars 15
5536
2
déc. 23
7070