How to set validation for document upload only to .pdf in openERP
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
3
Replies
8189
Views
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')
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!!
Were you able to solve it?
Yes..