I have a fields.Char attribute “identification_id”, That field must have 11 characters. How can I add a _sql_constraints to check the length of that field and ensure it should be 11 ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- إدارة علاقات العملاء
- e-Commerce
- المحاسبة
- المخزون
- PoS
- Project
- MRP
لقد تم الإبلاغ عن هذا السؤال
2
الردود
4360
أدوات العرض
_sql_constraints = [ ( 'identification_id_len_check', 'check (LENGTH(identification_id) = 11)', ('identification_id should be 11 symbols') ), ]SQL constraints are faster in comparison to api.constrains.
Make sure that none of your existing records have different size. Otherwise, constrain would not be created
Hi,
If it is not mandatory to for _sql_constraints, try to achieve the same using the constrains.
@api.constrains('identification_id')
def check_identification_id(self):
for rec in self:
if len(rec.identification_id) != 11:
raise ValidationError(_('Must be 11 Characters'))
See : How To Add Constrains For A Field in Odoo12
Thanks
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!
أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!
تسجيلالمنشورات ذات الصلة | الردود | أدوات العرض | النشاط | |
---|---|---|---|---|
|
0
ديسمبر 24
|
658 | ||
Import Data From Another Model
تم الحل
|
|
1
مارس 24
|
1560 | |
@api.constrains
تم الحل
|
|
2
ديسمبر 23
|
2301 | |
|
1
يونيو 23
|
11598 | ||
|
0
يناير 23
|
2348 |