Odoo Help

Welcome!

This community 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.

0

How to display a warning when returning an act_window (from python code) ? [V8]

By
Pierre Faniel
on 3/11/16, 6:54 AM 427 views

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.

0
Pierre Faniel
On 3/11/16, 7:27 AM

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’}

}


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/11/16, 6:54 AM
Seen: 427 times
Last updated: 3/11/16, 7:27 AM