تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3532 أدوات العرض

Since V14 the fields size parameter (size=x) is no longer valid on field definitions.
What is the correct way to limit the size of a string field in the database (not the view) so that the length is automatically cropped to 18 characters?

Please note that I need to do this on a related field:
fields.Char(string='CSV Memo', related='ref', store=False)

Originally in V13 I used:
fields.Char(string='CSV Memo', related='ref', store=False, size=18)

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Interesting update. I actually tried adding back size attribute to a field in V15 and it works without issue or any warning in the log! I was surprised as I took the advice from an OCA article https://github.com/OCA/maintainer-tools/wiki/Migration-to-version-14.0.

However I can see that even in V16 there are still many uses of the size attribute used on char fields, for example:
https://github.com/odoo/odoo/blob/16.0/addons/l10n_de/models/datev.py

Anyone know if Odoo backtracked on this plan and it's no longer relevant?

الصورة الرمزية
إهمال
أفضل إجابة

HI Chris Mann, 
Second option will be try to add constraints and check length of the char field in its method. You can raise exception for the size exceed. 

If you want to automatically crop it to 18 char , then you have to follow the string slicing. But on you case its related field , so might be automatically cropped will not work.
Hope it will help you. 

الصورة الرمزية
إهمال
الكاتب

Thanks Malay.
Unfortunately I don't think those options will work.
The field is used as part of an export template to CSV file and needs to have the limit applied when exported so that the field length is limited.
It's to export to a bank formatted CSV for payments that has strict rules on length.

المنشورات ذات الصلة الردود أدوات العرض النشاط
3
مايو 25
1750
1
أبريل 25
1293
3
سبتمبر 24
14207
1
يوليو 24
6845
2
فبراير 24
2479