This question has been flagged
3 Replies
8189 Views

How to set validation for document upload only to .pdf in openERP

Avatar
Discard
Best Answer

Hello @rumaan Try This:

from odoo.exceptions import UserError
import mimetypes
from odoo.tools.mimetypes import guess_mimetype
file_name = fields.Char('File Name')
mimetype = None
if
mimetype is None and self.file_name:
mimetype = mimetypes.guess_type(res.file_name)[0]
if not mimetype == 'pdf':
raise UserError('Allowed Format Pdf')

Avatar
Discard
Best Answer

Or you can also try this code::


# create a char field
file_data = fields.Binary('File')
file_name = fields.Char('File Name')

# Go to xml and

def check_file_type(self):

​if not self.file_name.endswith('.xlsx'): //Here you can define your file format like .pdf, .word etc.//

​​raise UserError('Please insert a valid file')


Thanks!! 

Avatar
Discard
Best Answer

Were you able to solve it?

Avatar
Discard