26
26
from report import report_sxw
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)
33
32
self.localcontext.update({
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,
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,
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)
36
# 'Carton': self._get_carton,
37
# 'SCondt': self._get_SCondt,
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,
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)
56
52
# if there are several, pick first
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
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.
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]
65
if 'link' in datas[0]:
60
if datas[0].has_key('link'):
67
img_data = base64.encodestring(
68
urllib.urlopen(datas[0]['datas']).read())
62
img_data = base64.encodestring(urllib.urlopen(datas[0]['datas']).read())
70
except Exception, innerEx:
64
except Exception,innerEx:
72
66
elif datas[0]['datas']:
73
67
return datas[0]['datas']
78
def setCat(self, cats):
72
def setCat(self,cats):
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']))
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)])
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)])
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)])
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)
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})
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})
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
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'])
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'])
123
112
p = str(s[0:9]) + "..."
125
114
elif not s == "False":
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'])
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'])
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]
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]
145
def _get_desc(self, tempate_id):
134
def _get_desc(self,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]
150
138
if prodtmpl['description_sale']:
151
139
return prodtmpl['description_sale']