~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to product_catalog_m321/report/product_catalog.py

  • Committer: nhomar at vauxoo
  • Date: 2011-09-14 00:54:21 UTC
  • Revision ID: nhomar@vauxoo.com-20110914005421-hgla9f4xtyqirfgz
[ADD] Multicompany Invoice Report

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
##############################################################################
2
 
#
 
2
#    
3
3
#    OpenERP, Open Source Management Solution
4
4
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
5
5
#
14
14
#    GNU Affero General Public License for more details.
15
15
#
16
16
#    You should have received a copy of the GNU Affero General Public License
17
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
18
18
#
19
19
##############################################################################
20
20
 
25
25
import base64
26
26
from report import report_sxw
27
27
 
28
 
 
29
28
class product_catalog(report_sxw.rml_parse):
30
29
    def __init__(self, cr, uid, name, context):
31
30
        super(product_catalog, self).__init__(cr, uid, name, context)
32
31
 
33
32
        self.localcontext.update({
34
33
            'time': time,
35
 
            'image_url': self._get_imagepath,
 
34
            'image_url' : self._get_imagepath,
36
35
            'currency_code': self._get_currency,
37
 
                                 #            'Carton': self._get_carton,
38
 
                                 #            'SCondt': self._get_SCondt,
39
 
                                 #            'UV': self._get_UV,
40
 
            'categories': self._getCategories,
41
 
            'products': self._getProducts,
42
 
            'description': self._get_desc,
43
 
            'packaging_title': self._get_packaging_title,
44
 
            'packaging_value': self._get_packaging_value,
45
 
            'Price': self._get_price,
46
 
 
47
 
                                 })
48
 
 
49
 
    def _get_imagepath(self, product):
50
 
        attach_ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [
51
 
                                                           ('res_model', '=', 'product.product'), ('res_id', '=', product)])
52
 
        datas = self.pool.get('ir.attachment').read(
53
 
            self.cr, self.uid, attach_ids)
54
 
 
 
36
#            'Carton': self._get_carton,
 
37
#            'SCondt': self._get_SCondt,
 
38
#            'UV': self._get_UV,
 
39
            'categories':self._getCategories,
 
40
            'products':self._getProducts,
 
41
            'description':self._get_desc,
 
42
            'packaging_title':self._get_packaging_title,
 
43
            'packaging_value':self._get_packaging_value,
 
44
            'Price':self._get_price,
 
45
 
 
46
        })
 
47
    def _get_imagepath(self,product):
 
48
        attach_ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [('res_model','=','product.product'), ('res_id', '=',product)])
 
49
        datas = self.pool.get('ir.attachment').read(self.cr, self.uid, attach_ids)
 
50
        
55
51
        if len(datas):
56
52
            # if there are several, pick first
57
53
            # Imp. by Vauxoo.
58
 
            # If Name of resource have in its first word the word "catalog" it
59
 
            # will be  the selected, if no there are any with this condition we
60
 
            # take the first.
 
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.
61
56
            print len(datas)
62
 
            datas = [i for i in datas if i['name'].find('catalog') != -1]
 
57
            datas = [i for i in datas if i['name'].find('catalog')<>-1]
63
58
            if datas:
64
59
                try:
65
 
                    if 'link' in datas[0]:
 
60
                    if datas[0].has_key('link'):
66
61
                        try:
67
 
                            img_data = base64.encodestring(
68
 
                                urllib.urlopen(datas[0]['datas']).read())
 
62
                            img_data =  base64.encodestring(urllib.urlopen(datas[0]['datas']).read())
69
63
                            return img_data
70
 
                        except Exception, innerEx:
 
64
                        except Exception,innerEx:
71
65
                            print innerEx
72
66
                    elif datas[0]['datas']:
73
67
                        return datas[0]['datas']
74
 
                except Exception, e:
 
68
                except Exception,e:
75
69
                    print e
76
70
        return None
77
71
 
78
 
    def setCat(self, cats):
 
72
    def setCat(self,cats):
79
73
        lst = []
80
74
        for cat in cats:
81
75
            if cat not in lst:
82
76
                lst.append(cat)
83
 
                category = self.pool.get('product.category').read(
84
 
                    self.cr, self.uid, [cat])
 
77
                category = self.pool.get('product.category').read(self.cr,self.uid,[cat])
85
78
                if category[0]['child_id']:
86
79
                    lst.extend(self.setCat(category[0]['child_id']))
87
80
        return lst
88
81
 
89
 
    def _getCategories(self, cat):
90
 
        lst = self.setCat(cat[0][2])
91
 
        cat_ids = self.pool.get('product.category').search(
92
 
            self.cr, self.uid, [('id', 'in', lst)])
 
82
 
 
83
    def _getCategories(self,cat):
 
84
        lst =  self.setCat(cat[0][2])
 
85
        cat_ids = self.pool.get('product.category').search(self.cr,self.uid,[('id','in',lst)])
93
86
        tmpCat_ids = []
94
87
        for cat in cat_ids:
