Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3585 มุมมอง

Hi everyone, I need to limit the files size that users upload in Odoo. I thought in a automatic action to prevent that. It worked in the model ir.attachments view, but when I upload a file using the chatter in any model, doesn't work.


This is my automatic action:


for x in record:
    if x.file_size > 2000:
        raise Warning('The selected file exceed the maximum file size of 2MB')


I'd appreciate your help.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Dear Juan Jose Santacruz,

In your code you have taken 1mb = 1000 kb, in fact it is 1mb = 1024 kb. Now try the code given below so that your problem will be solved.


for x in record:
if (x.file_size / 1024.0 / 1024.0) > 2 :
raise Warning('The selected file exceed the maximum file size of 2MB')



I hope this information has been useful to you and your error has been resolved after making this change.


Feel free for further assistance on contact@geminatecs.com.

Thank you
Geminate Consultancy Services

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.พ. 23
6321
0
มี.ค. 22
1736
2
ม.ค. 22
1879
0
มิ.ย. 21
3005
2
มิ.ย. 20
5145