Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Odoo (Formerly OpenERP) Functional Binary Field | Cocept https://www.cocept.

io/blog/development/odoo-binary-field/

Odoo (Formerly OpenERP)


Functional Binary Field
in Development

by Max Mumford (https://plus.google.com/+MaxMumford/)

  (https://www.cocept.io/blog/development/odoo-binary-�eld/)

In order to have more �exible �le serving functionality within


Odoo, you can swap out binary �elds for a functional �eld that
returns the contents of your �le. Below is a sample class that
loads a �le’s contents from a �le system path and serves it to

1 de 5 19-12-2016 03:10
Odoo (Formerly OpenERP) Functional Binary Field | Cocept https://www.cocept.io/blog/development/odoo-binary-field/

the user using a functional �eld. It was originally built for


 Cocept (/) Menu
version 6.0 but should work on newer versions too:

1 import base64
2 from osv import osv, fields
3
4 class my_class(osv.osv_memory):
5
6 def get_file(self, cr, uid, ids, field_name=None, arg=None, context=None):
7 result = dict.fromkeys(ids)
8 for record_browse in self.browse(cr, uid, ids):
9 f = open(record_browse.file_path)
10 result[record_browse.id] = base64.encodestring(f.read())
11 f.close()
12 return result
13
14 _name = 'my.class'
15
16 _columns = {
17 'file_path': fields.char('File Location', size=128),
18 'file': fields.function(get_file, method=True, store=False, type='binary
19 }
20
21 my_class()

view raw (https://gist.github.com/maxmumford/9371147


/raw/9489969db2ce57163551f6fef36e00171122add4/OpenERP%20Functional%20Binary%20Field.py)
OpenERP Functional Binary Field.py (https://gist.github.com/maxmumford/9371147#file-openerp-

2 de 5 19-12-2016 03:10
Odoo (Formerly OpenERP) Functional Binary Field | Cocept https://www.cocept.io/blog/development/odoo-binary-field/

functional-binary-field-py) hosted with ❤ by GitHub (https://github.com)

 Cocept (/) Menu

 Facebook (https://www.facebook.com/sharer/sharer.php?u=https://www.cocept.io
/blog/development/odoo-binary-field/)

 Twitter (https://twitter.com/home?status=https://www.cocept.io/blog/development/odoo-
binary-field/%20Odoo (Formerly OpenERP) Functional Binary Field)

 Google+ (https://plus.google.com/share?url=https://www.cocept.io/blog/development
/odoo-binary-field/)

 LinkedIn (https://www.linkedin.com/shareArticle?mini=true&url=https://www.cocept.io
/blog/development/odoo-binary-field/&title=Odoo (Formerly OpenERP) Functional Binary
Field&summary=In order to have more flexible file serving functionality within Odoo, you
can swap out binary fields for a functional field that returns the contents of your file. Below
is a sample class that loads a file’s contents from a file system path and serves it to the user
using a functional field. It was originally built for version 6.0 but should work on newer
versions too: )

3 de 5 19-12-2016 03:10
Odoo (Formerly OpenERP) Functional Binary Field | Cocept https://www.cocept.io/blog/development/odoo-binary-field/

Cocept
Buffer (https://buffer.com/add?url=https://www.cocept.io/blog/development/odoo-binary-
(/) Menu
field/&text=Odoo (Formerly OpenERP) Functional Binary Field)

Leave us a Comment

Connect With Us
Get our monthly newsletter with tech tips for business professionals

email address  Subscribe

(https://www.facebook.com/CoceptUK/) (//plus.google.com
0 (mailto:?body=%0D%0A%0D%0Ahttps%3A%2F
/u/0/103279012809634350123?prsrc=3) (https://twitter.com/CoceptUK)
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F&subject=Check out this
(https://uk.pinterest.com/cocept/) (https://www.linkedin.com/company/10672122)
great article I found!)0 (https://www.facebook.com/sharer/sharer.php?u=https%3A%2F
(/blog/feed.xml)
 %2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F)0

4 de 5 19-12-2016 03:10
Odoo (Formerly OpenERP) Functional Binary Field | Cocept https://www.cocept.io/blog/development/odoo-binary-field/

(https://plus.google.com/share?url=https%3A%2F
 Cocept (/)
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F)0 Menu
(https://www.linkedin.com/cws/share?url=https%3A%2F
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F)0 (https://twitter.com
/intent/tweet?url=https%3A%2F%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-
field%2F&
text=Odoo%20(Formerly%20OpenERP)%20Functional%20Binary%20Field%20-%20Cocept&
via=CoceptUK)00 ×
(https://twitter.com/intent/tweet?url=https%3A%2F
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F&via=CoceptUK&
text=file%20system&hashtags=cocept&related=ivyapp%3AGet the latest news and updates on
Ivy,filament_io%3AApps updates and tips for making your visitors happier)
(https://www.facebook.com/sharer/sharer.php?u=https%3A%2F
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F)
(mailto:?subject=A%20great%20quote%20from%20www.cocept.io&
body=Hi!%20I%20saw%20this%20quote%20and%20thought%20you'd%20like%20it%3A%0A
%0A%22file%20system%22%0A%0A%20%20%20%20https%3A%2F
%2Fwww.cocept.io%2Fblog%2Fdevelopment%2Fodoo-binary-field%2F
%0A%0AShared%20via%20Ivy%20-%20http%3A%2F%2Fgoo.gl%2F5K6KjB)
Shared via Ivy Get yours now free (http://filament.io/r.php?i=ivy&utm_source=ivy&
utm_medium=deployment&utm_campaign=filament&utm_content=confirmation)

5 de 5 19-12-2016 03:10

You might also like