Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
6 Trả lời
108101 Lượt xem

I wanna make a message that says something. I tryed it with raise osv.except_osv

but this is a Error Message.

I want to print a message and that the input is not saved. 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

you can use warning or RaiseError ,or you can create your default pop up or wizard like the example below


from odoo import api, fields, models 

class hr_wizard(models.TransientModel):

    _name = 'hr.wizard'

    _description = 'HR employee wizard'

    message = fields.Text(string="Your file is stored in the directory C:/", readonly=True, store=True)


now create your view like this

<?xml version="1.0" encoding="utf-8"?>

<odoo>

        <record id="view_hr_wizard" model="ir.ui.view">

            <field name="name">Pdf.generation.form</field>

            <field name="model">hr.wizard</field>

            <field name="arch" type="xml">

            <form string="generation fichier">

                <group>

                    <field name="message" />

                </group>

                <footer>

                    <button string="OK" special="cancel" class="oe_highlight"/>

                </footer>

            </form>

            </field>

        </record>

</odoo>

and you can call it in other function like this

return {

    'name': 'Pdf.generation.form',

    'type': 'ir.actions.act_window',

    'res_model': 'hr.wizard',

    'view_mode': 'form',

    'view_type': 'form',

    'target': 'new'

      }

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

you can raise a warning message in on_change by

return {

    'warning': {

        'title': 'Warning!',

        'message': 'The warning text'}

}

and this question is already in community hear

Ảnh đại diện
Huỷ bỏ

it worked for me very simple and perfect!!!

Câu trả lời hay nhất

Hi Try this in odoo16.

return {
'warning': {'title': "Warning", 'message': "What is this?", 'type': 'notification'},
}

If the type is set to notification, the warning will be displayed in a notification.
Otherwise, it will be displayed in a dialog as default.

Thanks

Gouranga Kala

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can try:

return {'value':{},'warning':{'title':'warning','message':'Your message'}}

Thanks

Ảnh đại diện
Huỷ bỏ

it worked for me very simple and perfect!!!

@Elsanita Sinaga, glad it's helped.

Câu trả lời hay nhất

Hello friend;

here is how you can print a warning message.

First, you should import:

from openerp.osv.orm import except_orm

And then in your python:

My_error_Msg = 'hello!!'

raise osv.except_osv(_("Error!"), _(My_error_Msg))

return True

So that, there are two possibilities:

- if you want to block the access and the record (return True)

-Only print the warning message, press ok and save the record (return False)

Some useful links:

https://www.odoo.com/fr_FR/forum/help-1/question/using-raise-osv-except-osv-16015

http://odoo-new-api-guide-line.readthedocs.org/en/latest/conventions.html

http://stackoverflow.com/questions/29072343/how-to-display-openerp-error-message

http://stackoverflow.com/questions/30210715/how-to-create-a-function-to-raise-error-in-openerp

Best Regards.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello wizards,

You can use "raise Warning" instead of "raise osv.except_osv".


Thank you.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 17
5129
1
thg 7 15
9367
3
thg 4 22
12720
0
thg 5 16
4065
0
thg 5 16
3681