How to display confirmation display box / message box on button click.

In this article I will show you how to add or display confirmation display box / message box on button click. Before going into deep we need to know problem statement. In some scenario we need to ask from user is he/she want to do further processing or not on button click.

For example we have some document which needs to be approved by vice chancellor of a university. And before submitting it to the vice chancellor we want to ask confirmation from user. So guys to achieve this goal follow these steps.

Display Dialog box / Message Box


  
# Confirmation msg box for ORIC
from openerp.osv import fields,osv
from openerp.tools.translate import _
class thesis_approval_message_oric(osv.osv_memory):
_name = "thesis.approval.message.oric"
_columns={
'text': fields.text(),
}
thesis_approval_message_oric()

Code Description

In above code we created a class named "thesis_approval_message_oric", and in that class we create one field named "text" this field holds our text message that we want to display our user before taking some action on button click.

Now we are going to create our dialog box / message box interface. In Odoo/ERP its not a big deal if you don't have any idea about form view than read this article How to create form and tree views.

     <!--Wizard For Raise Apprval Messages Thesis ORIC-->
<record id="wizard_message_form_for_oric" model="ir.ui.view">
<field name="name">Thesis Wizard Message Approval Message ORIC</field>
<field name="model">thesis.approval.message.oric</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Message" version="7.0">
<separator string="Message" colspan="6"/>
<field name="text" colspan="4" nolabel="1" readonly="1" widget="html"/>
<newline/>
<separator colspan="6"/>
<footer>
<button name="btn_approve_oric" type="object" string="Yes" class="oe_highlight"/>
<button special="cancel" string="No"/>
</footer>
</form>
</field>
</record>

Code Description

In above code we have created form view to display confirmation message box. This form view contains one field that will display our confirmation message and a footer that contains tow buttons, the first one is for "Yes", "Ok" and the second one is for cancellation of the form.

Now that we have class and form view associated to that class. Now we are going to create action menu for that model or class, because when we click on button than this action menu will popup or open dialog box or message confirmation box. For further knowledge about Action Menu read this article How to create Action Menu.


        <record id="wizard_message_action_for_oric" model="ir.actions.act_window">
<field name="name">Thesis Wizard Approval Message ORIC</field>
<field name="res_model">thesis.approval.message.oric</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

Now its time to open dialog box on button click.


    @api.multi
def btn_approve(self):
text = """The case """+str(self.case_no)+""" will be forward to VC for further Approval. Are you want to proceed."""
query='delete from thesis_approval_message_oric'
self.env.cr.execute(query)
value=self.env['thesis.approval.message.oric'].sudo().create({'text':text})
return{
'type':'ir.actions.act_window',
'name':'Message',
'res_model':'thesis.approval.message.oric',
'view_type':'form',
'view_mode':'form',
'target':'new',
# 'context':{'thesis_obj':self.id,'flag':'course Work completed'},
'res_id':value.id
}

Code Description

Above code will first delete previous message from database and create new message using Odoo create method. And return or display confirmation message or dialog box in a new window.