Skip to Content
Menu
This question has been flagged

I would like to display a warning at the end of the action I return like this


...some code...  


return {

'view_type': 'form',

'view_mode': 'form',

'view_id': self.env.ref('my_module.my_view').id,

'res_model': 'my.model',

'type': 'ir.actions.act_window',

'target': 'new',

 'context': {}

}

 

I tried adding the key warning to the return values but it only completed the act_window without raising any warning:

return {

'view_type': 'form',

'view_mode': 'form',

'view_id': self.env.ref('my_module.my_view').id,

'res_model': 'my.model',

'type': 'ir.actions.act_window',

    'target': 'new',

    'context': {},

    'warning': 'My warning',

}


I also tried adding the warning key to the context but it didn't work either.


The goal is to simply display an informative warning after the page is loaded.

Avatar
Discard
Author Best Answer

A possible solution would be to create a TransiantModel:

#../custom_warning/models/my_warning.py

class MyWarning(models.TransientModel):

_name = 'my.warning'

name = fields.Char('Name')

@api.multi

def action_warning(self):

return {

'view_type': 'form',

'view_mode': 'form',

'view_id': self.env.ref('my_module.my_view').id;

'res_model': 'my.model',

'type': 'ir.actions.act_window',

'target': current,

'context': {},

}

And a wizard to create a modal:

<!-- ../custom_warning/views/my_warning.xml -->

<?xml version="1.0" encoding="utf-8"?>

<openerp>

<data>

<record id="my_warning" model="ir.ui.view">

<field name="model">my.warning</field>

<field name="arch" type="xml">

<form>

<field name="name" readonly="1"/>

<footer>

<button string=“Continue”

class="oe_highlight"

type="object"

name="action_warning"/>

or

<button name="cancel" string="Cancel" special="cancel" class="oe_link"/>

</footer>

</form>

</field>

</record>

</data>

</openerp>

And then call the modal where the initial action was supposed to be:

        return {

               'name': 'Warning',

'view_type': 'form',

'view_mode': 'form',

'view_id': self.env.ref('custom_warning. my_warning’).id,

'res_model': ‘my.warning',

'type': 'ir.actions.act_window',

'target': 'new',

'context': {'default_name': ‘My warning message’}

}


Avatar
Discard
Related Posts Replies Views Activity
1
May 17
9176
0
Jun 21
5142
1
Aug 19
5093
2
Jul 19
3037
0
Dec 17
3187