1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from openerp.osv import osv
25 from openerp.report import report_sxw
26 from openerp.tools.translate import _
28 class product_pricelist(report_sxw.rml_parse):
29 def __init__(self, cr, uid, name, context):
30 super(product_pricelist, self).__init__(cr, uid, name, context=context)
33 self.localcontext.update({
35 'get_pricelist': self._get_pricelist,
36 'get_currency': self._get_currency,
37 'get_currency_symbol': self._get_currency_symbol, # TODO 7.0 - remove this - unused
38 'get_categories': self._get_categories,
39 'get_price': self._get_price,
40 'get_titles': self._get_titles,
43 def _get_titles(self, form):
49 if form['qty'+str(i)]!=0:
50 vals['qty'+str(qtys)] = str(form['qty'+str(i)]) + ' units'
55 def _set_quantity(self, form):
58 if form[q] >0 and form[q] not in self.quantity:
59 self.quantity.append(form[q])
61 self.quantity.append(0)
64 def _get_pricelist(self, pricelist_id):
65 pricelist = self.pool.get('product.pricelist').read(self.cr, self.uid, [pricelist_id], ['name'], context=self.localcontext)[0]
66 return pricelist['name']
68 def _get_currency(self, pricelist_id):
69 pricelist = self.pool.get('product.pricelist').read(self.cr, self.uid, [pricelist_id], ['currency_id'], context=self.localcontext)[0]
70 return pricelist['currency_id'][1]
72 # TODO 7.0 - remove this method, its unused
73 def _get_currency_symbol(self, pricelist_id):
74 pricelist = self.pool.get('product.pricelist').read(self.cr, self.uid, [pricelist_id], ['currency_id'], context=self.localcontext)[0]
75 symbol = self.pool.get('res.currency').read(self.cr, self.uid, [pricelist['currency_id'][0]], ['symbol'], context=self.localcontext)[0]
76 return symbol['symbol'] or ''
78 def _get_categories(self, products, form):
81 self.pricelist = form['price_list']
82 self._set_quantity(form)
84 for product in products:
85 pro_ids.append(product.id)
86 if product.categ_id.id not in cat_ids:
87 cat_ids.append(product.categ_id.id)
89 cats = self.pool.get('product.category').name_get(self.cr, self.uid, cat_ids, context=self.localcontext)
93 product_ids=self.pool.get('product.product').search(self.cr, self.uid, [('id', 'in', pro_ids), ('categ_id', '=', cat[0])], context=self.localcontext)
95 for product in self.pool.get('product.product').read(self.cr, self.uid, product_ids, ['name', 'code'], context=self.localcontext):
98 'name':product['name'],
99 'code':product['code']
102 for qty in self.quantity:
104 val['qty'+str(i)] = 0.0
106 val['qty'+str(i)]=self._get_price(self.pricelist, product['id'], qty)
109 res.append({'name':cat[1],'products': products})
112 def _get_price(self, pricelist_id, product_id, qty):
113 sale_price_digits = self.get_digits(dp='Product Price')
114 pricelist = self.pool.get('product.pricelist').browse(self.cr, self.uid, [pricelist_id], context=self.localcontext)[0]
115 price_dict = self.pool.get('product.pricelist').price_get(self.cr, self.uid, [pricelist_id], product_id, qty, context=self.localcontext)
116 if price_dict[pricelist_id]:
117 price = self.formatLang(price_dict[pricelist_id], digits=sale_price_digits, currency_obj=pricelist.currency_id)
119 res = self.pool.get('product.product').read(self.cr, self.uid, [product_id])
120 price = self.formatLang(res[0]['list_price'], digits=sale_price_digits, currency_obj=pricelist.currency_id)
123 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: