improved stock reports: continued.....
[odoo/odoo.git] / addons / stock / report / lot_overview_all.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 import pooler
23 import time
24 from report import report_sxw
25
26 class lot_overview_all(report_sxw.rml_parse):
27     def __init__(self, cr, uid, name, context):
28         super(lot_overview_all, self).__init__(cr, uid, name, context)
29         self.price_total = 0.0
30         self.localcontext.update({
31             'time': time,
32             'process':self.process,
33             'price_total': self._price_total,
34         })
35
36     def process(self,location_id):
37         res = {}
38         location_obj = pooler.get_pool(self.cr.dbname).get('stock.location')
39         product_obj = pooler.get_pool(self.cr.dbname).get('product.product')
40        
41         product_ids = product_obj.search(self.cr, self.uid, [])
42
43         products = product_obj.browse(self.cr,self.uid, product_ids)
44         products_by_uom = {}
45         products_by_id = {}
46         for product in products:
47             products_by_uom.setdefault(product.uom_id.id, [])
48             products_by_uom[product.uom_id.id].append(product)
49             products_by_id.setdefault(product.id, [])
50             products_by_id[product.id] = product
51
52         result = []
53 #        res['prod'] = []
54         for id in self.ids:
55             for uom_id in products_by_uom.keys():
56                 fnc = location_obj._product_get
57                 qty = fnc(self.cr, self.uid, id, [x.id for x in products_by_uom[uom_id]])
58                 for product_id in qty.keys():
59                     if not qty[product_id]:
60                         continue
61                     product = products_by_id[product_id]
62                     value=(product.standard_price)*(qty[product_id])
63                     self.price_total += value
64                     result.append({
65                         
66                         'name': product.name,
67                         'variants': product.variants or '',
68                         'code': product.default_code,
69                        'amount': str(qty[product_id]),
70                         'uom': product.uom_id.name,
71                         'price': str(product.standard_price),
72                         'value':str(value),
73                     })
74                     
75         
76         return result
77     
78     def _price_total(self):
79             return str( self.price_total)
80
81 report_sxw.report_sxw('report.lot.stock.overview_all', 'stock.location', 'addons/stock/report/lot_overview_all.rml', parser=lot_overview_all)
82
83
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
85