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.

0

display warning message when a float value is negative

By
layal abishalhla
on 3/19/14, 8:57 AM 1,432 views

how to display a warning message when the value of a float field is less than zero?

Do you want the warning to be displayed right on the change of that field, or when the user tries to save the record?

René Schuster
on 3/19/14, 9:06 AM

i want it to be displayed right on the change of that field,please

layal abishalhla
on 3/19/14, 9:36 AM
1

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 3/19/14, 9:55 AM

In your Case use an on_change method:

<field name="your_float_field" on_change="your_onchange_method(your_float_field)"/>

And in your .py file:

def your_onchange_method(cr, uid, ids, float_value, context=None):
    res = {}
    if float_value < 0:
        res['warning'] = {'title': 'Warning Title', 'message': '''Warning Message'''}
        res['value'] = {'your_float_field': abs(float_value)}
    return res

_columns = {
    'your_float_field': field.float('Field Name'),
}

This will display a warning message and set the float value to a positive value.

Regards.

0

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 3/19/14, 9:06 AM

Hi,

Add _constraints in py file, try below code

def _check_qty(self, cr, uid, ids, context=None):
    for order in self.browse(cr, uid, ids, context=context):
        if order.your_field < 0:
            return False
   return True

_constraints = [
           (_check_qty, ' your_field cannot be negative !', ['your_field']),
]

thank you jack for your reply, but this way will display the message after save, while what i need is to display it on change.. any help ?

layal abishalhla
on 3/19/14, 9:54 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

0 follower(s)

Stats

Asked: 3/19/14, 8:57 AM
Seen: 1432 times
Last updated: 3/16/15, 8:10 AM