[IMP]
[odoo/odoo.git] / addons / sale / product.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from osv import fields, osv
24 from tools import config
25
26
27
28 class product_product(osv.osv):
29     _name = 'product.product'
30     _inherit = 'product.product'
31
32     def _pricelist_calculate(self, cr, uid, ids, name, arg, context=None):
33         result = {}
34         pricelist_obj=self.pool.get('product.pricelist')
35         if name=='pricelist_purchase':
36             pricelist_ids=pricelist_obj.search(cr,uid,[('type','=','purchase')])
37         else:
38             pricelist_ids=pricelist_obj.search(cr,uid,[('type','=','sale')])
39         pricelist_browse=pricelist_obj.browse(cr,uid,pricelist_ids)
40         for product in self.browse(cr, uid, ids, context):
41             result[product.id] = ""
42             for pricelist in pricelist_browse:
43                 for version in pricelist.version_id:
44                     for items in version.items_id:
45                         qty = items.min_quantity
46                         try:
47                             prices = pricelist_obj.price_get(cr, uid, [pricelist.id], product.id, qty, partner=None, context=None)
48                             price = prices.get(pricelist.id) or 0.0
49                         except:
50                             price = 0.0
51                         result[product.id] += "%s (%.2f) : %.2f\n" % (pricelist.name, qty or 0.0, price)
52                         break
53                     break
54         return result
55
56     _columns = {
57         'pricelist_sale':fields.function(
58             _pricelist_calculate,
59             method=True,
60             string='Sale Pricelists',
61             store=True,
62             type="text"),
63         'pricelist_purchase':fields.function(
64             _pricelist_calculate,
65             method=True,
66             string='Purchase Pricelists',
67             store=True,
68             type="text"),
69     }
70
71 product_product()
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: