Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • 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
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to display dialog box

Subscribe

Get notified when there's activity on this post

This question has been flagged
messagebox
19 Replies
50791 Views
Avatar
Maniganda

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.

4
Avatar
Discard
Rajiv

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

Sehrish

this will helps: https://learnopenerp.blogspot.com/2017/12/how-to-display-confirmation-display-box.html

Avatar
Maniganda
Author Best Answer

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)))
8
Avatar
Discard
Stefan Reisich

thank you very much.

Atchuthan - Technical Consultant, Sodexis Inc

Is this module available in launchpad/github?

Avatar
Andreas Maertens
Best Answer

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 )

9
Avatar
Discard
Maniganda
Author

how to include in my module

Andreas Maertens

Did it work for you?

Maniganda
Author

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

Andreas Maertens

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. ;)

Maniganda
Author

Thank you its working

Francesco OpenCode

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

Andreas Maertens

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

Stefan Reisich

Does it works with create and write methods?

Stefan Reisich

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

sepdau

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

Avatar
amine
Best Answer

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

0
Avatar
Discard
Atchuthan - Technical Consultant, Sodexis Inc

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

Víg János

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to add pop up message or message box with message every button clicked? Solved
popup messagebox
Avatar
Avatar
1
Dec 19
7556
Allowing Collapse and Expand the Body of message in Message Chatter
messagebox odoo12
Avatar
0
Aug 19
4236
Is it possible to block the communication of 2 users within the odoo 16 messaging app?
message messagebox conversation
Avatar
0
Aug 23
1922
Hide notifications after opening them
notifications chat messagebox chatbot
Avatar
0
May 21
4203
How to change the e-mail indexing in "Discuss"
messaging index messagebox odooV9
Avatar
0
Jan 16
4332
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now