1
##############################################################################
3
# Copyright (c) 2005-2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
30
import reportlab.lib.units
33
from report import report_sxw
35
class product_catalog(report_sxw.rml_parse):
36
def __init__(self, cr, uid, name, context):
37
super(product_catalog, self).__init__(cr, uid, name, context)
39
self.localcontext.update({
41
'image_url' : self._get_imagepath,
42
'currency_code': self._get_currency,
43
# 'Carton': self._get_carton,
44
# 'SCondt': self._get_SCondt,
46
'categories':self._getCategories,
47
'products':self._getProducts,
48
'description':self._get_desc,
49
'packaging_title':self._get_packaging_title,
50
'packaging_value':self._get_packaging_value,
51
'Price':self._get_price,
54
def _get_imagepath(self,product):
55
attach_ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [('res_model','=','product.product'), ('res_id', '=',product)])
56
datas = self.pool.get('ir.attachment').read(self.cr, self.uid, attach_ids)
58
# if there are several, pick first
62
img_data = base64.encodestring(urllib.urlopen(datas[0]['link']).read())
64
except Exception,innerEx:
66
elif datas[0]['datas']:
67
return datas[0]['datas']
72
def setCat(self,cats):
77
category = self.pool.get('product.category').read(self.cr,self.uid,[cat])
78
if category[0]['child_id']:
79
lst.extend(self.setCat(category[0]['child_id']))
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)])
88
prod_ids = self.pool.get('product.template').search(self.cr,self.uid,[('categ_id','=',cat)])
90
tmpCat_ids.append(cat)
91
cats = self.pool.get('product.category').read(self.cr,self.uid,tmpCat_ids)
93
def _getProducts(self,category,lang):
94
prod_tmpIDs = self.pool.get('product.template').search(self.cr,self.uid,[('categ_id','=',category)])
95
prod_ids = self.pool.get('product.product').search(self.cr,self.uid,[('product_tmpl_id','in',prod_tmpIDs)])
96
prods = self.pool.get('product.product').read(self.cr,self.uid,prod_ids,context={'lang':lang})
99
def _get_currency(self):
100
return self.pool.get('res.users').browse(self.cr, self.uid, [self.uid])[0].company_id.currency_id.name
103
def _get_packaging_title(self,product,index):
104
packaging_ids = self.pool.get('product.packaging').search(self.cr,self.uid,[('product_id','=',product)],limit=4)
105
packs = self.pool.get('product.packaging').read(self.cr,self.uid,packaging_ids)
106
if len(packs) > index:
107
s = str(packs[index]['name'])
109
p = str(s[0:9]) + "..."
111
elif not s == "False":
115
def _get_packaging_value(self,product,index):
116
packaging_ids = self.pool.get('product.packaging').search(self.cr,self.uid,[('product_id','=',product)],limit=4)
117
packs = self.pool.get('product.packaging').read(self.cr,self.uid,packaging_ids)
118
if len(packs) > index:
119
return str(packs[index]['qty'])
122
def _get_price(self,product,pricelist):
123
price = self.pool.get('product.pricelist').price_get(self.cr,self.uid,[pricelist], product, 1.0, None,{'uom': False})[pricelist]
128
def _get_desc(self,tempate_id):
130
prodtmpl = self.pool.get('product.template').read(self.cr,self.uid,[tempate_id])[0]
132
if prodtmpl['description_sale']:
133
return prodtmpl['description_sale']
135
return "no Description Specified"
137
return "This is Test Description"
140
report_sxw.report_sxw('report.product_catalog', 'res.partner', 'addons/product_catalog_report/report/product_catalog.rml', parser=product_catalog,header=False)