~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to product_images_olbs/product_images.py

  • Committer: Jose Antonio
  • Date: 2012-04-22 20:38:11 UTC
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: jose@vauxoo.com-20120422203811-ahks9nmn4pck8bl8

[ADD] Added news modules to cancel invoices with withholding income and vat 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#########################################################################
2
2
# Copyright (C) 2009  Sharoon Thomas, Open Labs Business solutions      #
3
3
#                                                                       #
4
 
# This program is free software: you can redistribute it and/or modify   #
5
 
# it under the terms of the GNU General Public License as published by   #
6
 
# the Free Software Foundation, either version 3 of the License, or      #
 
4
#This program is free software: you can redistribute it and/or modify   #
 
5
#it under the terms of the GNU General Public License as published by   #
 
6
#the Free Software Foundation, either version 3 of the License, or      #
7
7
#(at your option) any later version.                                    #
8
8
#                                                                       #
9
 
# This program is distributed in the hope that it will be useful,        #
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of         #
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
12
 
# GNU General Public License for more details.                           #
 
9
#This program is distributed in the hope that it will be useful,        #
 
10
#but WITHOUT ANY WARRANTY; without even the implied warranty of         #
 
11
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
 
12
#GNU General Public License for more details.                           #
13
13
#                                                                       #
14
 
# You should have received a copy of the GNU General Public License      #
15
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
 
14
#You should have received a copy of the GNU General Public License      #
 
15
#along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
16
16
#########################################################################
17
 
from openerp.osv import osv, fields
18
 
import base64
19
 
import urllib
20
 
 
21
 
 
22
 
class product_images(osv.Model):
 
17
from osv import osv, fields
 
18
import base64, urllib
 
19
 
 
20
class product_images(osv.osv):
23
21
    "Products Image gallery"
24
22
    _name = "product.images"
25
23
    _description = __doc__
26
24
    _table = "product_images"
27
 
 
 
25
    
28
26
    def get_image(self, cr, uid, id):
29
27
        each = self.read(cr, uid, id, ['link', 'filename', 'image'])
30
28
        if each['link']:
31
29
            try:
32
30
                (filename, header) = urllib.urlretrieve(each['filename'])
33
 
                f = open(filename, 'rb')
 
31
                f = open(filename , 'rb')
34
32
                img = base64.encodestring(f.read())
35
33
                f.close()
36
34
            except:
38
36
        else:
39
37
            img = each['image']
40
38
        return img
41
 
 
 
39
    
42
40
    def _get_image(self, cr, uid, ids, field_name, arg, context={}):
43
41
        res = {}
44
42
        for each in ids:
45
43
            res[each] = self.get_image(cr, uid, each)
46
44
        return res
47
 
 
 
45
    
48
46
    _columns = {
49
 
        'name': fields.char('Image Title', size=100, required=True),
50
 
        'link': fields.boolean('Link?',
51
 
                               help="""Images can be linked from files on your
52
 
                                       file system or remote (Preferred)"""),
53
 
        'image': fields.binary('Image', filters='*.png,*.jpg,*.gif'),
54
 
        'filename': fields.char('File Location', size=250),
55
 
        'preview': fields.function(_get_image, type="binary", method=True),
56
 
        'comments': fields.text('Comments'),
57
 
        'product_id': fields.many2one('product.product', 'Product')
 
47
        'name':fields.char('Image Title', size=100, required=True),
 
48
        'link':fields.boolean('Link?', help="Images can be linked from files on your file system or remote (Preferred)"),
 
49
        'image':fields.binary('Image', filters='*.png,*.jpg,*.gif'),
 
50
        'filename':fields.char('File Location', size=250),
 
51
        'preview':fields.function(_get_image, type="binary", method=True),
 
52
        'comments':fields.text('Comments'),
 
53
        'product_id':fields.many2one('product.product', 'Product')
58
54
    }
59
55
 
60
56
    _defaults = {
61
57
        'link': lambda *a: True,
62
58
    }
 
59
product_images()