2009-10-14 11:15:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-09-16 11:45:13 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
2009-04-29 10:58:23 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-09-16 11:45:13 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-09-16 11:45:13 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-09-16 11:45:13 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-09-16 11:45:13 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import time
|
|
|
|
from report import report_sxw
|
|
|
|
from osv import osv
|
|
|
|
import pooler
|
2008-12-08 17:08:40 +00:00
|
|
|
|
2008-09-16 11:45:13 +00:00
|
|
|
class product_pricelist(report_sxw.rml_parse):
|
|
|
|
def __init__(self, cr, uid, name, context):
|
2009-10-09 11:49:00 +00:00
|
|
|
super(product_pricelist, self).__init__(cr, uid, name, context=context)
|
2008-09-16 11:45:13 +00:00
|
|
|
self.pricelist=False
|
|
|
|
self.quantity=[]
|
|
|
|
self.localcontext.update({
|
|
|
|
'time': time,
|
|
|
|
'get_pricelist': self._get_pricelist,
|
|
|
|
'get_currency': self._get_currency,
|
|
|
|
'get_categories': self._get_categories,
|
|
|
|
'get_price': self._get_price,
|
2009-07-16 10:14:17 +00:00
|
|
|
'get_titles': self._get_titles,
|
2008-09-16 11:45:13 +00:00
|
|
|
})
|
2008-12-08 17:08:40 +00:00
|
|
|
|
2009-07-16 10:14:17 +00:00
|
|
|
def _get_titles(self,form):
|
|
|
|
lst = []
|
|
|
|
vals = {}
|
|
|
|
qtys = 1
|
|
|
|
|
|
|
|
for i in range(1,6):
|
2009-07-22 14:15:39 +00:00
|
|
|
if form['qty'+str(i)] > 0 and form['qty'+str(i)] not in vals.values():
|
2009-07-16 10:14:17 +00:00
|
|
|
vals['qty'+str(qtys)] = form['qty'+str(i)]
|
|
|
|
qtys += 1
|
|
|
|
lst.append(vals)
|
|
|
|
return lst
|
|
|
|
|
2009-04-29 10:58:23 +00:00
|
|
|
def _set_quantity(self,form):
|
2008-09-16 11:45:13 +00:00
|
|
|
for i in range(1,6):
|
|
|
|
q = 'qty%d'%i
|
2009-07-22 14:15:39 +00:00
|
|
|
if form[q] >0 and form[q] not in self.quantity:
|
2008-09-16 11:45:13 +00:00
|
|
|
self.quantity.append(form[q])
|
2009-07-16 10:14:17 +00:00
|
|
|
# else:
|
|
|
|
# self.quantity.append(0)
|
2009-04-29 10:58:23 +00:00
|
|
|
return True
|
2008-09-16 11:45:13 +00:00
|
|
|
|
|
|
|
def _get_pricelist(self, pricelist_id):
|
|
|
|
pool = pooler.get_pool(self.cr.dbname)
|
|
|
|
pricelist = pool.get('product.pricelist').read(self.cr,self.uid,[pricelist_id],['name'])[0]
|
|
|
|
return pricelist['name']
|
2009-04-29 10:58:23 +00:00
|
|
|
|
2008-09-16 11:45:13 +00:00
|
|
|
def _get_currency(self, pricelist_id):
|
|
|
|
pool = pooler.get_pool(self.cr.dbname)
|
|
|
|
pricelist = pool.get('product.pricelist').read(self.cr,self.uid,[pricelist_id],['currency_id'])[0]
|
|
|
|
return pricelist['currency_id'][1]
|
2009-04-29 10:58:23 +00:00
|
|
|
|
|
|
|
def _get_categories(self, products,form):
|
2008-09-16 11:45:13 +00:00
|
|
|
cat_ids=[]
|
|
|
|
res=[]
|
2009-04-29 10:58:23 +00:00
|
|
|
self.pricelist = form['price_list']
|
|
|
|
self._set_quantity(form)
|
2008-09-16 11:45:13 +00:00
|
|
|
pool = pooler.get_pool(self.cr.dbname)
|
|
|
|
pro_ids=[]
|
|
|
|
for product in products:
|
|
|
|
pro_ids.append(product.id)
|
|
|
|
if product.categ_id.id not in cat_ids:
|
|
|
|
cat_ids.append(product.categ_id.id)
|
2009-07-16 10:14:17 +00:00
|
|
|
cats = pool.get('product.category').read(self.cr,self.uid,cat_ids,['name'])
|
2008-09-16 11:45:13 +00:00
|
|
|
for cat in cats:
|
2009-07-16 10:14:17 +00:00
|
|
|
product_ids=pool.get('product.product').search(self.cr,self.uid,[('id','in',pro_ids),('categ_id','=',cat['id'])])
|
2008-09-16 11:45:13 +00:00
|
|
|
products = []
|
2009-07-16 10:14:17 +00:00
|
|
|
for product in pool.get('product.product').read(self.cr,self.uid,product_ids,['name','code']):
|
2008-09-16 11:45:13 +00:00
|
|
|
val={
|
2009-07-16 10:14:17 +00:00
|
|
|
'id':product['id'],
|
|
|
|
'name':product['name'],
|
|
|
|
'code':product['code']
|
2008-09-16 11:45:13 +00:00
|
|
|
}
|
2009-04-29 10:58:23 +00:00
|
|
|
i = 1
|
2008-09-16 11:45:13 +00:00
|
|
|
for qty in self.quantity:
|
2009-07-16 10:14:17 +00:00
|
|
|
if qty == 0:
|
|
|
|
val['qty'+str(i)] = ""
|
|
|
|
else:
|
|
|
|
val['qty'+str(i)]=self._get_price(self.pricelist,product['id'],qty)
|
|
|
|
i += 1
|
2008-09-16 11:45:13 +00:00
|
|
|
products.append(val)
|
2009-07-16 10:14:17 +00:00
|
|
|
res.append({'name':cat['name'],'products':products})
|
2008-09-16 11:45:13 +00:00
|
|
|
return res
|
|
|
|
|
|
|
|
def _get_price(self,pricelist_id, product_id,qty):
|
|
|
|
pool = pooler.get_pool(self.cr.dbname)
|
|
|
|
price_dict = pool.get('product.pricelist').price_get(self.cr,self.uid,[pricelist_id],product_id,qty)
|
|
|
|
if price_dict[pricelist_id]:
|
|
|
|
price = self.formatLang(price_dict[pricelist_id])
|
|
|
|
else:
|
|
|
|
res = pool.get('product.product').read(self.cr, self.uid,[product_id])
|
|
|
|
price = self.formatLang(res[0]['list_price'])
|
|
|
|
return price
|
|
|
|
|
2008-09-18 09:47:22 +00:00
|
|
|
report_sxw.report_sxw('report.product.pricelist','product.product','addons/product/report/product_pricelist.rml',parser=product_pricelist)
|
2008-09-16 11:45:13 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|