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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Účetnictví
- Sklad
- PoS
- Project
- MRP
This question has been flagged
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!
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Přihlásit seRelated Posts | Odpovědi | Zobrazení | Aktivita | |
---|---|---|---|---|
odoo application update
Vyřešeno
|
|
5
lis 22
|
3890 | |
|
0
bře 22
|
3011 | ||
|
0
úno 22
|
2399 | ||
|
0
pro 21
|
1928 | ||
|
0
lis 21
|
1746 |