how to display a warning message when the value of a float field is less than zero?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- إدارة علاقات العملاء
- e-Commerce
- المحاسبة
- المخزون
- PoS
- Project
- MRP
لقد تم الإبلاغ عن هذا السؤال
2
الردود
8038
أدوات العرض
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.
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 ?
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!
أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!
تسجيل
Do you want the warning to be displayed right on the change of that field, or when the user tries to save the record?
i want it to be displayed right on the change of that field,please