This question has been flagged
9 Replies
18634 Views

My new module require to inform user about some things like stock levels, quantities etc. I can of course display it on screen but i would like to have it as a popup instead to make sure that the user is seeing it and react on this information.

For example if stock level is LOW message will popup "Hey you, do you know that your stock level is almost zero ? ;)" or something :)

If it's only on the screen among many other can be easily overlooked but if message popup, user must click to close it so I can record this information and if something will be wrong and for example order will not created I will know who is responsible for this mess ;)

I was trying to use warnings but warning stops all processes and roll them back. How to create popup message using other solution ?

Have some ideas but i'm not sure will it work.

def popup_method(...........):
    return {
              'name': _(some name),
              'view_type': 'form',
              "view_mode": 'form',
              'res_model': model-name,
              'type': 'ir.actions.act_window',
              'target': 'new',
              }

and call it conditionally. What do you think guys ?
Avatar
Discard
Best Answer

Yes, you can use the wizard to display the pop up message in order to show dynamic message and it will not stop the process. 

if you have a button and the text is static, can also use a button confirm attribute in xml, like

<button name="method" string="Confirm" type="object" confirm="are you sure you want to continue?"/>

It will display a confirmation dialog with yes and no button on it and won't break the process.


Avatar
Discard
Author

This second method is useless because as you said is static text only. I'm interested in first one ;) But how, never used wizards or things like that. Have you got any examples ?

Author

and also must be triggered depending on if condition ;)

Best Answer

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.

# 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() 

XML

     <!--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>  


Get complete code and description from here: http://learnopenerp.blogspot.com/2017/12/how-to-display-confirmation-display-box.html

Avatar
Discard
Author Best Answer

Hah, that's simple, thank you Pawan :)


Avatar
Discard
Best Answer

Rob,

Create a new object as osv.osv_memory( as its data will not be stored in database and is for temporary use only.

class YOUR_CLASS(osv.osv_memory):

and then keep one field in it:

_columns = {'name': fields.char('Message', readonly="1"),

Now under your if condition when u are calling that action as u have in ur part, modify it as:

if YOUR_CONDITION:
    

return {
              'name': _(some name),
              'view_type': 'form',
              "view_mode": 'form',
              'res_model': YOUR_CLASS,
              'type': 'ir.actions.act_window',    
          'context': {'default_name': 'YOUR CUSTOM MESSAGE'}
     'target': 'new', }

and design your xml as needed...

Hope it helps you!    

Avatar
Discard
Author

Testing ;)

Author

Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch result = self._call_function(**self.params) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call return self.endpoint(*a, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__ return self.method(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap response = f(*args, **kw) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 944, in call_kw return self._call_kw(model, method, args, kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 336, in old_api result = method(recs, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/connector/producer.py", line 48, in create record_id = create_original(self, vals) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper return new_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4074, in create record = self.browse(self._create(old_vals)) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper return new_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 462, in new_api result = method(self._model, cr, uid, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4265, in _create recs._validate_fields(vals) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper return new_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1262, in _validate_fields res_msg = trans._get_source(self._name, 'constraint', self.env.lang, msg) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper return new_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 441, in new_api result = method(self._model, cr, uid, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_translation.py", line 369, in _get_source return self.__get_source(cr, uid, name, types, lang, source, res_id) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "", line 2, in __get_source File "/usr/lib/python2.7/dist-packages/openerp/tools/cache.py", line 74, in lookup value = d[key] = self.method(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_translation.py", line 336, in __get_source cr.execute(query, params) File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 158, in wrapper return f(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/sql_db.py", line 234, in execute res = self._obj.execute(query, params) InternalError: current transaction is aborted, commands ignored until end of transaction block

Its a bit messy , can u pls figure out your file in it ..