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.

4

How to display dialog box

By
Maniganda
on 5/14/13, 7:27 AM 14,321 views

I have a requirement, to display the message box and update the current date and time but if I use raise.osv it's stopping the flow of control and the datetime is not updated.

These are Module files. Maybe make an extra module with this and then just use it as written @ the buttom

Rajiv
on 7/30/14, 9:34 AM
8

Maniganda

--Maniganda--
1038
| 5 7 7
Bangalore, India
--Maniganda--
Maniganda
On 9/5/13, 11:47 AM

crete py file in your module

from osv import osv
from osv import fields
from openerp.tools.translate import _

WARNING_TYPES = [('warning','Warning'),('info','Information'),('error','Error')]

class warning(osv.osv_memory):
_name = 'warning'
_description = 'warning'
_columns = {
    'type': fields.selection(WARNING_TYPES, string='Type', readonly=True),
    'title': fields.char(string="Title", size=100, readonly=True),
    'message': fields.text(string="Message", readonly=True),
}
_req_name = 'title'

def _get_view_id(self, cr, uid):
    """Get the view id
    @return: view id, or False if no view found
    """
    res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 
        'osc_integ', 'warning_form')
    return res and res[1] or False

def message(self, cr, uid, id, context):
    message = self.browse(cr, uid, id)
    message_type = [t[1]for t in WARNING_TYPES if message.type == t[0]][0]
    print '%s: %s' % (_(message_type), _(message.title))
    res = {
        'name': '%s: %s' % (_(message_type), _(message.title)),
        'view_type': 'form',
        'view_mode': 'form',
        'view_id': self._get_view_id(cr, uid),
        'res_model': 'warning',
        'domain': [],
        'context': context,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'res_id': message.id
    }
    return res

def warning(self, cr, uid, title, message, context=None):
    id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'warning'})
    res = self.message(cr, uid, id, context)
    return res

def info(self, cr, uid, title, message, context=None):
    id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'info'})
    res = self.message(cr, uid, id, context)
    return res

def error(self, cr, uid, title, message, context=None):
    id = self.create(cr, uid, {'title': title, 'message': message, 'type': 'error'})
    res = self.message(cr, uid, id, context)
    return res

and create xml file

<openerp>
   <data>
    <record id="warning_form" model="ir.ui.view">
        <field name="name">warning.form</field>
        <field name="model">warning</field>
        <field eval="20" name="priority"/>
        <field name="arch" type="xml">
            <form string="Warning" version="7.0">
                <field name="message"  nolabel="1" />
                <footer>
                    <button string="OK" class="oe_highlight" special="cancel" />
                </footer>
            </form>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_warning">
        <field name="name">Warning</field>
        <field name="res_model">warning</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="warning_form" />
        <field name="target">new</field>
    </record>
</data>

</openerp>

and finally call the method

return self.pool.get('warning').info(cr, uid, title='Export imformation', message="%s products Created, %s products Updated "%(str(prod_new),str(prod_update)))

thank you very much.

Stefan Reisich
on 9/10/13, 9:38 AM

Is this module available in launchpad/github?

Atchuthan - Technical Consultant, Sodexis Inc
on 7/30/14, 9:53 AM
9

Andreas Maertens

--Andreas Maertens--
912
| 5 5 7
Finsterwalde, Germany
--Andreas Maertens--

I develop odoo8.0 modules

Andreas Maertens
On 5/14/13, 7:43 AM

We made an addon to show warning messages and so on:

addon.py:

w_types = [('warning','Warning'),('info','Information'),('error','Error')]

class warning():
    ...
    _columns = {
        'title': fields.char(...),
        'message': fields.text(...),
    }
    _req_name = 'title'

    def _get_view_id(self, cr, uid):
        res = self.pool.get('ir.model.data').get_object_reference(cr, uid, 
            'warning', 'warning_form')
        if res:
            return res[1]
        else:
            return False

    def message(self, cr, uid, id, context):
        message = self.browse(cr, uid, id)
        message_type = [t[1]for t in w_types if message.type == t[0]][0]
        res = {
            'name': '%s: %s' % (_(message_type), _(message.title)),
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': self._get_view_id(cr, uid),
            'res_model': 'warning',
            'domain': [],
            'context': context,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'res_id': message.id
        }
        return res

    def warning(self, cr, uid, title, message, context=None):
        id = self.create(... {'title': title, 'message': message, 'type': 'warning'})
        res = self.message(cr, uid, id, context)
        return res

    def info(self, cr, uid, title, message, context=None):
        ...
        return res

    def error(self, cr, uid, title, message, context=None):
        ...
        return res

and the view.xml:

        <record id="warning_form" model="ir.ui.view">
            ...
            <field name="arch" type="xml">
                <form string="Warning" version="7.0">
                    <field name="message"  nolabel="1" />
                    <footer>
                        <button string="OK" class="oe_highlight" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_warning">
            ...
            <field name="view_id" ref="warning_form" />
            <field name="target">new</field>
        </record>

You may have to add functionallity to make it work as dialog.

        Just return this to a function that is called from client. 
        Usage:  return self.pool.get('warning').warning(cr, uid, title='Title', message='Text')
                                               .info(...)
                                               .error(...)

( this is an extract from a module made by our Team )

how to include in my module

Maniganda
on 5/14/13, 7:44 AM

Did it work for you?

Andreas Maertens
on 5/14/13, 8:31 AM

ya its working and how to display a variable value with text

Maniganda
on 5/14/13, 9:02 AM

You need to combine your text and values in one string: e.g. string = "value %s is wrong..."%str(value) You can also add new functionality to the module to do this. ;)

Andreas Maertens
on 5/14/13, 9:29 AM

Thank you its working

Maniganda
on 5/14/13, 9:30 AM

Andreas: Why you don't release it as public module?

Francesco OpenCode
on 5/14/13, 11:45 AM

We need to make clear, if our company releases the whole module. We come back on that.

Andreas Maertens
on 5/14/13, 12:15 PM

Does it works with create and write methods?

Stefan Reisich
on 9/5/13, 6:38 AM

I'm getting errors. Could you please tell me what i need to include at the "..."?

Stefan Reisich
on 9/5/13, 6:51 AM

didn't work in write or create function of object. Please help

sepdau
on 1/14/14, 11:40 PM
0
amine
On 5/22/14, 7:06 AM

hello i have two date time field and i calculated difference both of them but sometimes i missed to enter date so it raise the error, but i want some msg instead of error can you please help me

provide a default value for both the fields OR check whether the value is available at the field before calculating the difference

Atchuthan - Technical Consultant, Sodexis Inc
on 7/30/14, 9:52 AM

Nice work, but I don't like to save the warning etc. to the database, only show it to my user, then drop it.

Víg János
on 11/27/14, 4:43 AM

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

6 follower(s)

Stats

Asked: 5/14/13, 7:27 AM
Seen: 14321 times
Last updated: 3/16/15, 8:10 AM