Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
How to display a warning when returning an act_window (from python code) ? [V8]
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.
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’}
}
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 3/11/16, 6:54 AM |
Seen: 1210 times |
Last updated: 3/11/16, 7:27 AM |