Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
15814 Lượt xem

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
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can return

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

Or raise Usererror
raise UserError("Message")

With these functions you can continue workflow.
Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 23
4064
0
thg 8 19
7538
0
thg 11 17
4641
0
thg 3 15
5572
2
thg 12 23
7109