[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / stock / report_stock.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 osv, fields
24 from tools.translate import _
25 from tools.sql import drop_view_if_exists
26
27 #
28 # Check if it works with UoM ???
29 #
30 class stock_report_prodlots(osv.osv):
31     _name = "stock.report.prodlots"
32     _description = "Stock report by production lots"
33     _auto = False
34     _columns = {
35             'name': fields.float('Quantity', readonly=True),
36             'location_id': fields.many2one('stock.location', 'Location', readonly=True, select=True),
37             'product_id': fields.many2one('product.product', 'Product', readonly=True, select=True),
38             'prodlot_id': fields.many2one('stock.production.lot', 'Production lot', readonly=True, select=True),
39     }
40     
41     def init(self, cr):
42         drop_view_if_exists(cr, 'stock_report_prodlots')
43         cr.execute("""
44             create or replace view stock_report_prodlots as (
45                 select max(id) as id,
46                     location_id,
47                     product_id,
48                     prodlot_id,
49                     sum(qty) as name
50                 from (
51                     select -max(sm.id) as id,
52                         sm.location_id,
53                         sm.product_id,
54                         sm.prodlot_id,
55                         -sum(sm.product_qty /uo.factor) as qty
56                     from stock_move as sm
57                     left join stock_location sl
58                         on (sl.id = sm.location_id)
59                     left join product_uom uo
60                         on (uo.id=sm.product_uom)
61                     where state = 'done'
62                     group by sm.location_id, sm.product_id, sm.product_uom, sm.prodlot_id
63                     union all
64                     select max(sm.id) as id,
65                         sm.location_dest_id as location_id,
66                         sm.product_id,
67                         sm.prodlot_id,
68                         sum(sm.product_qty /uo.factor) as qty
69                     from stock_move as sm
70                     left join stock_location sl
71                         on (sl.id = sm.location_dest_id)
72                     left join product_uom uo
73                         on (uo.id=sm.product_uom)
74                     where sm.state = 'done'
75                     group by sm.location_dest_id, sm.product_id, sm.product_uom, sm.prodlot_id
76                 ) as report
77                 group by location_id, product_id, prodlot_id
78             )""")
79         
80     def unlink(self, cr, uid, ids, context={}):
81         raise osv.except_osv(_('Error !'), _('You cannot delete any record!'))
82
83         
84 stock_report_prodlots()
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: