Hi,
I have integer field and i want to limite the number of digit that can be enter if not it should give an error message
for exemple limite numbers in 4 digit
i'm using odoo 10.
Regards
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi,
I have integer field and i want to limite the number of digit that can be enter if not it should give an error message
for exemple limite numbers in 4 digit
i'm using odoo 10.
Regards
You can do it using a constraint on the field.
This will prevent creating or updating a record with a value for the field 'number' that violates the constraint
from odoo.exceptions import UserError, RedirectWarning, ValidationError
#field
number = fields.Integer(string = "My Number")
#constraint
@api.constrains('number')
@api.one
def _check_number(self):
number = self.number
if number and len(str(abs(number))) > 4:
raise ValidationError(_('Number of digits must on exceed 4'))
You can use parameter size = 4 in field definition
example -> number = fields.Integer(string = "My Number", size=4)
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.