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

Hello.
Is there any way in which I can put a validation to a many2many field where the user can only attach files in pdf format and if he uploads files of another type of extension, odoo launches a validation?
Odoo 14 community

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

You may achieve your goal using rewriting create and write method where you can put validation for extension of the file. You can have a look below code as a reference:


import pathlib
from odoo.exceptions import ValidationError

def write(self, vals):
ext = 0
for
attachment in vals['attachment_ids'][0][2]:
file_name = self.env['ir.attachment'].browse(attachment).name
if pathlib.Path(self.env['ir.attachment'].browse(attachment).name).suffix == '.pdf':
ext += 1
if
ext != len(vals['attachment_ids'][0][2]):
raise ValidationError('You can upload only pdf files!')
super().write(vals)
return True



Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

อวตาร
ละทิ้ง
ผู้เขียน

Thanks!

Related Posts ตอบกลับ มุมมอง กิจกรรม
odoo application update แก้ไขแล้ว
5
พ.ย. 22
3892
0
มี.ค. 22
3013
0
ก.พ. 22
2407
0
ธ.ค. 21
1931
0
พ.ย. 21
1747