Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Is there any easy way (like a widget) to filter the input of a binary field?

By
Juan Formoso
on 3/16/15, 6:45 AM 1,104 views

I have a binary field, and I want to allow the user to upload only zip files to it. I'm trying to do it this way:

source_file = fields.Binary('Source File', filters='*.zip')

But I've read that this only worked for the old GTK Client. Is there a great way to manage this on version 8?

1
Dewilde Valentin
On 3/24/15, 8:15 AM

Hi,

I'm with the same problem and don't find a solution as simple as the one you mention. But there is a solution as i think simple enough : use the api.constrains. Here is my modus operandi:


1) I save the file's name

My model:

files = fields.Binary(string="Download Zip")
filename = fields.Char()

My view:

<field name="filename" invisible="1" />
<field name="files" filename="filename" />


2) I use the api.constrains to verify the extension

@api.one
@api.constrains('filename')
def _check_filename(self):
    if self.files:
        if not self.filename:
	    raise exceptions.ValidationError(_("There is no file"))
	else:
	    # Check the file's extension
	    tmp = self.filename.split('.')
	    ext = tmp[len(tmp)-1]
	    if ext != 'zip':
	        raise exceptions.ValidationError(_("The file must be a zip file"))


I know, it's not a very beautiful way to do it but it's an alternative solution to your problem.

Hope that help you.

Yes nice ....post its working...

Odoo
on 3/25/15, 1:19 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 3/16/15, 6:45 AM
Seen: 1104 times
Last updated: 3/25/15, 1:18 AM