~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to product_catalog_report/report/product_catalog.py

  • Committer: Albert Cervera i Areny
  • Date: 2011-06-14 09:51:35 UTC
  • mfrom: (5345.1.165 openobject-addons)
  • Revision ID: albert@nan-tic.com-20110614095135-1x3p6tmil5lxkl9b
Merge and add nan_remove_default_filters

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    def _get_imagepath(self,product):
48
48
        attach_ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [('res_model','=','product.product'), ('res_id', '=',product)])
49
49
        datas = self.pool.get('ir.attachment').read(self.cr, self.uid, attach_ids)
 
50
        
50
51
        if len(datas):
51
52
            # if there are several, pick first
52
 
            try:
53
 
                if datas[0]['link']:
54
 
                    try:
55
 
                        img_data =  base64.encodestring(urllib.urlopen(datas[0]['link']).read())
56
 
                        return img_data
57
 
                    except Exception,innerEx:
58
 
                        print innerEx
59
 
                elif datas[0]['datas']:
60
 
                    return datas[0]['datas']
61
 
            except Exception,e:
62
 
                print e
 
53
            # Imp. by Vauxoo.
 
54
            # If Name of resource have in its first word the word "catalog" it 
 
55
            # will be  the selected, if no there are any with this condition we take the first.
 
56
            print len(datas)
 
57
            datas = [i for i in datas if i['name'].find('catalog')<>-1]
 
58
            if datas:
 
59
                try:
 
60
                    if datas[0].has_key('link'):
 
61
                        try:
 
62
                            img_data =  base64.encodestring(urllib.urlopen(datas[0]['datas']).read())
 
63
                            return img_data
 
64
                        except Exception,innerEx:
 
65
                            print innerEx
 
66
                    elif datas[0]['datas']:
 
67
                        return datas[0]['datas']
 
68
                except Exception,e:
 
69
                    print e
63
70
        return None
64
71
 
65
72
    def setCat(self,cats):
83
90
                tmpCat_ids.append(cat)
84
91
        cats = self.pool.get('product.category').read(self.cr,self.uid,tmpCat_ids)
85
92
        return cats
 
93
 
 
94
 
86
95
    def _getProducts(self,category,lang):
87
96
        prod_tmpIDs = self.pool.get('product.template').search(self.cr,self.uid,[('categ_id','=',category)])
88
97
        prod_ids = self.pool.get('product.product').search(self.cr,self.uid,[('product_tmpl_id','in',prod_tmpIDs)])
89
98
        prods = self.pool.get('product.product').read(self.cr,self.uid,prod_ids,context={'lang':lang})
90
99
        return prods
91
100
 
 
101
 
92
102
    def _get_currency(self):
93
103
        return self.pool.get('res.users').browse(self.cr, self.uid, [self.uid])[0].company_id.currency_id.name
94
104
 
105
115
                return s
106
116
        return " "
107
117
 
 
118
 
108
119
    def _get_packaging_value(self,product,index):
109
120
        packaging_ids = self.pool.get('product.packaging').search(self.cr,self.uid,[('product_id','=',product)],limit=4)
110
121
        packs = self.pool.get('product.packaging').read(self.cr,self.uid,packaging_ids,['qty'])
112
123
            return str(packs[index]['qty'])
113
124
        return False
114
125
 
 
126
 
115
127
    def _get_price(self,product,pricelist):
116
128
        price = self.pool.get('product.pricelist').price_get(self.cr,self.uid,[pricelist], product, 1.0, None,{'uom': False})[pricelist]
117
129
        if not price:
118
130
            price = 0.0
119
131
        return price
120
132
 
 
133
 
121
134
    def _get_desc(self,tempate_id):
122
135
        if tempate_id:
123
136
            prodtmpl = self.pool.get('product.template').read(self.cr,self.uid,[tempate_id])[0]