95
 
            prod_ids = self.pool.get('product.template').search(
96
 
                self.cr, self.uid, [('categ_id', '=', cat)])
 
88
            prod_ids = self.pool.get('product.template').search(self.cr,self.uid,[('categ_id','=',cat)])
97
89
            if len(prod_ids):
98
90
                tmpCat_ids.append(cat)
99
 
        cats = self.pool.get('product.category').read(
100
 
            self.cr, self.uid, tmpCat_ids)
 
91
        cats = self.pool.get('product.category').read(self.cr,self.uid,tmpCat_ids)
101
92
        return cats
102
93
 
103
 
    def _getProducts(self, category, lang):
104
 
        prod_tmpIDs = self.pool.get('product.template').search(
105
 
            self.cr, self.uid, [('categ_id', '=', category)])
106
 
        prod_ids = self.pool.get('product.product').search(
107
 
            self.cr, self.uid, [('product_tmpl_id', 'in', prod_tmpIDs)])
108
 
        prods = self.pool.get('product.product').read(
109
 
            self.cr, self.uid, prod_ids, context={'lang': lang})
 
94
 
 
95
    def _getProducts(self,category,lang):
 
96
        prod_tmpIDs = self.pool.get('product.template').search(self.cr,self.uid,[('categ_id','=',category)])
 
97
        prod_ids = self.pool.get('product.product').search(self.cr,self.uid,[('product_tmpl_id','in',prod_tmpIDs)])
 
98
        prods = self.pool.get('product.product').read(self.cr,self.uid,prod_ids,context={'lang':lang})
110
99
        return prods
111
100
 
 
101
 
112
102
    def _get_currency(self):
113
103
        return self.pool.get('res.users').browse(self.cr, self.uid, [self.uid])[0].company_id.currency_id.name
114
104
 
115
 
    def _get_packaging_title(self, product, index):
116
 
        packaging_ids = self.pool.get('product.packaging').search(
117
 
            self.cr, self.uid, [('product_id', '=', product)], limit=4)
118
 
        packs = self.pool.get('product.packaging').read(
119
 
            self.cr, self.uid, packaging_ids, ['name'])
 
105
 
 
106
    def _get_packaging_title(self,product,index):
 
107
        packaging_ids = self.pool.get('product.packaging').search(self.cr,self.uid,[('product_id','=',product)],limit=4)
 
108
        packs = self.pool.get('product.packaging').read(self.cr,self.uid,packaging_ids,['name'])
120
109
        if len(packs) > index:
121
110
            s = str(packs[index]['name'])
122
 
            if len(s) > 9:
 
111
            if len(s)>9:
123
112
                p = str(s[0:9]) + "..."
124
113
                return p
125
114
            elif not s == "False":
126
115
                return s
127
116
        return " "
128
117
 
129
 
    def _get_packaging_value(self, product, index):
130
 
        packaging_ids = self.pool.get('product.packaging').search(
131
 
            self.cr, self.uid, [('product_id', '=', product)], limit=4)
132
 
        packs = self.pool.get('product.packaging').read(
133
 
            self.cr, self.uid, packaging_ids, ['qty'])
 
118
 
 
119
    def _get_packaging_value(self,product,index):
 
120
        packaging_ids = self.pool.get('product.packaging').search(self.cr,self.uid,[('product_id','=',product)],limit=4)
 
121
        packs = self.pool.get('product.packaging').read(self.cr,self.uid,packaging_ids,['qty'])
134
122
        if len(packs) > index:
135
123
            return str(packs[index]['qty'])
136
124
        return False
137
125
 
138
 
    def _get_price(self, product, pricelist):
139
 
        price = self.pool.get('product.pricelist').price_get(self.cr, self.uid, [
140
 
                                                             pricelist], product, 1.0, None, {'uom': False})[pricelist]
 
126
 
 
127
    def _get_price(self,product,pricelist):
 
128
        price = self.pool.get('product.pricelist').price_get(self.cr,self.uid,[pricelist], product, 1.0, None,{'uom': False})[pricelist]
141
129
        if not price:
142
130
            price = 0.0
143
131
        return price
144
132
 
145
 
    def _get_desc(self, tempate_id):
 
133
 
 
134
    def _get_desc(self,tempate_id):
146
135
        if tempate_id:
147
 
            prodtmpl = self.pool.get('product.template').read(
148
 
                self.cr, self.uid, [tempate_id])[0]
 
136
            prodtmpl = self.pool.get('product.template').read(self.cr,self.uid,[tempate_id])[0]
149
137
 
150
138
            if prodtmpl['description_sale']:
151
139
                return prodtmpl['description_sale']
155
143
            return "This is Test Description"
156
144
 
157
145
 
158
 
report_sxw.report_sxw('report.product_catalog', 'res.partner',
159
 
                      'addons/product_catalog_report/report/product_catalog.rml', parser=product_catalog, header=False)
 
146
report_sxw.report_sxw('report.product_catalog', 'res.partner', 'addons/product_catalog_report/report/product_catalog.rml', parser=product_catalog,header=False)
160
147
 
161
148
 
162
149
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
150